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.
- A new client application initiates a session by sending an
initialize message, followed by a notifications/initialized notifications.
- Let's say that the Load Balancer routed both messages to replica
A
- As a result, replica
A generated a new session which Id is communicated back to the client
- Replica
A now has an McpServerSession instance properly initialized with all the necessary client information
Problem:
- Next the client sends a
tools/list message with the obtain sessionId, but this time the load balancer routes the message to replica B
- 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
- 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.
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 (
AandB) of this server, with a load balancer in front.initializemessage, followed by anotifications/initializednotifications.AAgenerated a new session which Id is communicated back to the clientAnow has anMcpServerSessioninstance properly initialized with all the necessary client informationProblem:
tools/listmessage with the obtain sessionId, but this time the load balancer routes the message to replicaBMcpServerSessioninstance that lives in replicaBhas never received (and will never receive) the initialize message and notificationssimulatethat handshake in replicaB(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.