Repository navigation
fix(mcp): AccessToken.scopes carries the token's real OAuth scope - #134
Merged
Merged
Conversation
OAuth tokens get the scope from /v1/auth/verify, with legacy full lists expanded to every current scope (port of expandLegacyFullScope). API keys keep every scope. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Why
ZernioTokenVerifier._grant()setAccessToken.scopesto every scope for every token. The real OAuth scope fromGET /api/v1/auth/verifywas already kept inclaims["scope"], soscopessaid the wrong thing about narrow OAuth grants.What
scopestring):scopesis that scope, expanded the way the API expands it. A legacy full list (at least the original 8, and a prefix ofOAUTH_SCOPESin order) means every current scope.expand_legacy_full_scopeis a port ofexpandLegacyFullScopefrom Schedule-Posts-APIlibs/oauth/scopes.ts.OAUTH_SCOPESorder already matches the API's (checked against main).list(OAUTH_SCOPES), as before.claims["scope"]stays the raw string, soMissingScopeMiddlewareis unchanged. Norequired_scopes, noscopes_supportedchange, no tool hidden.Readers of
AccessToken.scopessrc/late/mcp): none.MissingScopeMiddlewarereadsclaims["scope"], notscopes.server/telemetry.pyget_auth_span_attributes: setsenduser.scopeon OTel spans. Now shows the real scope for OAuth tokens. No OTel exporter is configured in this repo, so nothing observable changes.utilities/authorization.py(require_scopes,restrict_tag) andserver/middleware/authorization.pyAuthMiddleware: only run for components or middleware withauth=. We set none.server/auth/middleware/bearer_auth.py:AuthCredentials(scopes)andRequireAuthMiddleware, which checks onlyrequired_scopes. Ours is empty, so the loop never runs.Tests
tests/test_mcp_auth_cache.py: narrow scope, legacy full lists (8, 13, 22), 8 scopes that are not the original 8 stay narrow, API key, cache hit, grace for OAuth token and API key.Follow-ups
Hide tools per connection with FastMCP
auth=plus an any-of check and the per-connection BM25 tool search, in log-only mode first. Not in this PR.🤖 Generated with Claude Code