modelcontextprotocol / modelcontextprotocol/java-sdk

McpServerSession lifecycle doesn't support distributed services

未關閉
#274 17 則留言 12 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 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.

  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.

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 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

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。