modelcontextprotocol / modelcontextprotocol/python-sdk
Streamable HTTP stateless servers hang clients on the listen-mode GET (_handle_get_request opens a hold-open SSE stream)
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ả
Environment
mcp Python SDK 1.29.1 / 1.30.0, FastMCP with stateless_http=True and streamable_http_path="/", mounted in a Starlette app.
Symptom
A client that opens the listen-mode GET (Accept: text/event-stream) receives HTTP 200 with Content-Type: text/event-stream but the response never writes a single byte; the connection holds open indefinitely. MCP clients (e.g. Pi, Claude Code) that open this GET at connect time time out with messages like "Timed out connecting to SSE MCP server".
Root cause
StreamableHTTPServerTransport._handle_get_request (mcp/server/streamable_http.py) unconditionally creates an SSE stream and waits for server-initiated messages. For a stateless server there is no session and the server never pushes, so the stream stays open with zero bytes. The handler and its dispatch branch are marked # pragma: no cover.
Spec
MCP Streamable HTTP (2025-03-26) requires a server that does not support server-initiated messages to answer the listen-mode GET with 405 Method Not Allowed. There is no transport configuration that produces that 405 today; current workarounds are app-layer interception (return 405 before the stream handler) or monkey-patching the private handler.
Related
#1764 is a different stateless-mode hang (SSE-writer zero-buffer deadlock). This is the GET-listen path.
Suggested fix
At the top of _handle_get_request (or in handle_request), return 405 when the transport is stateless — or more generally whenever the server publishes no server-initiated messages — before any stream creation.
Repro
Minimal FastMCP: FastMCP("x", stateless_http=True, streamable_http_path="/"), serve, then curl -i -H 'Accept: text/event-stream' http://localhost:PORT/mcp/ — observe 200 + zero bytes, held open (hang), instead of 405.
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 trong mcp/server/streamable_http.py, đọc _handle_get_request và đường dẫn dispatch của nó trong handle_request. Tái hiện hành vi bằng lệnh curl từ issue, sau đó xác minh rằng GET stateless ở chế độ listen trả về 405 Method Not Allowed mà không mở một luồng SSE.
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
- Loại issue
- Lỗi
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức độ hoạt động
- Sôi nổi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 82/100