OAuth: 403 responses without insufficient_scope incorrectly retry with same token
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 55/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 停滞
- 技術スタック
- python
調査の方向性
src/mcp/client/auth/oauth2.py の 662~681 行付近を読み、error フィールドの抽出後に 403 レスポンスがどのように処理されるかに注目してください。insufficient_scope、別のエラー、error フィールドがない場合の動作を確認してください。scope-challenge パスだけがリトライし、その他の 403 レスポンスは直ちに例外を発生させれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Summary
The OAuth client unconditionally retries all 403 responses, even when the error is not insufficient_scope. This causes an unnecessary retry attempt with the same token that will fail for the same reason.
Location
src/mcp/client/auth/oauth2.py, lines 662-681
The Bug
elif response.status_code == 403:
error = self._extract_field_from_www_auth(response, "error")
# Only performs step-up if error == "insufficient_scope"
if error == "insufficient_scope":
self._select_scopes(response)
token_response = yield await self._perform_authorization()
await self._handle_token_response(token_response)
# BUG: Retries unconditionally, even when no new tokens were obtained
self._add_auth_header(request)
yield request
Lines 679-681 execute regardless of whether step-up authorization occurred, causing a retry with the same credentials.
Expected vs Actual Behavior
| Scenario | Expected | Actual |
|---|---|---|
403 with insufficient_scope |
Get new tokens → retry | ✅ Correct |
403 with different error (e.g., invalid_token) |
Raise error immediately | ❌ Retries once with same token, then fails |
| 403 with no error field | Raise error immediately | ❌ Retries once with same token, then fails |
Impact
- Wasted network round-trip: Client makes doomed retry request that will fail for the same reason
- Poor error feedback: Delays error reporting by one request cycle
- Spec non-compliance: MCP Authorization Spec implies retry only for
insufficient_scope - Resource waste: Unnecessary load on server and client
Fix
Move the retry logic inside the if error == "insufficient_scope": block and raise an error otherwise:
elif response.status_code == 403:
error = self._extract_field_from_www_auth(response, "error")
if error == "insufficient_scope":
try:
self._select_scopes(response)
token_response = yield await self._perform_authorization()
await self._handle_token_response(token_response)
# Retry with new tokens
self._add_auth_header(request)
yield request
except Exception:
logger.exception("OAuth flow error")
raise
else:
# Permanent authorization failure - cannot be resolved by retry
raise OAuthFlowError(
f"Access forbidden: {error or 'insufficient permissions'}"
)
References
- RFC 6750 Section 3.1 - Defines
insufficient_scopeas the only 403 error code - MCP Authorization Spec - Scope challenge handling
Authored by Claude, reviewed by @maxisbey
- 主要言語
- Python
- スター
- 24.3k
- フォーク
- 4k
- 平均マージ
- 1日 1時間
- マージ済み PR(30日)
- 31
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
modelcontextprotocol/python-sdk のほかの issue
-
v1 v2
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
modelcontextprotocol/python-sdk#3546 · コメント 4 件 ·
-
v1 v2
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
modelcontextprotocol/python-sdk#3545 · コメント 1 件 ·
-
v1 v2
難易度 1/5 1時間未満 初心者へのやさしさ 91/100
modelcontextprotocol/python-sdk#3508 · コメント 2 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
modelcontextprotocol/python-sdk#3504 ·
-
v1 v2
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
modelcontextprotocol/python-sdk#3492 · コメント 1 件 ·
modelcontextprotocol/python-sdk の issue をすべて見る
似ている issue
-
🐛 Bug 🔔 Pending processing
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
jumpserver/jumpserver#17584 ·
-
link-check link-check:sphinx-theme
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
OpenHands/extensions#626 · コメント 1 件 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
CSCfi/sd-search-api#39 ·