fix: accumulate OAuth scopes across 401/403 for progressive authorization#1604
Open
giulio-leone wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
fix: accumulate OAuth scopes across 401/403 for progressive authorization#1604giulio-leone wants to merge 1 commit intomodelcontextprotocol:mainfrom
giulio-leone wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
|
@modelcontextprotocol/client
@modelcontextprotocol/server
@modelcontextprotocol/express
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
giulio-leone
added a commit
to giulio-leone/python-sdk
that referenced
this pull request
Feb 28, 2026
… authorization Replace scope overwrite with union-based accumulation in OAuthClientProvider. Both the 401 and 403 (insufficient_scope) handlers now merge new scopes with previously-granted scopes via merge_scopes(), preventing infinite re-authorization loops when a server uses per-operation scopes. Companion fix to modelcontextprotocol/typescript-sdk#1604. Closes modelcontextprotocol/typescript-sdk#1582 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
giulio-leone
added a commit
to giulio-leone/python-sdk
that referenced
this pull request
Feb 28, 2026
… authorization Replace scope overwrite with union-based accumulation in OAuthClientProvider. Both the 401 and 403 (insufficient_scope) handlers now merge new scopes with previously-granted scopes via merge_scopes(), preventing infinite re-authorization loops when a server uses per-operation scopes. Companion fix to modelcontextprotocol/typescript-sdk#1604. Closes modelcontextprotocol/typescript-sdk#1582
… authorization Replace scope overwrite with union-based accumulation in StreamableHTTPClientTransport. Both the 401 and 403 (insufficient_scope) handlers now merge new scopes with previously-granted scopes, preventing the infinite re-authorization loop described in modelcontextprotocol#1582. Adds mergeScopes() helper that computes the set union of space-delimited OAuth scope strings per RFC 6749 §3.3. Closes modelcontextprotocol#1582
c315630 to
aaa9865
Compare
Author
|
Friendly ping — CI is green and this is ready for review. Happy to address any feedback. Thanks! |
Author
|
All CI checks pass. Ready for review. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1582
The
StreamableHTTPClientTransportoverwrites_scopeon each 401/403 response instead of accumulating scopes. This causes an infinite re-authorization loop when an MCP server uses per-operation scopes (progressive/step-up authorization):initializesucceeds with scopeinittools/listreturns 403 →_scope = "mcp:tools:read"(init lost)mcp:tools:readbut notinitinitfails →_scope = "init"(read lost)Changes
mergeScopes()helper: Computes the set-union of space-delimited OAuth scope strings per RFC 6749 §3.3this._scope = mergeScopes(this._scope, scope)this._scope = mergeScopes(this._scope, scope)Test
Added
accumulates scopes across multiple 403 responses for progressive authorizationtest that verifies:mcp:tools:readmcp:tools:read mcp:tools:writeAll 253 client tests pass (2 consecutive clean runs).