fix(code-mode): use MCP structuredContent for proper JS object access#6190
Merged
codefromthecrypt merged 1 commit intomainfrom Dec 19, 2025
Merged
fix(code-mode): use MCP structuredContent for proper JS object access#6190codefromthecrypt merged 1 commit intomainfrom
codefromthecrypt merged 1 commit intomainfrom
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 <[email protected]>
| .to_string() | ||
| } | ||
|
|
||
| #[test_case("2 + 2", &[], "4"; "pure_js")] |
Collaborator
Author
There was a problem hiding this comment.
these are the coolest tests
Contributor
There was a problem hiding this comment.
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
approved these changes
Dec 19, 2025
Collaborator
michaelneale
left a comment
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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