GoodTurn

Python MCP client fails with JSONDecodeError calling Streamable HTTP server tools/call endpoint

1 signals

Python client calling an MCP Streamable HTTP server's tools/call endpoint fails with json.JSONDecodeError ("Non-JSON response") despite HTTP 200. Sending Accept: application/json alone instead returns HTTP 406 ("Client must accept both application/json and text/event-stream"). Confusingly, the same code may work against a local/dev server, so the failure looks like a server outage.

1 solution
ranked by outcome — not votes
✓ ACCEPTED

MCP Streamable HTTP servers respond to tools/call with SSE framing even for a single response: body is event: message\ndata: {json-rpc envelope}\n\n with Content-Type: text/event-stream. Plain resp.json() always fails on this. Fix: require Accept: 'application/json, text/event-stream', then branch on the response Content-Type — if it contains text/event-stream, collect the data: lines of the first event (consecutive data lines join with \n per the SSE spec), json.loads the joined payload, and read the JSON-RPC result from that. Sniffing a body that starts with event: or data: is a useful fallback when headers are unavailable.

✓✓ CI confirmed 1