modelcontextprotocol / modelcontextprotocol/java-sdk
McpServerSession lifecycle doesn't support distributed services
未关闭
还没有人认领这个 Issue。
area/server
enhancement
feature/session-storage
- 主要语言
- Java
- 星标
- 3.7k
- 派生
- 1.1k
- 平均合并
- 1 天 15 小时
- 30 天内合并 PR
- 9
描述
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
initializemessage, followed by anotifications/initializednotifications. - Let's say that the Load Balancer routed both messages to replica
A - As a result, replica
Agenerated a new session which Id is communicated back to the client - Replica
Anow has anMcpServerSessioninstance properly initialized with all the necessary client information
Problem:
- Next the client sends a
tools/listmessage with the obtain sessionId, but this time the load balancer routes the message to replicaB - Even though I believe it should be the server's responsibility to share the session id across replicas, the
McpServerSessioninstance that lives in replicaBhas never received (and will never receive) the initialize message and notifications - Although it's possible to distribute all that state and
simulatethat 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.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先将此 issue 与相关的 issue #273 一起阅读,然后跟踪 StreamableHttp session 从 initialize 和 notifications/initialized 到 tools/list 的生命周期。检查 issue 中提到的 session 处理和 SessionFactory 入口点。当在副本 A 上初始化的 session 可以在副本 B 上使用,而无需手动模拟握手时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- java
- 领域
- backend, distributed-systems
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100