Skip to content

Preserve explicit tool response content#469

Open
jstar0 wants to merge 1 commit into
modelcontextprotocol:mainfrom
jstar0:fix/preserve-explicit-tool-content
Open

Preserve explicit tool response content#469
jstar0 wants to merge 1 commit into
modelcontextprotocol:mainfrom
jstar0:fix/preserve-explicit-tool-content

Conversation

@jstar0

@jstar0 jstar0 commented Jul 22, 2026

Copy link
Copy Markdown

Summary

Fixes #467.

Tool::Response normalized omitted content, explicit nil, and explicit []
to the same empty array. The structured-content compatibility fallback then
treated every empty array as absent. It also classified JSON objects with a
Ruby Hash check, so adapters such as representable objects that serialize to
JSON objects were treated as non-object values.

Together, those behaviors could add synthesized text content even when a tool
explicitly selected an empty content array, causing clients to expose the
same result twice.

Changes

  • Preserve whether non-nil content was explicitly supplied to
    Tool::Response.
  • Classify non-Hash structured values by their serialized JSON root shape.
  • Add regressions for object-like values, explicit empty content, and the
    omitted/nil compatibility fallback.

The wire shape and existing fallback for omitted or nil content with array or
scalar structured values remain unchanged.

Verification

bundle exec ruby -I lib -I test test/mcp/tool/response_test.rb
bundle exec ruby -I lib -I test test/mcp/server_test.rb
bundle exec rake
bundle exec yard --no-output
bundle exec gem build mcp.gemspec

All checks passed. The default Rake task covered RuboCop, 1,434 Ruby tests, 40
server conformance checks, and 280 client conformance checks.

Breaking Changes

None.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

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.

Response content is silently exchanged when structured content is not a hash

1 participant