Skip to content

Commit 15f480a

Browse files
committed
fix: handle None required_scopes in validate_scope as no restrictions
When a client is registered without scope restrictions (self.scope is None), validate_scope() incorrectly treated it as an empty allowed-scopes list, causing all requested scopes to be rejected with InvalidScopeError. Now when self.scope is None, the method returns the requested scopes as-is, treating None as 'no restrictions' rather than 'no scopes allowed'. Fixes #2216
1 parent 7ba41dc commit 15f480a

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

src/mcp/shared/auth.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,14 @@ def validate_scope(self, requested_scope: str | None) -> list[str] | None:
7171
if requested_scope is None:
7272
return None
7373
requested_scopes = requested_scope.split(" ")
74-
allowed_scopes = [] if self.scope is None else self.scope.split(" ")
74+
if self.scope is None:
75+
# No scope restrictions registered for this client; allow any scopes
76+
return requested_scopes
77+
allowed_scopes = self.scope.split(" ")
7578
for scope in requested_scopes:
76-
if scope not in allowed_scopes: # pragma: no branch
79+
if scope not in allowed_scopes:
7780
raise InvalidScopeError(f"Client was not registered with scope {scope}")
78-
return requested_scopes # pragma: no cover
81+
return requested_scopes
7982

8083
def validate_redirect_uri(self, redirect_uri: AnyUrl | None) -> AnyUrl:
8184
if redirect_uri is not None:

0 commit comments

Comments
 (0)