You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Python: [Bug][Python][AG-UI] MCP tool results containing TextContent list are incorrectly serialized to object repr string #2509
When using MCP tools with the AG-UI protocol, tool results containing list[TextContent] are incorrectly serialized. Instead of
extracting the text content, the serialization produces Python object repr strings like:
[<agent_framework._types.TextContent object at 0x7f8e7c1cc730>]
This results in the frontend displaying raw object addresses instead of actual tool output data.
To Reproduce
Set up an AG-UI endpoint using AgentFrameworkAgent with MCP tools
Invoke any MCP tool that returns text content
Observe the MessagesSnapshotEvent or tool result display
Expected behavior
Tool results should be properly serialized to display the actual text content, e.g.:
{"role": "tool", "content": "Actual tool output text here..."}
Root cause analysis
The issue is in agent_framework_ag_ui/_events.py around line 415-418:
When MCP tools return results, they go through _mcp_call_tool_result_to_ai_contents() in agent_framework/_mcp.py:69-73, which
converts them to list[Contents] (typically list[TextContent]).
The current serialization logic doesn't handle list[TextContent] - it just calls str() on the list, producing the object repr
string.
Suggested fix
Update the serialization logic to handle list[Contents]:
This bug affects all MCP tool integrations when using the AG-UI protocol. It prevents proper display of tool results in frontend
applications like CopilotKit.
changed the title [-][Bug][Python][AG-UI] MCP tool results containing TextContent list are incorrectly serialized to object repr string[/-][+]Python: [Bug][Python][AG-UI] MCP tool results containing TextContent list are incorrectly serialized to object repr string[/+]on Nov 28, 2025
Activity
[-][Bug][Python][AG-UI] MCP tool results containing TextContent list are incorrectly serialized to object repr string[/-][+]Python: [Bug][Python][AG-UI] MCP tool results containing TextContent list are incorrectly serialized to object repr string[/+]Fix MCP tool result serialization for list[TextContent]
claude89757 commentedon Nov 28, 2025
I've submitted a fix for this issue in PR #2523.
The fix properly handles
list[TextContent]results from MCP tools by:textattributemodel_dump()for items that support itstr()for other typesThis ensures that MCP tool results are correctly serialized and displayed in AG-UI frontends.
Fix MCP tool result serialization for list[TextContent]
Python: Fix MCP tool result serialization for list[TextContent] (#2523)
.NET: Python: Merge main into feature-durabletask-python branch (#3160)
Python: Merge `main` into `feature-durabletask-python` branch (#3261)
.NET: Python: Merge `main` into `feature-durabletask` branch (#3385)
Python: Merge `durabletask` changes into `main` (#3420)
Python: Fix MCP tool result serialization for list[TextContent] (micr…