Add support for serverside oauth (#255)
Some checks failed
Check uv.lock / check-lock (push) Has been cancelled
Main branch checks / checks (push) Has been cancelled

Co-authored-by: David Soria Parra <davidsp@anthropic.com>
Co-authored-by: Basil Hosmer <basil@anthropic.com>
Co-authored-by: ihrpr <inna@anthropic.com>
This commit is contained in:
Peter Raboud 2025-05-01 11:42:59 -07:00 • committed by GitHub
commit 2210c1be18
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -309,6 +309,33 @@ async def long_task(files: list[str], ctx: Context) -> str:
return "Processing complete"
```
### Authentication
Authentication can be used by servers that want to expose tools accessing protected resources.
`mcp.server.auth` implements an OAuth 2.0 server interface, which servers can use by
providing an implementation of the `OAuthServerProvider` protocol.
```
mcp = FastMCP("My App",
auth_provider=MyOAuthServerProvider(),
auth=AuthSettings(
issuer_url="https://myapp.com",
revocation_options=RevocationOptions(
enabled=True,
),
client_registration_options=ClientRegistrationOptions(
enabled=True,
valid_scopes=["myscope", "myotherscope"],
default_scopes=["myscope"],
),
required_scopes=["myscope"],
),
)
```
See [OAuthServerProvider](mcp/server/auth/provider.py) for more details.
## Running Your Server
### Development Mode