MCPcopy Create free account
hub / github.com/TraderAlice/OpenAlice / wrapToolExecute

Function wrapToolExecute

src/core/mcp-export.ts:115–133  ·  view source on GitHub ↗
(tool: Tool)

Source from the content-addressed store, hash-verified

113 * Adds try/catch error handling and toolCallId generation.
114 */
115export 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}

Callers 4

createGlobalMcpServerMethod · 0.85
registerCliRoutesFunction · 0.85
createToolsRoutesFunction · 0.85

Calls 1

toMcpContentFunction · 0.85

Tested by

no test coverage detected