Streamable HTTP client drops the HTTP status of an error response

オープン 初心者向け
#3,857 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

  • #3870 @tang-ontheway による — マージされずにクローズ

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
70/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
api, networking

調査の方向性

汎用エラーは mcp/client/streamable_http.py で作成されており、2xx 以外のレスポンスが "Server returned an error response" というメッセージの ErrorData に変換されています。まずそこから始めて、その時点でレスポンスのどの値(ステータスコード、reason phrase、URL)がスコープ内に残っているかを確認してください。ステータスはメッセージと、http_status のようなデータフィールドの両方に含めてください。その後、401 と 502 がクライアントのテストで異なるエラーを生成することを確認してください。呼び出し元がカスタムのレスポンスフックを使わずにステータスを読み取れれば完了です。

索引モデルが issue の本文から書いたものです。

説明

enhancement
What happens

When the server (or a proxy or gateway in front of it) answers a JSON-RPC request with a non-2xx status and no JSON-RPC error body, the streamable HTTP client replaces the response with a generic error:

# mcp/client/streamable_http.py (main and 2.3.0)
error_data = ErrorData(code=INTERNAL_ERROR, message="Server returned an error response")

The status code, reason phrase and URL are dropped, so a caller cannot tell a 401 from a 502 or a 504. Every non-404 HTTP failure reaches the caller as the same -32603 error.

Why it matters
  • Callers cannot decide whether a failure is worth retrying (a gateway 502/503/504) or not (a 401, 403 or 413).
  • Logs and user-facing errors cannot name the cause. We saw this with an install whose MCP URL went through an auth proxy: every call failed with a 401, and all we could log was "Server returned an error response".
Suggestion

Keep the HTTP status in the error, for example ErrorData(code=INTERNAL_ERROR, message=f"Server returned an error response ({status} {reason})", data={"http_status": status}), so callers can branch on it without a response hook of their own.

Versions

mcp 2.3.0 (checked against main as well).

主要言語
Python
スター
25k
フォーク
4.2k
平均マージ
10分
マージ済み PR(30日)
1

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

modelcontextprotocol/python-sdk のほかの issue

modelcontextprotocol/python-sdk の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。