Skip to content

Fix validate_scope rejecting scopes when client scope is None#2426

Closed
Christian-Sidak wants to merge 1 commit intomodelcontextprotocol:mainfrom
Christian-Sidak:fix/validate-scope-none-allowed-scopes
Closed

Fix validate_scope rejecting scopes when client scope is None#2426
Christian-Sidak wants to merge 1 commit intomodelcontextprotocol:mainfrom
Christian-Sidak:fix/validate-scope-none-allowed-scopes

Conversation

@Christian-Sidak
Copy link
Copy Markdown

Summary

Fixes #2216

OAuthClientMetadata.validate_scope() incorrectly treats self.scope = None as an empty allowlist ([]), causing all requested scopes to be rejected with InvalidScopeError. Per OAuth 2.0 semantics, None means the client was registered without scope restrictions, so any requested scope should be permitted.

Before: allowed_scopes = [] if self.scope is None else self.scope.split(" ") -- any requested scope fails the in check against [].

After: Skip the allowlist check entirely when self.scope is None, only validate against registered scopes when they are explicitly set.

Test plan

  • Added test: None client scope allows any requested scope
  • Added test: set client scope correctly rejects unregistered scopes
  • Added test: set client scope correctly allows registered scopes
  • Added test: None requested scope returns None regardless of client scope
  • All existing tests continue to pass

When a client is registered without specifying allowed scopes (scope=None),
validate_scope was treating this as an empty allowlist, rejecting all requested
scopes with InvalidScopeError. The correct behavior per OAuth 2.0 semantics is
to treat None as unrestricted, allowing any requested scope.

Fixes modelcontextprotocol#2216
@Christian-Sidak
Copy link
Copy Markdown
Author

Closing -- just noticed existing PRs (#2224, #2246) already addressing this. Apologies for the duplicate!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: validate_scope rejects client scopes when required scopes in None

1 participant