Streamable HTTP client drops the HTTP status of an error response

Offen Anfängerfreundlich
#3,857 3 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

  • #3870 von @tang-ontheway — ohne Merge geschlossen

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
70/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
python
Bereich
api, networking

Rechercherichtung

Der generische Fehler wird in mcp/client/streamable_http.py erzeugt, wo eine Antwort mit Status ungleich 2xx in ein ErrorData mit der Meldung "Server returned an error response" umgewandelt wird. Beginne dort und prüfe, welche Werte aus der Antwort (Statuscode, Reason Phrase, URL) an dieser Stelle noch im Gültigkeitsbereich sind. Nimm den Status sowohl in die Meldung als auch in ein Datenfeld wie http_status auf und bestätige dann, dass ein 401 und ein 502 in den Client-Tests unterschiedliche Fehler erzeugen. Fertig ist, wenn Aufrufer den Status ohne einen eigenen Response-Hook auslesen können.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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).

Vorherrschende Sprache
Python
Sterne
25k
Forks
4.2k
Ø Merge
10 Min.
Gemergte PRs (30 T.)
1

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus modelcontextprotocol/python-sdk

Alle Issues in modelcontextprotocol/python-sdk

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.