fix(auth): preserve explicitly configured OAuth scopes - #3261
Draft
daleselaji-dev wants to merge 1 commit into
Draft
fix(auth): preserve explicitly configured OAuth scopes#3261daleselaji-dev wants to merge 1 commit into
daleselaji-dev wants to merge 1 commit into
Conversation
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.
Problem
OAuthClientProviderreplaces a scope explicitly configured by the client with all scopes discovered from the protected resource or authorization server. This can request broader permissions than the application intended and can fail against servers that advertise scopes the client is not allowed to request.Root Cause
The OAuth flow unconditionally assigned the result of
get_client_metadata_scopes(...)toclient_metadata.scope, so the configured value was not treated as authoritative.Solution
Keep an explicitly configured scope, including an explicit empty string, while still applying the existing
offline_accessaugmentation for non-empty configured scopes when the AS supports refresh-token grants.Changes
Testing
py -m pytest tests/client/test_auth.py -q— 140 passed, 1 xfailed.py -m pytest tests/client/test_auth.py -q— 141 passed, 1 xfailed.py -m ruff format --check src/mcp/client/auth/oauth2.py src/mcp/client/auth/utils.py tests/client/test_auth.py— passed.py -m ruff check src/mcp/client/auth/oauth2.py src/mcp/client/auth/utils.py tests/client/test_auth.py— passed.git diff --check— passed.Compatibility/Risk
The helper's existing discovery behavior remains the default. Explicit non-empty scopes still receive the existing
offline_accessaddition when applicable; explicit empty scope remains empty. No public constructor or field is renamed.Notes for Reviewer
Pyright is unverified locally because the incremental worktree does not contain the repository
.venv; the available alternate environment has mismatched project dependencies and produces unrelated baseline import/type diagnostics.Linked Issue
Closes #2317