(tool: Tool)
| 113 | * Adds try/catch error handling and toolCallId generation. |
| 114 | */ |
| 115 | export function wrapToolExecute(tool: Tool): (args: any) => Promise<McpToolResult> { |
| 116 | return async (args: any) => { |
| 117 | try { |
| 118 | const result = await tool.execute!(args, { |
| 119 | toolCallId: crypto.randomUUID(), |
| 120 | messages: [], |
| 121 | }) |
| 122 | return { content: toMcpContent(result) } |
| 123 | } catch (err) { |
| 124 | // err.message, not `${err}` — a thrown Error stringifies to "Error: <msg>", |
| 125 | // which the `Error: ` prefix then doubled into "Error: Error: <msg>". |
| 126 | const message = err instanceof Error ? err.message : String(err) |
| 127 | return { |
| 128 | content: [{ type: 'text' as const, text: `Error: ${message}` }], |
| 129 | isError: true, |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | } |
no test coverage detected