Repository navigation
Separate advertised scopes_supported from required_scopes - #3783
xubenqiang wants to merge 1 commit into
Conversation
`AuthSettings.required_scopes` is used both to refuse tokens and as the Protected Resource Metadata's `scopes_supported`, so a server cannot advertise a scope that only some handlers check (a write scope, for example) without challenging for it on every request. Add an optional `AuthSettings.scopes_supported` used for the metadata, defaulting to `required_scopes` to keep current servers unchanged. The bearer middleware still challenges with `required_scopes`.
|
This PR has been closed automatically. This repo only keeps pull requests open when they come from a maintainer, or from a contributor a maintainer has assigned to the linked issue, and you aren't currently assigned to #3778. If a maintainer assigns you to #3778, this PR reopens on its own and there's nothing more you need to do here. Assignment is a maintainer call based on capacity; comments that only ask to be assigned don't factor in. What does help is engaging on the issue itself by confirming the repro, explaining why it matters for your use case, or describing the approach you'd take. You're welcome to keep pushing commits here (just avoid force-pushing, since GitHub can't reopen a rewritten branch), but that on its own won't get the PR reviewed or the issue assigned, and realistically most auto-closed PRs stay closed. There's no need to open a new PR either way. CONTRIBUTING.md has the full reasoning, but in short:
Maintainers: reopen, remove |
Fixes #3778
AuthSettings.required_scopesis used both to refuse tokens (RequireAuthMiddleware) and as the Protected Resource Metadata'sscopes_supported, so a server cannot advertise a scope that only some handlers check — a write scope, for example — without challenging for it on every request. Clients that take their scope request fromscopes_supportedthen never ask for the write scope.Change
AuthSettings.scopes_supported: list[str] | None(new, optional): the scopes advertised in the Protected Resource Metadata.mcpserverandlowlevel) useauth.scopes_supported or auth.required_scopes, so existing servers are unchanged and the challenge still usesrequired_scopesonly.Tests
tests/server/auth/test_protected_resource.py:test_scopes_supported_advertised_separately_from_required_scopes: anMCPServerwithrequired_scopes=["returns:read"]andscopes_supported=["returns:read", "returns:write"]servesscopes_supportedas both scopes overGET /.well-known/oauth-protected-resource/mcp.test_scopes_supported_defaults_to_required_scopes: without the new field, the metadata still advertisesrequired_scopes.Verified:
pytest tests/server/auth/test_protected_resource.py -q-> 16 passed; with only the three source files reverted, the advertising test fails (the field is ignored and the metadata lists onlyreturns:read).ruff checkandruff format --checkare clean on all four files.Note: the issue author offered to open this PR; this is unassigned work on the same proposal, and the tests above are new. Happy to adjust the field name or the default if you prefer a different shape.