modelcontextprotocol / modelcontextprotocol/python-sdk
Refactor handler context to be transport- and handler-type-aware
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 24.3k
- Forks
- 4k
- Ø Merge
- 1 T. 1 Std.
- Gemergte PRs (30 T.)
- 31
Beschreibung
The current RequestContext / ServerRequestContext design has a few rough edges that warrant a dedicated refactor:
-
Request vs notification context — Request handlers have
request_idandmeta, notification handlers do not. Currentlyrequest_idis optional (RequestId | None) on a single shared type, which loses type safety. Ideally these would be distinct types so request handlers get a context whererequest_idis always present, and notification handlers get one where it does not exist. -
Transport-specific context — The
request_contextfield onServerMessageMetadatais typed asAnybecause the server layer is transport-agnostic (e.g. it is a StarletteRequestfor HTTP transports,Nonefor stdio). A better design would let transports provide their own typed context that handlers can access without casting.
These two concerns are related — both point toward making the context type more precise depending on how and where a handler is invoked.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, RequestContext und ServerRequestContext durch die Handler-Einstiegspunkte zu verfolgen, und untersuche anschließend ServerMessageMetadata.request_context sowie die für Starlette Request und stdio erwähnten Transportfälle. Vergleiche, wie Request- und Notification-Handler Kontext erhalten und wie auf transportspezifische Werte zugegriffen wird. Als abgeschlossen gilt die Aufgabe, wenn die vorgesehenen Typgrenzen und das Transportverhalten definiert sind, ohne sich auf Any oder optionale Request-IDs zu stützen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- backend-api-design
- Issue-Typ
- Refactoring
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 25/100