(
def: ToolDefinition<TName, TShape, TMetadata>,
context: ToolContext,
)
| 5 | import { ToolContext, ToolDefinition } from "./types"; |
| 6 | |
| 7 | export function toVercelAITool<TName extends string, TShape extends z.ZodRawShape, TMetadata>( |
| 8 | def: ToolDefinition<TName, TShape, TMetadata>, |
| 9 | context: ToolContext, |
| 10 | ) { |
| 11 | return tool({ |
| 12 | description: def.description, |
| 13 | inputSchema: def.inputSchema, |
| 14 | title: def.title, |
| 15 | execute: async (input) => { |
| 16 | let success = true; |
| 17 | try { |
| 18 | return await def.execute(input, context); |
| 19 | } catch (error) { |
| 20 | success = false; |
| 21 | throw error; |
| 22 | } finally { |
| 23 | captureEvent('tool_used', { |
| 24 | toolName: def.name, |
| 25 | source: context.source ?? 'unknown', |
| 26 | success, |
| 27 | }); |
| 28 | } |
| 29 | }, |
| 30 | toModelOutput: ({ output }) => ({ |
| 31 | type: "content", |
| 32 | value: [{ type: "text", text: output.output }], |
| 33 | }), |
| 34 | }); |
| 35 | } |
| 36 | |
| 37 | export function registerMcpTool<TName extends string, TShape extends z.ZodRawShape, TMetadata>( |
| 38 | server: McpServer, |
no test coverage detected