GeezerVison is showing github.com — [v1.x] Add AuthSettings.validate_token_resource to check a bearer token's resource by maxisbey · Pull Request #3451 · modelcontextprotocol/python-sdk
Conversation
v1.x backport of #3447.
Adds AuthSettings.validate_token_resource. When set, the bearer gate only accepts a token that the TokenVerifier reports as issued for resource_server_url (via AccessToken.resource); a token reporting another resource, or none, gets the same 401 as an unrecognized token. Leaving it unset on a resource server emits a DeprecationWarning and behaves as off; 3.0 makes it the default there. RefreshToken gains an optional resource so providers can carry the binding through the refresh grant.
Differences from #3447
- The wiring is
FastMCP.sse_app() and FastMCP.streamable_http_app() in src/mcp/server/fastmcp/server.py (main: Server.streamable_http_app() and MCPServer.sse_app()).
- Plain
DeprecationWarning, as v1.x has no MCPDeprecationWarning (same as [v1.x] Validate the authorization server metadata issuer on every discovery path #3431).
- v1.x has no interaction suite or docs tutorials; the tests are the
BearerAuthBackend unit table and the AuthSettings warning/validation tests, and the documentation lands in docs/authorization.md (the oauth_server snippet it mirrors sets the option against its endpoint URL).
How Has This Been Tested?
Unit tests as above; driven end to end under uvicorn on FastMCP with an introspection-backed verifier over Streamable HTTP (option on: a token for another resource gets 401 and one for this server 200; unset: behaviour unchanged apart from the warning); full suite with coverage, ruff, pyright.
Breaking Changes
None. Unset behaves as off (with the deprecation warning); BearerAuthBackend(verifier) and existing verifiers behave as before. Setting it to True without a resource_server_url raises at construction.
Types of changes
- Bug fix (non-breaking change which fixes an issue)
- New feature (non-breaking change which adds functionality)
- Breaking change (fix or feature that would cause existing functionality to change)
- Documentation update
Checklist
- I am assigned to the linked issue (or it is labeled
help wanted, or I'm a maintainer)
- I have disclosed any AI assistance and can explain the change in my own words
- I have read the MCP Documentation
- My code follows the repository's style guidelines
- New and existing tests pass locally
- I have added appropriate error handling
- I have added or updated documentation as needed
AI Disclaimer
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
…en's resource
v1.x backport. BearerAuthBackend takes an optional resource_server_url; when
it is set, only a token the verifier reports as issued for that URL
(AccessToken.resource, the RFC 8707 resource indicator, compared as a URL
with a trailing slash tolerated) is accepted, and anything else is answered
401 like an unrecognized token. AuthSettings.validate_token_resource turns
this on for FastMCP's SSE and Streamable HTTP apps; leaving it unset while
resource_server_url is set emits a DeprecationWarning and behaves as False,
and 3.0 makes True the default there. RefreshToken gains an optional
resource so a provider can carry the binding through the refresh grant.
TokenVerifier.verify_token's docstring and docs/authorization.md say where
the token's audience goes and when to enable the option versus checking the
audience in the verifier. The oauth_server snippet and the simple-auth
example set it.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
cubic-dev-ai
Bot
left a comment
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All reported issues were addressed across 10 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Findings marked 🟡 are optional suggestions and need no follow-up push.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.