Skip to content

Conversation

@codefromthecrypt
Copy link
Collaborator

Summary

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

Type of Change

  • Feature
  • Bug fix
  • Refactor / Code quality
  • Performance improvement
  • Documentation
  • Tests
  • Security fix
  • Build / Release
  • Other (specify below)

AI Assistance

  • This PR was created or reviewed with AI assistance

Testing

After this ONE SHOT even with a crappy model, it knew that the call had an structured output field

$ cargo run -p goose-cli --release -- run --text "Search for get_file_info and write_file tools. Use them to save info about $PWD to $PWD/result.txt." --with-builtin code_execution --with-extension "npx -y @modelcontextprotocol/server-filesystem $PWD"
   Compiling goose v1.17.0 (/Users/codefromthecrypt/oss/goose/crates/goose)
   Compiling goose-bench v1.17.0 (/Users/codefromthecrypt/oss/goose/crates/goose-bench)
   Compiling goose-cli v1.17.0 (/Users/codefromthecrypt/oss/goose/crates/goose-cli)
    Finished `release` profile [optimized] target(s) in 52.12s
     Running `target/release/goose run --text 'Search for get_file_info and write_file tools. Use them to save info about /Users/codefromthecrypt/oss/goose to /Users/codefromthecrypt/oss/goose/result.txt.' --with-builtin code_execution --with-extension 'npx -y @modelcontextprotocol/server-filesystem /Users/codefromthecrypt/oss/goose'`
starting session | provider: tetrate model: gpt-5-nano
    session id: 20251219_24
    working directory: /Users/codefromthecrypt/oss/goose

─── read_module | code_execution ──────────────────────────
module_path: goose_b051fheg


─── execute_code | code_execution ──────────────────────────
code: import { get_file_info, write_file } from "goose_b051fheg";
                                                                                                                                                                                                                          
const sourcePath = "/Users/codefromthecrypt/oss/goose";                                                                                                                                                                   
const destPath = "/Users/codefromthecrypt/oss/goose/result.txt";                                                                                                                                                          
                                                                                                                                                                                                                          
const info = get_file_info...                                                                                                                                                                                             

I have saved the file information to /Users/codefromthecrypt/oss/goose/result.txt.

Details:
- Source path queried: /Users/codefromthecrypt/oss/goose
- Destination: /Users/codefromthecrypt/oss/goose/result.txt
- Operation: Retrieved file metadata and wrote it to the destination

If you want the metadata in a different format (JSON, YAML, etc.) or want additional fields, tell me and I can adjust.

Related Issues

Relates to #6188

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")]
Copy link
Collaborator Author

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

@codefromthecrypt codefromthecrypt marked this pull request as ready for review December 19, 2025 07:46
Copilot AI review requested due to automatic review settings December 19, 2025 07:46
Copy link
Contributor

Copilot AI left a 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_content from MCP responses over plain text content
  • Extracts parse_result_to_js helper to consistently coerce tool results into proper JavaScript values
  • Enhances type signature generation to display detailed object/array structures instead of generic "object" labels

Copy link
Collaborator

@michaelneale michaelneale left a 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. 

@codefromthecrypt codefromthecrypt merged commit 41588e8 into main Dec 19, 2025
25 checks passed
@codefromthecrypt codefromthecrypt deleted the fix-output-schema-display branch December 19, 2025 07:58
joahg pushed a commit to joahg/goose that referenced this pull request Dec 22, 2025
…block#6190)

Signed-off-by: Adrian Cole <adrian@tetrate.io>
Signed-off-by: Joah Gerstenberg <joah@squareup.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants