modelcontextprotocol / modelcontextprotocol/python-sdk
Improve log clarity for "Terminating session: None" in stateless mode
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 24.3k
- 分支
- 4k
- 平均合併
- 1 天 1 小時
- 30 天內合併 PR
- 31
描述
Description
In stateless HTTP mode, every request logs INFO:mcp.server.streamable_http:Terminating session: None. This is correct behavior — stateless mode creates a new transport with mcp_session_id=None per request and terminates it afterward — but the message is confusing to end users who see it and assume their connection is failing or being dropped.
I maintain an MCP server (ha-mcp) that runs in stateless mode, and this log message regularly causes confusion among users who think they aren't connected.
Suggested change
Differentiate the log message for stateless (session-less) terminations:
# Current (streamable_http.py):
logger.info(f"Terminating session: {self.mcp_session_id}")
# Suggested:
if self.mcp_session_id:
logger.info(f"Terminating session: {self.mcp_session_id}")
else:
logger.debug("Stateless request completed, cleaning up transport")
This would:
- Downgrade stateless cleanup to
DEBUG(routine, not noteworthy) - Use wording that doesn't alarm users ("completed" vs "Terminating")
- Keep the existing
INFO-level log for actual session terminations
References
- Source:
streamable_http.pyterminate() method - Stateless transport creation:
streamable_http_manager.py_handle_stateless_request()
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 src/mcp/server/streamable_http.py 中的 terminate() 方法開始,然後將其與 src/mcp/server/streamable_http_manager.py 中的 _handle_stateless_request() 進行比較。確認無狀態清理與工作階段終止有所區別,並確認實際的工作階段終止保留現有的記錄行為。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- backend, observability
- Issue 類型
- 缺陷
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 活躍度
- 停滯
- 描述清晰度
- 描述清楚
- 新手友好度
- 45/100