Streamable HTTP client drops the HTTP status of an error response

Aperta Adatta ai principianti
#3,857 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

  • #3870 di @tang-ontheway — chiusa senza merge

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
70/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
api, networking

Direzione di ricerca

L'errore generico viene costruito in mcp/client/streamable_http.py, dove la risposta non 2xx viene convertita in un ErrorData con il messaggio "Server returned an error response". Inizia da lì e verifica quali valori della risposta (codice di stato, reason phrase, URL) sono ancora nel campo di visibilità in quel punto. Mantieni lo stato nel messaggio e in un campo dati come http_status, quindi conferma che un 401 e un 502 producono errori diversi nei test del client. Il lavoro è completato quando i chiamanti possono leggere lo stato senza un hook di risposta personalizzato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement
What happens

When the server (or a proxy or gateway in front of it) answers a JSON-RPC request with a non-2xx status and no JSON-RPC error body, the streamable HTTP client replaces the response with a generic error:

# mcp/client/streamable_http.py (main and 2.3.0)
error_data = ErrorData(code=INTERNAL_ERROR, message="Server returned an error response")

The status code, reason phrase and URL are dropped, so a caller cannot tell a 401 from a 502 or a 504. Every non-404 HTTP failure reaches the caller as the same -32603 error.

Why it matters
  • Callers cannot decide whether a failure is worth retrying (a gateway 502/503/504) or not (a 401, 403 or 413).
  • Logs and user-facing errors cannot name the cause. We saw this with an install whose MCP URL went through an auth proxy: every call failed with a 401, and all we could log was "Server returned an error response".
Suggestion

Keep the HTTP status in the error, for example ErrorData(code=INTERNAL_ERROR, message=f"Server returned an error response ({status} {reason})", data={"http_status": status}), so callers can branch on it without a response hook of their own.

Versions

mcp 2.3.0 (checked against main as well).

Lingua principale
Python
Stelle
25k
Fork
4.2k
Merge medio
10m
PR unite (30g)
1

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di modelcontextprotocol/python-sdk

Tutte le issue di modelcontextprotocol/python-sdk

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.