Repository navigation
Python: serialize Anthropic MCP tool result content on replay - #9972
Merged
Eduard van Valkenburg (eavanvalkenburg) merged 5 commits intoNov 4, 2026
Conversation
Render parsed Anthropic MCP results as JSON-serializable text blocks instead of Content objects, and cover list, top-level mapping, and persisted-history replay with regression tests. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Kip (uragoodman)
requested review from
SergeyMenshykh,
Eduard van Valkenburg (eavanvalkenburg) and
Roger Barreto (rogerbarreto)
as code owners
November 2, 2026 13:10
Kip (uragoodman)
temporarily deployed
to
github-app-auth
November 2, 2026 13:10 — with
GitHub Actions
Inactive
Kip (uragoodman)
requested review from
Darren Cohen (dargilco),
Jose Alvarez (jpalvarezl),
sophia-ramsey and
westey (westey-m)
as code owners
November 2, 2026 13:10
Kip (uragoodman)
temporarily deployed
to
github-app-auth
November 2, 2026 13:10 — with
GitHub Actions
Inactive
…ool-result-replay
Kip (uragoodman)
temporarily deployed
to
github-app-auth
November 2, 2026 13:12 — with
GitHub Actions
Inactive
Kip (uragoodman)
temporarily deployed
to
github-app-auth
November 3, 2026 00:53 — with
GitHub Actions
Inactive
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Persist the provider's is_error flag in Anthropic metadata so MCP tool results replay with the same error status after serialization. Tighten the replay output contract to a concrete union and reject unsupported shapes instead of stringifying them. Add streaming, non-streaming, persistence, and unsupported-output regression tests. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Kip (uragoodman)
temporarily deployed
to
github-app-auth
November 3, 2026 13:46 — with
GitHub Actions
Inactive
Eduard van Valkenburg (eavanvalkenburg)
approved these changes
Nov 4, 2026
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation & Context
Anthropic's provider-hosted MCP connector returns
mcp_tool_resultblocks whose content is parsed intolist[Content]. On the next turn,_prepare_message_for_anthropiccopiedcontent.outputdirectly into the request body, so the Anthropic SDK failed with:The first request succeeds; every subsequent turn that replays the MCP result fails before the request is sent.
This change normalizes MCP tool result output into the shapes Anthropic accepts for
mcp_tool_result.content: a string or a list of text blocks.Description & Review Guide
_prepare_mcp_tool_result_contentto convertNone, strings, top-level mappings, andSequence[Content] | Sequence[Mapping]into Anthropic-compatible content.mcp_server_tool_resultnow uses this helper instead of emittingcontent.outputunchanged.Contentitems become{"type": "text", "text": ...}; non-text items are skipped with a debug log because the Anthropicmcp_tool_resultschema only accepts text.TypeError.function_result.Noneoutputs keep their previous wire shape.mcp_tool_result.The diff also contains one
ruff formatadjustment to an existing over-wrapped call in the same file; it is required by the repository formatter.Testing
pytest packages/anthropic/tests -m "not integration" -q— 259 passedruff format --check— passruff check --no-fix— passpyright --pythonpath .venv/Scripts/python.exe packages/anthropic/agent_framework_anthropic— 0 errorsmypy packages/anthropic/tests/test_anthropic_client.py— no issuesFull workspace build and the full unit-test suite were not run locally; CI will run them.
Related Issue
Fixes #9970
The issue is filed; opening this focused fix for maintainer review. No
ready-for-implementationlabel was present when this PR was opened.AI Assistance
AI assistance details: implementation, tests, and PR description were drafted with an AI coding assistant; I reproduced and verified the failure and the fix locally.
Contribution Checklist
ready-for-implementationlabel was present when opened, and the PR is submitted for early direction feedback.