From 775d3e237efd4686bb98aca11ac96c0488ac1fd8 Mon Sep 17 00:00:00 2001 From: westhood Date: Mon, 2 Jun 2025 23:10:21 +0800 Subject: [PATCH] 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. --- src/agents/mcp/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/agents/mcp/util.py b/src/agents/mcp/util.py index bbfe188..5a963bc 100644 --- a/src/agents/mcp/util.py +++ b/src/agents/mcp/util.py @@ -116,7 +116,7 @@ class MCPUtil: if len(result.content) == 1: tool_output = result.content[0].model_dump_json() elif len(result.content) > 1: - tool_output = json.dumps([item.model_dump() for item in result.content]) + tool_output = json.dumps([item.model_dump(mode="json") for item in result.content]) else: logger.error(f"Errored MCP tool result: {result}") tool_output = "Error running tool."