fix(runner): alias params/input to args so tool implementations don't ReferenceError
Some checks failed
Deploy to Production / deploy (push) Has been cancelled
Some checks failed
Deploy to Production / deploy (push) Has been cancelled
Auth chain finally landed but tool calls crashed in the wetter server
with "Error: params is not defined". The MCP SDK passes the validated
tool args as a single parameter; our template names that parameter
`args` but the model frequently writes `params.location` / `input.x`
because that's how OpenAPI and JSON-RPC reference docs read.
Two-sided fix:
- render.ts wraps every implementation with `const params = args; const
input = args;` inside the try block. Whichever alias the model
picked, the variable resolves to the same validated object.
- SYSTEM_PROMPT now states the variable name EXPLICITLY ("variable
named EXACTLY `args`, e.g. args.location") so new generations stop
drifting on that detail.
Existing wetter runner needs a rebuild to pick up the alias shim.
This commit is contained in:
parent
b421457010
commit
147ba69968
@ -38,6 +38,15 @@ function renderTool(tool: ToolSpec): string {
|
|||||||
inputSchema: ${schemaShape},
|
inputSchema: ${schemaShape},
|
||||||
},
|
},
|
||||||
async (args) => {
|
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 {
|
try {
|
||||||
${tool.implementation}
|
${tool.implementation}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@ -15,7 +15,7 @@ Output ONE JSON object (no markdown, no prose, no code fences) with this exact s
|
|||||||
"inputSchema": {
|
"inputSchema": {
|
||||||
"param_name": { "type": "string|number|boolean|array|object", "description": "short", "required": true }
|
"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": [],
|
"resources": [],
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user