Skip to content

Commit 6780800

Browse files
committed
remove oauth scope validation
1 parent 81c470f commit 6780800

File tree

2 files changed

+2
-21
lines changed

2 files changed

+2
-21
lines changed

src/mcp/client/auth/oauth2.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -352,11 +352,7 @@ async def _handle_token_response(self, response: httpx.Response) -> None:
352352
raise OAuthTokenError(f"Token exchange failed ({response.status_code}): {body_text}")
353353

354354
# Parse and validate response with scope validation
355-
token_response = await handle_token_response_scopes(
356-
response,
357-
self.context.client_metadata,
358-
validate_scope=True,
359-
)
355+
token_response = await handle_token_response_scopes(response)
360356

361357
# Store tokens in context
362358
self.context.current_tokens = token_response

src/mcp/client/auth/utils.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -228,18 +228,13 @@ async def handle_registration_response(response: Response) -> OAuthClientInforma
228228

229229
async def handle_token_response_scopes(
230230
response: Response,
231-
client_metadata: OAuthClientMetadata,
232-
validate_scope: bool = True,
233231
) -> OAuthToken:
234232
"""Parse and validate token response with optional scope validation.
235233
236-
Parses token response JSON and validates scopes to prevent scope escalation
237-
if requested. Callers should check response.status_code before calling.
234+
Parses token response JSON. Callers should check response.status_code before calling.
238235
239236
Args:
240237
response: HTTP response from token endpoint (status already checked by caller)
241-
client_metadata: Client metadata containing requested scopes (if any)
242-
validate_scope: Whether to validate scopes (default True). Set False for refresh.
243238
244239
Returns:
245240
Validated OAuthToken model
@@ -250,16 +245,6 @@ async def handle_token_response_scopes(
250245
try:
251246
content = await response.aread()
252247
token_response = OAuthToken.model_validate_json(content)
253-
254-
# Validate scopes to prevent scope escalation
255-
# Only validate during initial token exchange, not during refresh
256-
if validate_scope and token_response.scope and client_metadata.scope:
257-
requested_scopes = set(client_metadata.scope.split())
258-
returned_scopes = set(token_response.scope.split())
259-
unauthorized_scopes = returned_scopes - requested_scopes
260-
if unauthorized_scopes:
261-
raise OAuthTokenError(f"Server granted unauthorized scopes: {unauthorized_scopes}")
262-
263248
return token_response
264249
except ValidationError as e:
265250
raise OAuthTokenError(f"Invalid token response: {e}")

0 commit comments

Comments
 (0)