Skip to content

Commit e8f42d6

Browse files
committed
fix: preserve client_metadata.scope if already set
Don't override the scope if it was explicitly set by the client. This allows clients to: - Request fewer permissions than available - Work with servers that reject requests for unauthorized scopes The scope selection strategy now only applies when scope is None. Fixes #2317
1 parent 92c693b commit e8f42d6

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

src/mcp/client/auth/oauth2.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -571,12 +571,13 @@ async def async_auth_flow(self, request: httpx.Request) -> AsyncGenerator[httpx.
571571
else:
572572
logger.debug(f"OAuth metadata discovery failed: {url}")
573573

574-
# Step 3: Apply scope selection strategy
575-
self.context.client_metadata.scope = get_client_metadata_scopes(
576-
extract_scope_from_www_auth(response),
577-
self.context.protected_resource_metadata,
578-
self.context.oauth_metadata,
579-
)
574+
# Step 3: Apply scope selection strategy (only if not already set)
575+
if self.context.client_metadata.scope is None:
576+
self.context.client_metadata.scope = get_client_metadata_scopes(
577+
extract_scope_from_www_auth(response),
578+
self.context.protected_resource_metadata,
579+
self.context.oauth_metadata,
580+
)
580581

581582
# Step 4: Register client or use URL-based client ID (CIMD)
582583
if not self.context.client_info:

0 commit comments

Comments
 (0)