modelcontextprotocol / modelcontextprotocol/java-sdk

McpServerSession lifecycle doesn't support distributed services

Aperta
#274 17 commenti 12 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

area/server enhancement feature/session-storage
Lingua principale
Java
Stelle
3.7k
Fork
1.1k
Merge medio
1g 15h
PR unite (30g)
9

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia leggendo questa issue insieme all’issue correlata #273, quindi traccia il ciclo di vita della sessione StreamableHttp da initialize e notifications/initialized fino a tools/list. Esamina i punti di ingresso per la gestione della sessione e SessionFactory menzionati nell’issue. Il lavoro è completato quando una sessione inizializzata sulla replica A può essere utilizzata sulla replica B senza simulare manualmente l’handshake.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
java
Ambito
backend, distributed-systems
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.