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 入口點。當在 replica A 上初始化的 session 可以在 replica B 上使用,而不需要手動模擬 handshake 時,即表示完成。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- java
- 領域
- backend, distributed-systems
- Issue 類型
- 功能
- 難度
- 5/5
- 預估耗時
- 一週以上
- 活躍度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100