modelcontextprotocol / modelcontextprotocol/python-sdk
HTTP transport swallows non-2xx status codes causing client to hang
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 24.3k
- Fork
- 4k
- Merge medio
- 1g 1h
- PR unite (30g)
- 31
Descrizione
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_writerin 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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia tracciando la gestione degli errori in src/mcp/client/streamable_http.py, in particolare post_writer, e in src/mcp/client/sse.py, in particolare sse_reader. Esamina la issue correlata #1742 relativa alla progettazione degli errori tipizzati. Il lavoro è completato quando le risposte non-2xx raggiungono il chiamante come eccezioni, mantengono il proprio stato HTTP, distinguono tra 401/403 e non lasciano più i chiamanti in attesa indefinitamente.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- api, backend
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Tranquilla
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 48/100