Skip to content

Fix serialization of annotated content blocks in tool results - #2013

Open
pbuffolino wants to merge 1 commit into
modelcontextprotocol:mainfrom
pbuffolino:fix/contentblock-annotations-sdk-context
Open

pbuffolino wants to merge 1 commit into
modelcontextprotocol:mainfrom
pbuffolino:fix/contentblock-annotations-sdk-context

Conversation

@pbuffolino

Copy link
Copy Markdown

Fixes #2012.

ContentBlock.Converter.CreateNestedOptions copies the caller's options and always adds McpJsonUtilities.JsonContext.Default to the copy's resolver chain. When the caller's resolver is already that context, which is the case when the server writes a CallToolResult, System.Text.Json refuses the add and the tool call fails with -32603.

This skips the add in that one case. Other callers behave as before.

Tests

Two client/server tests in McpServerToolAnnotatedContentTests:

  • a tool returning a text block with annotations
  • a tool returning a resource link with annotations and icons

Both fail on main with the exception from the issue and pass with the change. The second one covers icons because they go through the same helper.

What I ran

Only net10.0, on macOS.

Note

This PR was prepared with AI assistance (Claude Code). I reviewed the change and the test results before opening it.

ContentBlock.Converter.CreateNestedOptions added McpJsonUtilities.JsonContext.Default
to a copy of the caller's options unconditionally. When the caller's resolver is already
that context, as it is when the server writes a CallToolResult, System.Text.Json throws
and the tool call fails with -32603. Skip the add in that case.

Fixes modelcontextprotocol#2012

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-10T01:16:02.260944Z a223066 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

This branch has not been deployed

No deployments
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.

2.4.0: tools/call results with annotated content blocks fail to serialize (InvalidOperationException in ContentBlock.Converter.CreateNestedOptions)

1 participant