modelcontextprotocol / modelcontextprotocol/python-sdk

Fix Streamable HTTP Accept header quality-factor handling

オープン
#3,154 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

bug needs confirmation P3 v1 v2
主要言語
Python
スター
24.3k
フォーク
4k
平均マージ
1日 1時間
マージ済み PR(30日)
31

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. 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

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

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