-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix(code-mode): use MCP structuredContent for proper JS object access #6190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Tool results with outputSchema (e.g. `{ content: string }`) were
returned as plain text. JS code like `result.content` returned
undefined because the MCP structuredContent field was ignored.
- Prioritize structuredContent from MCP response when available
- Extract parse_result_to_js helper for JSON→JsValue coercion
- Show output schema structure in signatures (not just `object`)
- Add lightweight tests proving structured vs plain text behavior
Signed-off-by: Adrian Cole <adrian@tetrate.io>
| .to_string() | ||
| } | ||
|
|
||
| #[test_case("2 + 2", &[], "4"; "pure_js")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these are the coolest tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a bug where MCP tool results with outputSchema were returned as plain text instead of structured JSON objects, causing JavaScript property access (e.g., result.content) to fail.
Key Changes:
- Prioritizes
structured_contentfrom MCP responses over plain text content - Extracts
parse_result_to_jshelper to consistently coerce tool results into proper JavaScript values - Enhances type signature generation to display detailed object/array structures instead of generic "object" labels
michaelneale
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very nice, and looking at live tests for code mode:
Provider: openrouter
Model: google/gemini-2.5-pro
starting session | provider: openrouter model: google/gemini-2.5-pro
session id: 20251219_1
working directory: /tmp/tmp.M5q6b81WPx
─── execute_code | code_execution ──────────────────────────
code: import { shell } from "developer";
shell({ command: "ls -la" });
```text
total 20
drwx------ 2 runner runner 4096 Dec 19 07:44 .
drwxrwxrwt 15 root root 12288 Dec 19 07:44 ..
-rw-r--r-- 1 runner runner 6 Dec 19 07:44 hello.txt
✓ SUCCESS: Test passed - code_execution tool called
first go! Much improved.
…block#6190) Signed-off-by: Adrian Cole <adrian@tetrate.io> Signed-off-by: Joah Gerstenberg <joah@squareup.com>
Summary
Tool results with outputSchema (e.g.
{ content: string }) were returned as plain text. JS code likeresult.contentreturned undefined because the MCP structuredContent field was ignored.object)Type of Change
AI Assistance
Testing
After this ONE SHOT even with a crappy model, it knew that the call had an structured output field
Related Issues
Relates to #6188