Skip to content

Commit 775d3e2

Browse files
authored
Ensure item.model_dump only contains JSON serializable types (#801)
The EmbeddedResource from MCP tool call contains a field with type AnyUrl that is not JSON-serializable. To avoid this exception, use item.model_dump(mode="json") to ensure a JSON-serializable return value.
1 parent 3e7b286 commit 775d3e2

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/agents/mcp/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ async def invoke_mcp_tool(
116116
if len(result.content) == 1:
117117
tool_output = result.content[0].model_dump_json()
118118
elif len(result.content) > 1:
119-
tool_output = json.dumps([item.model_dump() for item in result.content])
119+
tool_output = json.dumps([item.model_dump(mode="json") for item in result.content])
120120
else:
121121
logger.error(f"Errored MCP tool result: {result}")
122122
tool_output = "Error running tool."

0 commit comments

Comments
 (0)