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.
This commit is contained in:
westhood 2025-06-02 23:10:21 +08:00 committed by GitHub
parent 3e7b2863e9
commit 775d3e237e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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."