Skip to content

Python: [Bug]: Anthropic MCP tool result replay sends Content objects instead of text blocks #9970

Closed

Description

@uragoodman

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

  1. Build a Message containing an mcp_server_tool_result with output=[Content.from_text("hello")].
  2. Call AnthropicClient._prepare_message_for_anthropic(message).
  3. 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

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.

Activity

  1. added
    pythonUsage: [Issues, PRs], Target: Python
    triageUsage: [Issues], Target: All issues that still need to be triaged
    on Nov 2, 2026
  2. added
    reproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflow
    on Nov 2, 2026
  3. github-actions commented on Nov 2, 2026

    @github-actions
    Contributor

    🤖 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_anthropic at lines 1296-1301 when an mcp_server_tool_result has output containing framework Content objects. The parser at _parse_contents_from_anthropic lines 1761-1788 produces this shape for Anthropic MCP result blocks. Minimal repro: prepare a tool-role Message with output=[Content.from_text("hello")] and pass the result to json.dumps.

    • Failing test: python/packages/anthropic/tests/test_anthropic_client.py::test_prepare_message_for_anthropic_mcp_server_tool_result_content_list_is_json_serializable
    • Files examined: python/packages/anthropic/agent_framework_anthropic/_chat_client.py, python/packages/anthropic/tests/test_anthropic_client.py, python/packages/anthropic/pyproject.toml, docs/specs/004-python-function-calling-loop.md
    • Tests run: test_prepare_message_for_anthropic_mcp_server_tool_result_content_list_is_json_serializable, test_prepare_message_for_anthropic_mcp_server_tool_result, test_prepare_message_for_anthropic_mcp_server_tool_result_none_output
    • Reported version: 1.0.0b261030
    • Current version: 1.0.0b261030
  4. added
    agentsUsage: [Issues, PRs], Target: Single agent
    and removed
    triageUsage: [Issues], Target: All issues that still need to be triaged
    on Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

agentsUsage: [Issues, PRs], Target: Single agentpythonUsage: [Issues, PRs], Target: PythonreproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflow

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions