modelcontextprotocol / modelcontextprotocol/python-sdk
Fix Streamable HTTP Accept header quality-factor handling
オープン
まだ誰も着手していません。
bug
needs confirmation
P3
v1
v2
- 主要言語
- Python
- スター
- 24.3k
- フォーク
- 4k
- 平均マージ
- 1日 1時間
- マージ済み PR(30日)
- 31
説明
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
Streamable HTTP currently ignores q=0 values in the Accept header, so requests that explicitly mark a media type as unacceptable can still be accepted. This violates RFC 7231 semantics for content negotiation and can cause clients and servers to disagree about which response format is actually allowed.
Example Code
from starlette.requests import Request
def check_accept_headers(request: Request) -> tuple[bool, bool]:
accept_header = request.headers.get("accept", "")
accept_types = [media_type.strip().split(";")[0].strip().lower() for media_type in accept_header.split(",")]
has_wildcard = "*/*" in accept_types
has_json = has_wildcard or any(t in ("application/json", "application/*") for t in accept_types)
has_sse = has_wildcard or any(t in ("text/event-stream", "text/*") for t in accept_types)
return has_json, has_sse
# Example: client explicitly rejects JSON
request = Request({"type": "http", "method": "GET", "headers": [(b"accept", b"application/json;q=0, text/event-stream;q=1.0")]})
print(check_accept_headers(request))
# -> (True, True)
Python & MCP Python SDK
Python 3.12.10
MCP Python SDK: 1.28.1
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、Streamable HTTP リクエストの処理と issue 内の check_accept_headers 例を追跡し、Accept パラメーターがどのように解析されるかに注目します。提供された application/json;q=0 および text/event-stream;q=1.0 のリクエストで動作を確認し、追加の quality factor のケースも検討します。RFC 7231 のセマンティクスに従い、明示的に受け入れ不可とされたメディアタイプが受け入れ済みとして扱われないことが確認できれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- api, backend
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 静か
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 68/100