modelcontextprotocol / modelcontextprotocol/python-sdk

Active Streamable HTTP sessions are not terminated during shutdown

未关闭
#2,150 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

bug P2 ready for work
主要语言
Python
星标
24.3k
派生
4k
平均合并
1 天 1 小时
30 天内合并 PR
31

描述

Initial Checks
Description

Context

This is primarily a repost of this fastmcp issue as it seems to actually be a bug in the mcp python sdk and I want to make sure we've got visibility over here.

When shutting down a FastMCP server (CTRL+C) while clients have active streaming connections, Uvicorn logs:

ERROR: ASGI callable returned without completing response.

The error occurs because StreamableHTTPSessionManager cancels the task group without first gracefully terminating active SSE/streaming connections.

Expected behavior would be the active connections being closed with a proper http response before the rest of shutdown.

Example Code
from fastmcp import FastMCP

mcp = FastMCP("Test Server")

@mcp.tool
def hello() -> str:
  return "Hello, World!"

if __name__ == "__main__":
  mcp.run(transport="streamable-http", port=8000)
Python & MCP Python SDK
Python 3.12
MCP Python SDK 1.26.0

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 StreamableHTTPSessionManager 的 shutdown 处理开始,并使用 Python 3.12 下的 streamable-http 示例重现该问题。跟踪活动的 SSE 或流式连接是如何被取消的,然后验证 shutdown 是否会通过正确的 HTTP 响应关闭这些连接,且不会出现 Uvicorn ASGI 错误。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
api, backend
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
冷清
描述清晰度
基本清楚
新手友好度
48/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。