diff --git a/apps/generator/src/lib/render.ts b/apps/generator/src/lib/render.ts index 179a104..9705179 100644 --- a/apps/generator/src/lib/render.ts +++ b/apps/generator/src/lib/render.ts @@ -38,6 +38,15 @@ function renderTool(tool: ToolSpec): string { inputSchema: ${schemaShape}, }, async (args) => { + // The MCP SDK passes the validated tool arguments as the single + // parameter. Models trained on OpenAPI / JSON-RPC examples reach + // for "params" instead of "args", and "input" shows up too — bind + // every common alias to the same object so the generated body + // works whichever name the model picked. Without this the runner + // crashes with "ReferenceError: params is not defined" at the + // first tool call (verified in prod with the wetter server). + const params = args; + const input = args; try { ${tool.implementation} } catch (err) { diff --git a/packages/llm/src/index.ts b/packages/llm/src/index.ts index 1c2c546..a62f155 100644 --- a/packages/llm/src/index.ts +++ b/packages/llm/src/index.ts @@ -15,7 +15,7 @@ Output ONE JSON object (no markdown, no prose, no code fences) with this exact s "inputSchema": { "param_name": { "type": "string|number|boolean|array|object", "description": "short", "required": true } }, - "implementation": "async TS body, return { content: [{ type:'text', text:'...' }] }; secrets via process.env; HTTP via globalThis.fetch with AbortSignal.timeout(10000); try/catch -> { content:[{type:'text',text:'Error: ...'}], isError:true }; no eval/Function/child_process; no imports." + "implementation": "async TS body. The tool's validated arguments arrive in the variable named EXACTLY `args` (e.g. args.location, args.query). Return { content: [{ type:'text', text:'...' }] }. Secrets via process.env. HTTP via globalThis.fetch with AbortSignal.timeout(10000). Wrap external calls in try/catch and return { content:[{type:'text',text:'Error: ...'}], isError:true } on failure. No eval/Function/child_process. No import statements." } ], "resources": [],