modelcontextprotocol / modelcontextprotocol/python-sdk

User-Agent header in sHTTP transport is not forwarded to auth flow

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

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

auth bug P2 ready for work
主要言語
Python
スター
24.3k
フォーク
4k
平均マージ
1日 1時間
マージ済み PR(30日)
31

説明

Initial Checks
Description

Passing a custom User-Agent header to the sHTTP transport, e.g. here does not result in auth flow requests including that user agent. There also does not appear to be any way to customize this behavior externally to the SDK itself.

In particular, this becomes a problem when working with AWS WAF, as one of its baseline rules is to require all requests to include a User-Agent header, to filter out low-grade spam.

I am currently recommending to internal teams that they disable this rule for the time being, but this is not a great solution for them, as it means removing an application guardrail to work around an SDK limitation.

Example Code
print("📡 Opening StreamableHTTP transport connection with auth...")
async with streamablehttp_client(
    url=self.server_url,
    auth=oauth_auth,
    timeout=timedelta(seconds=60),
    headers={
        "User-Agent": "mcp-python-sdk/0.1.0",
    },
) as (read_stream, write_stream, get_session_id):
    await self._run_session(read_stream, write_stream, get_session_id)
Python & MCP Python SDK

Latest SDK commit: 27279bc (1.22.0)
Python 3.13.2

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

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

はじめの一歩

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

調査の方向性

examples/clients/simple-auth-client/mcp_simple_auth_client/main.py の streamablehttp_client の使用箇所、特に 214-220 行付近の headers 引数から始めて、認証フローがどのようにリクエストを構築しているかを追跡してください。カスタム User-Agent がそれらのリクエストに到達することを、AWS WAF のユースケースも含めて確認してください。完了の条件は、呼び出し元がそのルールを無効化せずに SDK 経由でヘッダーを設定できることです。

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

評価

技術スタック
python
領域
authentication
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
活発
明瞭さ
おおむね明確
初心者へのやさしさ
68/100

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

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