Skip to content

feat: add structured-only tool results that skip the text mirror#1046

Open
olaservo wants to merge 2 commits into
modelcontextprotocol:mainfrom
olaservo:structured-content-mirror-optout
Open

feat: add structured-only tool results that skip the text mirror#1046
olaservo wants to merge 2 commits into
modelcontextprotocol:mainfrom
olaservo:structured-content-mirror-optout

Conversation

@olaservo

@olaservo olaservo commented Jul 24, 2026

Copy link
Copy Markdown
Member

CallToolResult::structured and structured_error always mirror the structured value into content as serialized text, doubling large payloads. The spec marks that mirror as a SHOULD, not a MUST.

This PR makes the mirror optional. Opting out is explicit, since the mirror is the compatibility path for clients that do not read structuredContent:

  • CallToolResult::structured_only / structured_error_only — constructors that leave content empty
  • StructuredOnly<T> — return-type wrapper, a sibling of Json<T>, for #[tool] methods; the tool macro derives outputSchema from it the same way it does for Json<T>
  • CallToolResult::with_content — replaces the content blocks, so a structured result can pair structuredContent with a custom rendering (e.g. a short text summary) instead of the verbatim mirror; the two fields need not carry the same data

CallToolResult::structured and structured_error always mirror the
structured value into content as serialized text, doubling large
payloads. Add explicit opt-outs, never the default since the mirror is
the only compatibility path for clients that do not read
structuredContent:

- CallToolResult::structured_only / structured_error_only constructors
  that leave content empty
- StructuredOnly<T> return-type wrapper, a sibling of Json<T>, for use
  with #[tool] methods; the tool macro derives outputSchema from it the
  same way it does for Json<T>

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@olaservo
olaservo requested a review from a team as a code owner July 24, 2026 03:21
@github-actions github-actions Bot added T-test Testing related changes T-core Core library changes T-handler Handler implementation changes T-macros Macro changes labels Jul 24, 2026
…endering

content and structuredContent need not match: with_content replaces the
content blocks on any result, so a structured_only result can carry a
short text summary while structuredContent holds the full value.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-core Core library changes T-handler Handler implementation changes T-macros Macro changes T-test Testing related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant