modelcontextprotocol / modelcontextprotocol/python-sdk
HTTP transport swallows non-2xx status codes causing client to hang
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ả
Summary
When an MCP server returns non-2xx HTTP status codes (401/403/404/5xx), the Streamable HTTP and SSE transports do not reliably propagate the error to the caller. In the Streamable HTTP transport, post_writer catches exceptions and logs them, but the caller blocks indefinitely waiting for a response on the read stream. HTTP 404 responses are also converted to JSONRPCError(code=32600), losing the original HTTP status information.
Expected Behavior
- Non-2xx HTTP responses should be surfaced as exceptions to the caller, not silently logged
- The original HTTP status code should be preserved and accessible
- Auth-related errors (401/403) should be distinguishable from other failures
Current Behavior
post_writerin Streamable HTTP transport catches and logs errors without forwarding them through the read stream- Callers hang indefinitely waiting for a response
- HTTP 404 is converted to
JSONRPCError(code=32600), destroying HTTP-level context
Affected Code
src/mcp/client/streamable_http.py(post_writer)src/mcp/client/sse.py(sse_reader)
Related
- #1742 — broader typed error classes design
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 bằng cách lần theo việc xử lý lỗi trong src/mcp/client/streamable_http.py, đặc biệt là post_writer, và src/mcp/client/sse.py, đặc biệt là sse_reader. Xem lại issue liên quan #1742 về thiết kế lỗi có kiểu. Được coi là hoàn thành khi các phản hồi non-2xx đến được caller dưới dạng exception, giữ nguyên HTTP status, phân biệt 401/403 và không còn khiến caller phải chờ vô thời hạn.
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ó
- 4/5
- Thời gian dự kiến
- 3-5 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