fix: remove scope registration check from authorize handler#2301
Draft
fix: remove scope registration check from authorize handler#2301
Conversation
The check in validate_scope rejected any requested scope not in the client's registered metadata. This broke the MCP spec's step-up authorization flow: when a server returns 403 insufficient_scope with a WWW-Authenticate challenge containing expanded scopes, the client (see client/auth/oauth2.py) re-authorizes with those scopes and the server would reject them. RFC 7591 Section 2 defines the scope field as scopes the client "can use", with no language restricting requests to that set. Scope policy enforcement belongs in OAuthAuthorizationServerProvider.authorize(), which can already raise AuthorizeError(error="invalid_scope", ...). The TypeScript SDK removed this check in #983 for the same reason. InvalidScopeError is removed as it was only raised from this path. Reported-by: nik1097 Github-Issue: #2216
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.
Supersedes #2220 and #2224. Fixes #2216.
Motivation and Context
OAuthClientMetadata.validate_scope()rejected any requested scope not in the client's registeredscopefield. WhenscopewasNone(no registration restriction), this converted to an empty allow-list and rejected everything — the bug reported in #2216. Both #2220 and #2224 fix that narrow case.But the check itself breaks the MCP spec's step-up authorization flow. The Python client already implements step-up (
client/auth/oauth2.py): on403 insufficient_scopeit re-authorizes with the expanded scopes fromWWW-Authenticate. The server then rejects those scopes because they weren't in the original registration, so step-up against a Python MCP server is currently broken.RFC 7591 §2 defines registered scope as values the client "can use" — there's no language restricting requests to that set. The TypeScript SDK removed the equivalent check in typescript-sdk#983 for the same reason.
Scope policy enforcement belongs in
OAuthAuthorizationServerProvider.authorize(), which can already raiseAuthorizeError(error="invalid_scope", ...)— the handler already catches this.How Has This Been Tested?
./scripts/test— full suite passes with 100% branch coveragetest_authorize_invalid_scoperemoved (tested the behavior being removed, same as typescript-sdk#983)validate_scopeBreaking Changes
mcp.shared.auth.InvalidScopeErrorremoved (only raised from the deleted code path)OAuthClientMetadata.validate_scope()no longer raises — it only parsesprovider.authorize()(example indocs/migration.md)Types of changes
Checklist
Additional context
Thanks to @nik1097 for the original report, and to @shivama205 (#2224) and @lavish0000 (#2220) for the initial fixes that surfaced the broader issue.
AI Disclaimer