Repository navigation
Fix serialization of annotated content blocks in tool results - #2013
pbuffolino wants to merge 1 commit into
Conversation
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 <noreply@anthropic.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Coding-Professional
left a comment
There was a problem hiding this comment.
Reviewed the resolver guard and both client/server regression tests. The guard addresses the reported failure: when the SDK context is already the copied options' resolver, appending that same context to its resolver chain throws. Other caller resolvers still receive the SDK context as fallback.
Verified on PR head a2230665:
- .NET 10: 2/2 new
McpServerToolAnnotatedContentTestspassed. - .NET 8: 157/157 combined
ContentBlockTestsand new tests passed.
I did not find a blocking issue. I could not run the .NET 9 target locally because its runtime is not installed here.
Fixes #2012.
ContentBlock.Converter.CreateNestedOptionscopies the caller's options and always addsMcpJsonUtilities.JsonContext.Defaultto the copy's resolver chain. When the caller's resolver is already that context, which is the case when the server writes aCallToolResult, 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:Both fail on
mainwith 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.tests/ModelContextProtocol.Tests: 3676 passed, 5 skipped, 1 failed. The failure isDockerEverythingServerTests.Sampling_Sse_EverythingServer("Unknown tool: trigger-sampling-request"), and it fails the same way without this change.tests/ModelContextProtocol.AspNetCore.Tests: 754 passed, 45 skipped.Note
This PR was prepared with AI assistance (Claude Code). I reviewed the change and the test results before opening it.