modelcontextprotocol / modelcontextprotocol/java-sdk

McpServerSession lifecycle doesn't support distributed services

Offen
#274 17 Kommentare 12 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

area/server enhancement feature/session-storage
Vorherrschende Sprache
Java
Sterne
3.7k
Forks
1.1k
Ø Merge
1 T. 15 Std.
Gemergte PRs (30 T.)
9

Beschreibung

This issue is closely related to #273 and could be considered as a follow up to that, but I decided to split it for convenience and readability.

Consider an MCP server written with this SDK and using the StreamableHttp transport. We deploy two replicas (A and B) of this server, with a load balancer in front.

  1. A new client application initiates a session by sending an initialize message, followed by a notifications/initialized notifications.
  2. Let's say that the Load Balancer routed both messages to replica A
  3. As a result, replica A generated a new session which Id is communicated back to the client
  4. Replica A now has an McpServerSession instance properly initialized with all the necessary client information

Problem:

  1. Next the client sends a tools/list message with the obtain sessionId, but this time the load balancer routes the message to replica B
  2. Even though I believe it should be the server's responsibility to share the session id across replicas, the McpServerSession instance that lives in replica B has never received (and will never receive) the initialize message and notifications
  3. Although it's possible to distribute all that state and simulate that handshake in replica B (I actually did it), I think this SDK should have an OOTB support for that, or at the very least, SessionFactory methods that make it easier to generate "ready to use" Sessions based on previous initializations.

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

Beginne damit, dieses Issue zusammen mit dem verwandten Issue #273 zu lesen, und verfolge dann den Lebenszyklus der StreamableHttp-Session von initialize und notifications/initialized bis hin zu tools/list. Untersuche die im Issue erwähnten Einstiegspunkte für die Session-Verarbeitung und SessionFactory. Als abgeschlossen gilt die Aufgabe, wenn eine auf Replica A initialisierte Session auf Replica B verwendet werden kann, ohne den Handshake manuell zu simulieren.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
java
Bereich
backend, distributed-systems
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Ruhig
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

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