-
Notifications
You must be signed in to change notification settings - Fork 2.6k
[client] Implement MCP OAuth scope selection and step-up authorization #1324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
pcarleton
merged 23 commits into
modelcontextprotocol:main
from
dogacancolak:dogacan/mcp-python-sdk/fix-oauth-scope-handling
Oct 13, 2025
+317
−52
Merged
Changes from 7 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
359e159
test: add scope priority tests for OAuth flow
dogacancolak 8463dc7
functionality
dogacancolak 09ef708
fix: prioritize PRM endpoint scopes over OAuth metadata scopes
dogacancolak 1517e4b
fixes
dogacancolak 3e4407d
reorg
dogacancolak aedb751
DRY tests
dogacancolak 9718486
lint
dogacancolak 0708565
Merge branch 'modelcontextprotocol:main' into dogacan/mcp-python-sdk/…
dogacancolak cf4cc3f
Change to the updated MCP spec where priority order is 1. Client scop…
dogacancolak 2736dfb
Move logic from Auth Server Metadata handler to PRM handler
dogacancolak fbde0f5
comments
dogacancolak b0f0222
DRY up the www-authenticate header extraction
dogacancolak 643ae86
comment
dogacancolak 094c341
remove unused fixture
dogacancolak 32411ee
fix test class name
dogacancolak 7f39d90
revert uv.lock changesd
dogacancolak c7bcfbc
try again
dogacancolak b0cf94c
once more
dogacancolak 5a311f7
step-up auth flow and fix tests
dogacancolak 2efec15
revert uv
dogacancolak 95267ed
test step-up auth flow
dogacancolak ed443f5
revert uv lock
dogacancolak f84d1d2
function names
dogacancolak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see this latest change to the spec:
Are you able to update this PR to:
www-authenticate
scopes_supported
from AS metadata)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated. Although the complete priority order is:
www-authenticate
scopeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm I don't think (1) is correct there. If we always use what's configured on the client, there's no path for upgrading scope if the initial request didn't have the correct scope.
We had some discussion in this across a few PR's (example) and in discord about similar issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to this spec https://modelcontextprotocol.io/specification/draft/basic/authorization#scope-challenge-handling the step-up only happens when the server returns 403. The changes in this PR only take effect upon a 401.
I can definitely update the 401 path by not prioritizing the configured scope on the client, but the step-up logic remains unhandled in the MCP client in this SDK. I can create a separate PR for that if that makes sense
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can make it part of this PR too considering this is already a breaking change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
working on adding step-up auth flow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done