Support structuredContent in tool response #147
Merged
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.
This PR enables the inclusion of
structuredContentwithin tool call responses.Or, to conform with the spec's suggestion about backward compatibility, both
contentandstructured_contentmay be provided:Motivation and Context
Currently an
MCP::Toolwhich declares anoutput_schemabut does not providestructuredContentin its response is entirely incompatible with the many MCP clients that are built with the official Python SDK:See: modelcontextprotocol/python-sdk/src/mcp/client/session.py
In order to make Ruby SDK MCP servers useable with such clients we need to support
structuredContentin conformance with the spec forCallToolResult:See: https://modelcontextprotocol.io/specification/2025-06-18/schema#calltoolresult
See: https://modelcontextprotocol.io/specification/2025-06-18/server/tools#structured-content
@honzasterba had kindly submitted a similar PR #81 — this PR follows @koic's suggestion there.
How Has This Been Tested?
In addition to the unit tests, I have field tested this in an MCP server that utilizes this change in:
structuredContentagainst theoutput_schemaand confirms that thestructuredContentmatches the serializedcontentstructuredContent, so was fine before and after this change 🤷🏽Breaking Changes
None.
The tool response can be constructed as before, or in the new style:
Types of changes
Checklist
Additional context
I have not added documentation yet, but if this PR seems likely to be accepted I can definitely do so!Added now