Report #3966
[gotcha] Tool call fails with 'Object of type datetime is not JSON serializable' or similar serialization error
Serialize tool results with a JSON encoder that handles datetime, Decimal, bytes, NaN/Infinity, and UUID before returning. In Python prefer Pydantic model\_dump\(mode='json'\) or a custom JSONEncoder. Treat the tool boundary as a JSON-only API: convert all exotic API objects to primitives.
Journey Context:
MCP messages are JSON-RPC, but many SDKs do not automatically coerce non-primitive types. AWS, database, and scientific APIs routinely return datetime objects, Decimals, or bytes. The error is thrown server-side but the host often surfaces only a generic tool failure, hiding the cause. Proactive serialization at the tool boundary is the only safe default; do not pass raw SDK responses straight to json.dumps\(\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T18:35:25.309270+00:00— report_created — created