modelcontextprotocol / modelcontextprotocol/python-sdk

ExceptionGroup wrapping obscures real errors from task groups

Offen
#2,114 3 Kommentare 2 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug P1 v2
Vorherrschende Sprache
Python
Sterne
24.3k
Forks
4k
Ø Merge
1 T. 1 Std.
Gemergte PRs (30 T.)
31

Beschreibung

Summary

When SDK internal anyio task group tasks fail, the real error is wrapped in a BaseExceptionGroup alongside Cancelled exceptions from cancelled sibling tasks. This makes error classification extremely difficult for callers — they cannot reliably determine the root cause of a failure.

There are 16 create_task_group() usages across the SDK with no except* syntax or ExceptionGroup unwrapping anywhere.

Expected Behavior

  • Callers should receive the original exception, not an ExceptionGroup wrapping it alongside cancellation noise
  • When a task group has one real failure and N cancelled siblings, only the real failure should propagate

Current Behavior

  • A single connection failure produces a BaseExceptionGroup containing the real error plus multiple Cancelled exceptions
  • Callers must manually unwrap exception groups to find the root cause
  • This affects ~80+ call sites across the SDK where task groups are used

Affected Code

  • src/mcp/shared/session.py (session task groups)
  • src/mcp/client/streamable_http.py (transport task groups)
  • All other create_task_group() sites

Related

  • #1742 — broader typed error classes design
  • #1830 — CancelledError indistinguishable from external cancellation (closed but related)

AI Disclaimer

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

Lies zunächst die Behandlung von Task-Gruppen in src/mcp/shared/session.py und src/mcp/client/streamable_http.py und untersuche anschließend die anderen im Issue erwähnten Stellen mit create_task_group(). Reproduziere einen Verbindungsfehler mit abgebrochenen Geschwister-Tasks und verifiziere, dass sich die tatsächliche Ausnahme über die betroffenen Aufrufstellen hinweg ohne Abbruchrauschen weiterverbreitet.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
backend
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Ruhig
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
48/100

Neue Issues direkt in Ihr Postfach

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