Summary
When an MCP server returns non-2xx HTTP status codes (401/403/404/5xx), the Streamable HTTP and SSE transports do not reliably propagate the error to the caller. In the Streamable HTTP transport, post_writer catches exceptions and logs them, but the caller blocks indefinitely waiting for a response on the read stream. HTTP 404 responses are also converted to JSONRPCError(code=32600), losing the original HTTP status information.
Expected Behavior
- Non-2xx HTTP responses should be surfaced as exceptions to the caller, not silently logged
- The original HTTP status code should be preserved and accessible
- Auth-related errors (401/403) should be distinguishable from other failures
Current Behavior
post_writer in Streamable HTTP transport catches and logs errors without forwarding them through the read stream
- Callers hang indefinitely waiting for a response
- HTTP 404 is converted to
JSONRPCError(code=32600), destroying HTTP-level context
Affected Code
src/mcp/client/streamable_http.py (post_writer)
src/mcp/client/sse.py (sse_reader)
Related