MCPcopy
hub / github.com/CopilotKit/CopilotKit / handler

Function handler

packages/runtime/src/lib/runtime/mcp-tools-utils.ts:168–186  ·  view source on GitHub ↗
(params: any)

Source from the content-addressed store, hash-verified

166 const parameters = extractParametersFromSchema(tool);
167
168 const handler = async (params: any): Promise<any> => {
169 try {
170 const result = await tool.execute(params);
171 // Ensure the result is a string or stringify it, as required by many LLMs.
172 // This might need adjustment depending on how different LLMs handle tool results.
173 return typeof result === "string" ? result : JSON.stringify(result);
174 } catch (error) {
175 console.error(
176 `Error executing MCP tool '${toolName}' from endpoint ${mcpEndpoint}:`,
177 error,
178 );
179 // Re-throw or format the error for the LLM
180 throw new Error(
181 `Execution failed for MCP tool '${toolName}': ${
182 error instanceof Error ? error.message : String(error)
183 }`, { cause: error },
184 );
185 }
186 };
187
188 actions.push({
189 name: toolName,

Calls 2

executeMethod · 0.65
errorMethod · 0.65

Tested by 3

createElysiaSingleServerFunction · 0.40
createElysiaMultiServerFunction · 0.40

Used in the wild real call sites across dependent graphs

searching dependent graphs…