8000 Handle '&scope=' in authorize request to return empty list by dwreeves · Pull Request #979 · modelcontextprotocol/python-sdk · GitHub
[go: up one dir, main page]

Skip to content

Handle '&scope=' in authorize request to return empty list #979

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
8000
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/mcp/shared/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class OAuthClientMetadata(BaseModel):
def validate_scope(self, requested_scope: str | None) -> list[str] | None:
if requested_scope is None:
return None
if requested_scope == "":
return []
requested_scopes = requested_scope.split(" ")
allowed_scopes = [] if self.scope is None else self.scope.split(" ")
for scope in requested_scopes:
Expand Down
11 changes: 11 additions & 0 deletions tests/client/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,17 @@ async def test_scope_priority_no_scope(self, oauth_provider, oauth_client_info):
# No scope should be set
assert "scope" not in auth_params

@pytest.mark.anyio
async def test_client_metadata_validate_scopes_none(self, client_metadata):
"""Test that validate_scopes method handles None and empty string correctly."""
# Should return None
requested_scopes = client_metadata.validate_scope(None)
assert requested_scopes is None

# No scopes should be requested; this can happen when a client authorizes with "&scope=".
requested_scopes = client_metadata.validate_scope("")
assert requested_scopes == []

@pytest.mark.anyio
async def test_state_parameter_validation_uses_constant_time(
self, oauth_provider, oauth_metadata, oauth_client_info
Expand Down
Loading
0