Skip to content

fix(auth): respect explicitly-set client_metadata.scope during discovery#2373

Open
chasewhughes wants to merge 1 commit intomodelcontextprotocol:mainfrom
chasewhughes:fix/respect-explicit-client-scopes
Open

fix(auth): respect explicitly-set client_metadata.scope during discovery#2373
chasewhughes wants to merge 1 commit intomodelcontextprotocol:mainfrom
chasewhughes:fix/respect-explicit-client-scopes

Conversation

@chasewhughes
Copy link
Copy Markdown

Problem

async_auth_flow unconditionally overwrites client_metadata.scope with server-advertised scopes during OAuth discovery (Step 3). This prevents clients from limiting their requested permissions, which is required by some servers — for example, the official SalesForce MCP server rejects requests that include scopes not authorized for the given client application.

Solution

Only apply automatic scope selection when client_metadata.scope is None. If the caller has explicitly set scopes, they are preserved through the discovery flow.

The 403 step-up flow (insufficient_scope) is intentionally left unchanged — when a server explicitly demands different scopes, those should override regardless.

Tests

Two new tests:

  • test_auth_flow_preserves_explicit_scopes — verifies that explicitly-set scopes survive the discovery flow
  • test_auth_flow_auto_selects_scopes_when_none — verifies that auto-selection still works when no explicit scope is set

All 86 tests in test_auth.py pass.

Fixes #2317

The scope selection strategy in async_auth_flow unconditionally
overwrites client_metadata.scope with server-advertised scopes. This
is problematic when the caller has explicitly set scopes to limit
permissions or to avoid rejection by servers that only permit certain
scopes (e.g. SalesForce MCP server).

Only apply automatic scope selection when client_metadata.scope is
None, preserving any explicitly-set value.

Github-Issue: modelcontextprotocol#2317
Reported-by: jbweston
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.

Don't override client_metadata.scopes if they are already set

1 participant