Uh oh!
There was an error while loading. Please reload this page.
Add ScopeSelectorDelegate to enhance OAuth options for scope filtering - #1596
Conversation
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
halter73
left a comment
There was a problem hiding this comment.
Thanks for addressing the feedback so cleanly!
Uh oh!
There was an error while loading. Please reload this page.
@tarekgh@jeffhandley Heads up I just merged this new TS and Python do cover the same use case through their broader |
Add a
ScopeSelectorhook toClientOAuthOptionsfor customizing OAuth scopesMotivation and Context
The MCP authorization spec defines a strict scope selection priority: WWW-Authenticate header scope → PRM
scopes_supported→ omit scope parameter. Clients sometimes need to request only a subset of the scopes a server advertises (e.g. a client that only supportsmcp:toolsbut the server lists ten scopes), or to append a scope not in the server metadata (e.g. a non-standard scope required by a specific deployment).The existing
Scopesproperty onClientOAuthOptionswas documented as an override but only ever acted as a last-resort fallback — consistent with the TypeScript and Python SDKs. That misleading documentation has been corrected. The newScopeSelectordelegate is the intended extension point for clients that need to influence scope selection when the server does provide scope information.This closes out the use-case from #1238 and #1236 without violating the spec's priority order.
How Has This Been Tested?
Five integration tests were added to
AuthTests.cs, covering all input/output combinations of the delegate:mcp:toolsfrom a two-scope server)offline_access; delegate receivesnullnull—scopequery parameter is absent from the authorization URLscopequery parameter is absent from the authorization URLAll tests run end-to-end against the in-process test OAuth server on net8.0, net9.0, and net10.0.
Breaking Changes
None. The behavior of
Scopes(last-resort fallback) is unchanged; only its documentation was corrected to match the actual behavior and the spec.Types of changes
Checklist
Additional context
Delegate signature:
The delegate receives the scope list after the full MCP priority logic and after
offline_accesshas been auto-appended (per #1479), so it can also strip that scope if the client opts out. Returningnullor an empty enumerable omits thescopeparameter from the authorization request entirely.The selector is intentionally not applied to the scope hint sent during Dynamic Client Registration — DCR scope is advisory and the authorization request scope is what matters for token issuance.