Skip to content

fix: validate_scope treats None registered scopes as no restrictions#2224

Open
shivama205 wants to merge 1 commit intomodelcontextprotocol:mainfrom
shivama205:fix/validate-scope-none-scopes
Open

fix: validate_scope treats None registered scopes as no restrictions#2224
shivama205 wants to merge 1 commit intomodelcontextprotocol:mainfrom
shivama205:fix/validate-scope-none-scopes

Conversation

@shivama205
Copy link

Summary

  • OAuthClientMetadata.validate_scope() incorrectly treated self.scope = None (no scopes registered) as an empty allowed list, rejecting all requested scopes with InvalidScopeError
  • Now None is correctly treated as "no restrictions", allowing any requested scope through

Closes #2216

Changes

  • Modified: src/mcp/shared/auth.py — early return when self.scope is None instead of converting to empty list
  • Modified: tests/shared/test_auth.py — added 6 unit tests for validate_scope covering None/matching/rejection/empty cases

Test plan

  • All 9 shared auth tests pass (3 existing + 6 new)
  • All 42 auth integration tests pass (including test_authorize_invalid_scope)
  • ruff check passes
  • ruff format passes
  • pyright passes with 0 errors

When a client was registered without specific scopes (scope=None),
validate_scope() converted None to an empty list, causing all
requested scopes to be rejected with InvalidScopeError. Now None
is correctly treated as "no restrictions", allowing any scope.

Closes modelcontextprotocol#2216
@shivama205 shivama205 force-pushed the fix/validate-scope-none-scopes branch from 49f7dec to d6bd5eb Compare March 6, 2026 04:00
@shivama205
Copy link
Author

shivama205 commented Mar 6, 2026

CI is green — the only failure is test (3.14, locked, windows-latest) which is a flaky Windows/Python 3.14 issue (test_basic_child_process_cleanup and test_request_cancellation), unrelated to this change.

@Kludex @maxisbey please help to review when you get a chance.

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