modelcontextprotocol / modelcontextprotocol/python-sdk

401 in Streamable HTTP should be handled gracefully

Offen
#1,295 2 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug P2 ready for work
Vorherrschende Sprache
Python
Sterne
24.3k
Forks
4k
Ø Merge
1 T. 1 Std.
Gemergte PRs (30 T.)
31

Beschreibung

Initial Checks
Description

Currently, streamable_http will call response.raise_for_status() when handling POST requests. (ref).

This means that a 401 will bubble up and cause the entire program to crash.

While a 401 on server initialize could warrant an exception, we have a use case where a MCP server will return 401 for specific unauthorized operations, and allow others.

This should be handled gracefully, similar to how _handle_unexpected_content_type works, returning a JSONRPC message outlining an unauthorized exception was thrown.

This would let an agent or other client handle it instead of crashing the program.

Python & MCP Python SDK
Python 3.12 and MCP SDK v1.13.1

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginnen Sie in src/mcp/client/streamable_http.py bei der POST-Behandlung rund um response.raise_for_status(), und vergleichen Sie sie anschließend mit _handle_unexpected_content_type. Verfolgen Sie, wie HTTP-Fehler zu Client-Ergebnissen werden; fertig ist die Aufgabe, wenn eine 401-Antwort von einer nicht autorisierten Operation eine JSON-RPC-Fehlermeldung unauthorized erzeugt, die der Client ohne Absturz verarbeiten kann.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
api
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Aktiv
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
74/100

Neue Issues direkt in Ihr Postfach

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