Repository navigation
Labels
agentsUsage: [Issues, PRs], Target: Single agentUsage: [Issues, PRs], Target: Single agentpythonUsage: [Issues, PRs], Target: PythonUsage: [Issues, PRs], Target: PythonreproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflowUsage: [Issues], Target: all issues that can be reproduced by the triage workflow
Description
Observed Behavior
On the second turn of a conversation using Anthropic's provider-hosted MCP connector, replaying an mcp_tool_result fails with:
TypeError: Object of type Content is not JSON serializable
The parser stores MCP result content as list[Content], but _prepare_message_for_anthropic places content.output directly into the request body. The SDK cannot serialize it, so the request is never sent. The first request works; the failure is on replay.
The adjacent function_result branch already converts items into text/image blocks; the mcp_server_tool_result branch does not.
Verified on upstream main at 9f52e7155.
Expected Behavior
Replay should convert text items into {"type": "text", "text": ...} (or a string) and never put Content objects in the request. None should become "".
Steps to Reproduce
- Build a
Messagecontaining anmcp_server_tool_resultwithoutput=[Content.from_text("hello")]. - Call
AnthropicClient._prepare_message_for_anthropic(message). - Serialize the result with
json.dumps.
Minimal Reproduction
import json
from agent_framework import Content, Message
from agent_framework_anthropic import AnthropicClient
message = Message(
role="tool",
contents=[
Content.from_mcp_server_tool_result(
call_id="call_1",
output=[Content.from_text("hello")],
)
],
)
client = AnthropicClient(api_key="test", model="claude-3-5-sonnet-20241022")
prepared = client._prepare_message_for_anthropic(message)
print(prepared)
json.dumps(prepared)Observed:
{'role': 'user', 'content': [{'type': 'mcp_tool_result', 'tool_use_id': 'call_1', 'content': [<Content object>]}]}
TypeError: Object of type Content is not JSON serializable
Error Messages and Stack Traces
TypeError: Object of type Content is not JSON serializable
Package Versions
agent-framework-anthropic 1.0.0b261030
agent-framework-core 1.24.0
upstream main 9f52e7155
Python Version
3.11.17
Operating System
Windows
Regression
Unknown
Additional Context
- Relevant code on
9f52e7155:_prepare_message_for_anthropic, casemcp_server_tool_result(around line 1296);_parse_contents_from_anthropic, casemcp_tool_result(around line 1696). - The Anthropic SDK type
BetaRequestMCPToolResultBlockParam.contentisUnion[str, Iterable[BetaTextBlockParam]], soContentobjects are not valid there. - Related but different: Python: Fix Anthropic server-tool continuation and replay #9718 covers server-tool replay for web search/fetch; Python: [Bug]: Content.from_dict leaves the nested content of image generation and MCP server tool results as plain dicts #9303/Python: fix(core): rebuild nested Content of image generation and MCP tool results in Content.from_dict #9304 rebuild nested
ContentinContent.from_dict. - No duplicate found. I'd like to fix this and have a focused patch with regression tests ready.
- AI assistance: used for analysis and drafting; I reproduced and verified the behavior myself.
Acknowledgements
- I searched existing issues and did not find a duplicate.
- I personally verified this behavior and the reproduction details are authentic.
- I will wait for explicit maintainer agreement before starting implementation of a non-trivial change.
Metadata
Metadata
Labels
agentsUsage: [Issues, PRs], Target: Single agentUsage: [Issues, PRs], Target: Single agentpythonUsage: [Issues, PRs], Target: PythonUsage: [Issues, PRs], Target: PythonreproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflowUsage: [Issues], Target: all issues that can be reproduced by the triage workflow
Type
Projects
- StatusShow more project fieldsDone
Activity
github-actions commentedon Nov 2, 2026
🤖 Automated triage reproduction notes (agent-authored — trust but verify)
Agent analysis
The bug reproduces in
python/packages/anthropic/agent_framework_anthropic/_chat_client.py::_prepare_message_for_anthropicat lines 1296-1301 when anmcp_server_tool_resulthasoutputcontaining frameworkContentobjects. The parser at_parse_contents_from_anthropiclines 1761-1788 produces this shape for Anthropic MCP result blocks. Minimal repro: prepare a tool-roleMessagewithoutput=[Content.from_text("hello")]and pass the result tojson.dumps.python/packages/anthropic/tests/test_anthropic_client.py::test_prepare_message_for_anthropic_mcp_server_tool_result_content_list_is_json_serializable1.0.0b2610301.0.0b261030