modelcontextprotocol / modelcontextprotocol/python-sdk
MCP client doesn't not initialize new session when getting 404 session not found
未關閉
還沒有人認領這個 Issue。
bug
improves spec compliance
P2
ready for work
- 主要語言
- Python
- 星號
- 24.3k
- 分支
- 4k
- 平均合併
- 1 天 1 小時
- 30 天內合併 PR
- 31
描述
Initial Checks
- I confirm that I'm using the latest version of MCP Python SDK
- I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue
Description
Per https://modelcontextprotocol.io/specification/2025-11-25/basic/transports#session-management
When a client receives HTTP 404 in response to a request containing an MCP-Session-Id, it MUST start a new session by sending a new InitializeRequest without a session ID attached.
This is not the case with the python client. It just sends a session terminated error in streamable_http.py
Example Code
Python & MCP Python SDK
mcp: 1.22.0
python: 3.14.0
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 src/mcp/client/streamable_http.py 第277行附近開始,這裡處理了包含 MCP-Session-Id 的404回應,並將該行為與 issue 中連結的工作階段管理要求進行比較。追蹤用戶端的初始化進入點,並透過觸發404回應來驗證完成後的行為:用戶端應傳送一個不帶工作階段 ID 的新 InitializeRequest,而不是傳回 session-terminated 錯誤。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- api
- Issue 類型
- 缺陷
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 70/100