modelcontextprotocol / modelcontextprotocol/python-sdk
401 in Streamable HTTP should be handled gracefully
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
Currently, streamable_http will call response.raise_for_status() when handling POST requests. (ref).
This means that a 401 will bubble up and cause the entire program to crash.
While a 401 on server initialize could warrant an exception, we have a use case where a MCP server will return 401 for specific unauthorized operations, and allow others.
This should be handled gracefully, similar to how _handle_unexpected_content_type works, returning a JSONRPC message outlining an unauthorized exception was thrown.
This would let an agent or other client handle it instead of crashing the program.
Python & MCP Python SDK
Python 3.12 and MCP SDK v1.13.1
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 src/mcp/client/streamable_http.py, tại phần xử lý POST quanh response.raise_for_status(), sau đó so sánh với _handle_unexpected_content_type. Theo dõi cách các lỗi HTTP trở thành kết quả của client; hoàn thành khi một 401 từ một thao tác không được ủy quyền tạo ra thông báo lỗi JSON-RPC unauthorized mà client có thể xử lý mà không bị crash.
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ó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Sôi nổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 74/100