modelcontextprotocol / modelcontextprotocol/python-sdk
Progress notifications cause server to hang on stdio transport
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 24.3k
- Fork
- 4k
- Merge trung bình
- 1 ngày 1 giờ
- Pull request đã merge (30 ngày)
- 31
Mô tả
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.
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với Server API cấp thấp và phần triển khai giao thức truyền tải stdio tại src/mcp/server/stdio.py:57. Chạy ví dụ thông báo tiến trình được cung cấp với MCP 1.10.1 để xác nhận send bị chặn ở đâu, sau đó kiểm tra hành vi của bộ đệm stream. Hoàn thành có nghĩa là cả các thông báo tiến trình và CallToolResult cuối cùng đều đến được client mà server không bị treo.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- api, backend
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Ít trao đổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 48/100