modelcontextprotocol / modelcontextprotocol/python-sdk

HTTP transport swallows non-2xx status codes causing client to hang

Open
#2,110 7 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P1 v2
Dominant language
Python
Stars
24.3k
Forks
4k
Avg merge
1d 1h
Merged PRs (30d)
31

Description

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

  • #1742 — broader typed error classes design

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing error handling in src/mcp/client/streamable_http.py, especially post_writer, and src/mcp/client/sse.py, especially sse_reader. Review related issue #1742 for the typed error design. Done means non-2xx responses reach the caller as exceptions, retain their HTTP status, distinguish 401/403, and no longer leave callers waiting indefinitely.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.