modelcontextprotocol / modelcontextprotocol/python-sdk

401 in Streamable HTTP should be handled gracefully

未關閉
#1,295 2 則留言 1 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

bug P2 ready for work
主要語言
Python
星號
24.3k
分支
4k
平均合併
1 天 1 小時
30 天內合併 PR
31

描述

Initial Checks
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

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

從 src/mcp/client/streamable_http.py 中 response.raise_for_status() 附近的 POST 處理開始,然後將其與 _handle_unexpected_content_type 進行比較。追蹤 HTTP 錯誤如何變成客戶端結果;完成的標準是:未授權操作傳回的 401 會產生一則 JSON-RPC unauthorized 錯誤訊息,客戶端可以處理該訊息而不會崩潰。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
api
Issue 類型
缺陷
難度
3/5
預估耗時
1-2 天
活躍度
活躍
描述清晰度
基本清楚
新手友好度
74/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。