fix(mcp): request configured OAuth scopes when server advertises scopes#34076
Closed
mroffmix wants to merge 2 commits into
Closed
fix(mcp): request configured OAuth scopes when server advertises scopes#34076mroffmix wants to merge 2 commits into
mroffmix wants to merge 2 commits into
Conversation
The MCP SDK uses the configured oauth.scope only as a last-resort fallback, so when a server advertises its resource scopes the configured scopes (e.g. openid, offline_access) are dropped and the authorization server never issues a refresh token. Merge the configured clientMetadata.scope with the advertised scopes (deduped, order preserved) so it applies to both dynamic client registration and the authorization request.
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
Author
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.
Issue for this PR
Closes #34034
Type of change
What does this PR do?
The MCP SDK applies the configured
oauth.scopeonly as a last-resort fallback (SEP-835), so when a server advertises its resource scopes the configured scopes are ignored. In particularoffline_accessis never requested, the authorization server issues no refresh token, and short-lived access tokens force a manual re-auth on every expiry.This merges the configured
clientMetadata.scopewith the advertised scopes (deduped, order preserved) in the SDK's scope selection, applied consistently to both dynamic client registration and the authorization request. The change lives in the existing@modelcontextprotocol/sdkpatch because the merge has to happen inside the SDK'sauth()flow, which exposes no hook for it.How did you verify your code works?
auth()flow with advertised scopes plus a config scope and asserts the authorization URL contains the merged set (and that a server advertising no scopes still falls back to the config scope).offline_access/openidon top of the advertised scopes, andmcp-auth.jsonstores a refresh token.Screenshots / recordings
Not a UI change.
Checklist