modelcontextprotocol / modelcontextprotocol/python-sdk
Client tool call hangs forever if server crashes or connection dies when using streamable-http
未關閉
還沒有人認領這個 Issue。
bug
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
If the server dies during a tool call before it sends a response the client will get stuck forever.
Example Code
# server.py
from mcp.server.fastmcp import FastMCP
import sys
mcp = FastMCP("StatefulServer")
@mcp.tool()
def greet(name: str = "World") -> str:
"""Greet someone by name."""
sys.exit(0)
return f"Hello, {name}!"
if __name__ == "__main__":
mcp.run(transport="streamable-http")
# client.py
import asyncio
from mcp import ClientSession
from mcp.client.streamable_http import streamablehttp_client
async def main():
# Connect to a streamable HTTP server
async with streamablehttp_client("http://localhost:8000/mcp") as (
read_stream,
write_stream,
_,
):
# Create a session using the client streams
async with ClientSession(read_stream, write_stream) as session:
# Initialize the connection
await session.initialize()
res = await session.call_tool("greet", {"name": "World"})
print(res)
if __name__ == "__main__":
asyncio.run(main())
# Run server.py then client.py
# client.py will hang forever in the tool call and never complete. I would expect it to throw an error since the connection died and it will never get a response.
Python & MCP Python SDK
Python 3.13.7
mcp 1.20.0
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 streamablehttp_client 進入點和 client.py 中顯示的 ClientSession.call_tool 路徑開始,然後重現工具呼叫期間 server.py 的當機。當伺服器在回應前結束時,客戶端回報連線失敗而不是永遠等待,即表示完成。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- api, networking
- Issue 類型
- 缺陷
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 55/100