Add ScopeSelectorDelegate to enhance OAuth options for scope filtering#1596
Open
halllo wants to merge 3 commits into
Open
Add ScopeSelectorDelegate to enhance OAuth options for scope filtering#1596halllo wants to merge 3 commits into
halllo wants to merge 3 commits into
Conversation
halter73
reviewed
May 22, 2026
9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.