Skip to content

MCP tokens claim the scopes the user picked, not the scopes Cloudflare granted #227

Description

@mattzcarey

In /oauth/callback (src/auth/oauth-handler.ts), completeAuthorization({ scope: oauthReqInfo.scope }) uses the scopes chosen on the consent page. Cloudflare's token response carries the scopes it actually granted (AuthorizationToken.scope), and that is ignored. On refresh, handleTokenExchangeCallback ignores the refreshed token's scope too.

If Cloudflare grants fewer scopes than requested (the account can't grant one, or the user narrows them on Cloudflare's consent), the MCP token and ctx.auth.scope claim scopes the upstream token doesn't have. Tools then fail at Cloudflare's API instead of getting a clean MCP insufficient_scope challenge.

Fix: grant the MCP token the intersection of the requested scopes and Cloudflare's granted scope, at the callback and on each refresh (accessTokenScope). When Cloudflare returns no scope, keep the requested scopes.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions