OAuth scope selection falls back to the authorization server's scopes_supported, which the spec does not allow
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 79/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- python
調査の方向性
src/mcp/client/auth/utils.py の get_client_metadata_scopes から始め、issueで引用されている仕様の動作と照らし合わせながら、scope選択の分岐を追ってください。challenge scopeがない場合とPRM scopes_supported を対象とするテストを確認するか追加してください。これらのケースで、PRM scopesがあればそれを選択し、なければscopeを省略し、authorization server scopesを使わないことが完了条件です。
索引モデルが issue の本文から書いたものです。
説明
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
When the 401 carries no scope and the Protected Resource Metadata (PRM) has no scopes_supported, get_client_metadata_scopes (src/mcp/client/auth/utils.py) requests every scope the authorization server lists:
# MCP spec scope selection priority:
# 1. WWW-Authenticate header scope
# 2. PRM scopes_supported
# 3. AS scopes_supported (SDK fallback)
# 4. Omit scope parameter
...
elif authorization_server_metadata is not None and authorization_server_metadata.scopes_supported is not None:
selected_scope = " ".join(authorization_server_metadata.scopes_supported)
The spec has two steps, and the second one ends in omitting scope (2026-07-28, Authorization → Scope Selection Strategy):
- Use
scopeparameter from the initialWWW-Authenticateheader in the 401 response, if provided- If
scopeis not available, use all scopes defined inscopes_supportedfrom the Protected Resource Metadata document, omitting thescopeparameter ifscopes_supportedis undefined.
The same section says clients SHOULD request "only the scopes necessary for their intended operations."
An authorization server's scopes_supported describes the whole authorization server, not this resource. Often that's a shared IdP serving many APIs (openid, profile, email, org-admin and write scopes for unrelated services). Tier 3 therefore turns "the resource didn't say" into "ask for everything the IdP has". The results:
- an over-privileged token for an MCP server that needed none of it;
- a broad consent screen for the user;
- a login failure when the authorization server refuses to issue some of the listed scopes to a public or dynamically registered client (
invalid_scope), where omittingscopewould have succeeded with the authorization server's default.
Example Code
The selection function on its own (works on 1.26.0, 1.30.0 and 2.3.0):
from mcp.client.auth.utils import get_client_metadata_scopes
from mcp.shared.auth import OAuthMetadata, ProtectedResourceMetadata
prm = ProtectedResourceMetadata(
resource="https://mcp.example.com/mcp",
authorization_servers=["https://auth.example.com"],
) # no scopes_supported
asm = OAuthMetadata(
issuer="https://auth.example.com",
authorization_endpoint="https://auth.example.com/authorize",
token_endpoint="https://auth.example.com/token",
scopes_supported=["openid", "profile", "email", "admin:org", "repo:write"],
)
print(get_client_metadata_scopes(None, prm, asm))
# 'openid profile email admin:org repo:write' — expected: None (omit scope)
In the real flow, OAuthClientProvider.async_auth_flow assigns this result to client_metadata.scope on every 401. So a client can't avoid it by configuring a narrower scope: that is #2317, which has several production reports.
Expected behaviour
Follow the spec: (1) the challenge scope, (2) PRM scopes_supported, otherwise omit scope. If a fallback beyond the spec is wanted, make it something a client turns on, not the default.
Relation to existing issues
- #2317: a configured
client_metadata.scopeis overwritten. This issue is separate: even with no configured scope, the SDK should omitscoperather than take the authorization server's list. Fixing #2317 alone would leave clients that don't configure a scope on tier 3. - #3172 (closed): put the configured scope after tier 3. That doesn't help here, because the AS-wide list still wins whenever the authorization server advertises any scopes.
Python & MCP Python SDK
- MCP Python SDK: reproduced on 1.26.0, 1.30.0, 2.3.0. The same code is on
mainatd7845c0. - Python 3.12
- 主要言語
- Python
- スター
- 24.7k
- フォーク
- 4.1k
- 平均マージ
- 18時間 27分
- マージ済み PR(30日)
- 15
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
modelcontextprotocol/python-sdk のほかの issue
-
bug v2
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
modelcontextprotocol/python-sdk#3811 ·
メンテナーはふだん 1 日以内に返信
-
bug v2
難易度 2/5 1〜3時間 初心者へのやさしさ 79/100
modelcontextprotocol/python-sdk#3810 ·
メンテナーはふだん 1 日以内に返信
-
[Bug]: Inconsistent structured output wrapping and opt-out for typing.Dict and typing sequence generics in func_metadata再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープンbug v1 v2
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
modelcontextprotocol/python-sdk#3771 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
bug v2
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
modelcontextprotocol/python-sdk#3769 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
2026 Streamable HTTP rejects whitespace-padded Mcp-Name values再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープンbug spec-2026-07-28 v2
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
modelcontextprotocol/python-sdk#3763 · コメント 4 件 ·
メンテナーはふだん 1 日以内に返信
modelcontextprotocol/python-sdk の issue をすべて見る
似ている issue
-
bug ready-for-dev
難易度 1/5 1〜3時間 初心者へのやさしさ 92/100
OpenHands/extensions#897 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
tensorflow/datasets#11253 ·
メンテナーはふだん 1 日以内に返信
-
fix(core): a config section with all keys commented out crashes startup対応中かも @Aryanbhargava18 が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
kubeflow/mcp-server#512 ·
メンテナーはふだん 1 日以内に返信
-
Stop trusting the compromised eMudhra CA certificates対応中かも @anth-volk が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
PolicyEngine/uk-triple-lock#54 ·
メンテナーはふだん 1 日以内に返信
-
DBFS append mode silently overwrites existing files対応中かも @IlyaKhalafi が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
fsspec/filesystem_spec#2429 ·
メンテナーはふだん 1 日以内に返信