modelcontextprotocol / modelcontextprotocol/python-sdk
Progress notifications cause server to hang on stdio transport
還沒有人認領這個 Issue。
- 主要語言
- 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
When using the low-level Server API (mcp.server.lowlevel.Server) with stdio transport, sending progress notifications during request handling causes the server to hang indefinitely and never send the final response.
What I am seeing:
- Server successfully sends progress notification via
write_stream.send() - Server handler returns
CallToolResult - The final response is never sent to the client
- Client times out waiting for response
- Server remains blocked and time out eventually
Example Code
import asyncio
from mcp.server.lowlevel import Server
from mcp.server.stdio import stdio_server
from mcp.types import *
server = Server("progress-bug-demo")
@server.list_tools()
async def handle_list_tools() -> list[Tool]:
return [Tool(
name="test_tool",
description="Demonstrates the bug",
inputSchema={"type": "object", "properties": {}}
)]
@server.call_tool()
async def handle_call_tool(name: str, arguments: dict) -> list[TextContent]:
ctx = server.request_context
progress_token = ctx.meta.progressToken if ctx.meta else None
if progress_token:
# This causes the server to hang
await ctx.session.send_progress_notification(
progress_token=progress_token,
progress=0.5,
total=1.0,
message="Working..."
)
# This response is never sent due to the hang
return [TextContent(type="text", text="Task completed!")]
async def main():
async with stdio_server() as (read_stream, write_stream):
await server.run(
read_stream,
write_stream,
server.create_initialization_options()
)
if __name__ == "__main__":
asyncio.run(main())
Python & MCP Python SDK
MCP: 1.10.1
Python: 3.12.6
From deeper debugging looks like buffer size is the problem : https://github.com/modelcontextprotocol/python-sdk/blob/main/src/mcp/server/stdio.py#L57
Have to test locally if increasing it will most likely fix the issue and if its causing more problems than just fixing this.
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從低階 Server API 和 src/mcp/server/stdio.py:57 中的 stdio 傳輸實作開始。使用 MCP 1.10.1 執行提供的進度通知範例,以確認 send 在哪裡發生阻塞,然後檢查串流緩衝區的行為。完成的標準是進度通知和最終的 CallToolResult 都能到達用戶端,且伺服器不會掛起。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- api, backend
- Issue 類型
- 缺陷
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 48/100