| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
There was a problem hiding this comment.
Thanks for addressing the feedback so cleanly!
Sorry, something went wrong.
|
@tarekgh @jeffhandley Heads up I just merged this new ScopeSelectorDelegate. I looked at the TS and Python SDKs and they don't have a dedicated equivalent, but I think it's worth adding given the concern about not wanting the new implicit offline_access behavior as described in #1238 (comment). TS and Python do cover the same use case through their broader OAuthClientProvider interfaces, which sit somewhere between configuring the ClientOAuthOptions callbacks and implementing an OAuth DelegatingHandler end to end. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Add a ScopeSelector hook to ClientOAuthOptions for customizing OAuth scopes
Motivation 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 supports mcp:tools but 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 Scopes property on ClientOAuthOptions was 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 new ScopeSelector delegate 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:
All 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_access has been auto-appended (per #1479), so it can also strip that scope if the client opts out. Returning null or an empty enumerable omits the scope parameter 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.