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