From d8a0ffe643712fc0f8251286ebb94b16b0059080 Mon Sep 17 00:00:00 2001 From: rabi Date: Fri, 6 Feb 2026 14:39:02 +0530 Subject: [PATCH] fix: fix snake_case function names in code_execution instructions The execute tool description used snake_case function names (e.g., `Developer.text_editor`, `Github.create_issue`) but the TypeScript runtime expects camelCase (`Developer.textEditor`, `Github.createIssue`) since pctx_codegen converts all MCP tool names to camelCase. This causes TS2551 type errors at runtime. Also: - Added explicit "Function names are always camelCase" rule with examples. - Added HANDLING RETURN VALUES section: many MCP tools return wrapper objects not raw arrays, causing `TypeError: x.filter is not a function` when LLMs assume array returns. Signed-off-by: rabi --- .../src/agents/code_execution_extension.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/crates/goose/src/agents/code_execution_extension.rs b/crates/goose/src/agents/code_execution_extension.rs index 535851d02574..2f9371f54bcc 100644 --- a/crates/goose/src/agents/code_execution_extension.rs +++ b/crates/goose/src/agents/code_execution_extension.rs @@ -342,7 +342,7 @@ impl McpClientTrait for CodeExecutionClient { Get detailed type information for specific functions. Provide a list of function identifiers in the format "Namespace.functionName" - (e.g., "Developer.shell", "Github.create_issue"). + (e.g., "Developer.shell", "Github.createIssue"). Returns full TypeScript interface definitions with parameter types, return types, and descriptions for the requested functions. @@ -365,9 +365,9 @@ impl McpClientTrait for CodeExecutionClient { SYNTAX - TypeScript with async run() function: ```typescript async function run() { - // Access functions via Namespace.functionName({ params }) + // Access functions via Namespace.functionName({ params }) — always camelCase const files = await Developer.shell({ command: "ls -la" }); - const readme = await Developer.text_editor({ path: "./README.md", command: "view" }); + const readme = await Developer.textEditor({ path: "./README.md", command: "view" }); return { files, readme }; } ``` @@ -384,13 +384,16 @@ impl McpClientTrait for CodeExecutionClient { KEY RULES: - Code MUST define an async function named `run()` - All function calls are async - use `await` - - Access functions as Namespace.functionName() (e.g., Developer.shell, Github.create_issue) + - Function names are always camelCase (e.g., Developer.textEditor, Github.listIssues, Github.createIssue) - Return value from `run()` is the result, all `console.log()` output will be returned as well. - - Only functions from `list_functions()` are available - no `fetch()`, fs, or other Node/Deno APIs + - Only functions from `list_functions()` and `console` methods are available — no `fetch()`, `fs`, or other Node/Deno APIs - Variables don't persist between `execute()` calls - return or log anything you need later - - Add console.log() statements between API calls to track progress if errors occur - - Code runs in an isolated Deno sandbox with restricted network access - - If a function returns `any` do not assume it has any particular fields + - Code runs in an isolated sandbox with restricted network access + + HANDLING RETURN VALUES: + - If a function returns `any`, do NOT assume its shape - log it first: `console.log(JSON.stringify(result))` + - Many functions return wrapper objects, not raw arrays - check the response structure before calling .filter(), .map(), etc. + - Always inspect unfamiliar return values with console.log() before processing them TOKEN USAGE WARNING: This tool could return LARGE responses if your code returns big objects. To minimize tokens: