Secure your FastMCP server with flexible authentication patterns, from simple API keys to full OAuth 2.1 integration with external identity providers.
New in version: 2.11.0
Authentication in MCP presents unique challenges that differ from traditional web applications. MCP clients need to discover authentication requirements automatically, negotiate OAuth flows without user intervention, and work seamlessly across different identity providers. FastMCP addresses these challenges by providing authentication patterns that integrate with the MCP protocol while remaining simple to implement and deploy.
http
and sse
). The STDIO transport inherits security from its local execution environment.TokenVerifier
provides pure token validation without OAuth metadata endpoints. This class focuses on the essential task of determining whether a token is valid and extracting authorization information from its claims.
The implementation handles JWT signature verification, expiration checking, and claim extraction. It validates tokens against known issuers and audiences, ensuring that tokens intended for your server are not accepted by other systems.
JWTVerifier
will fetch public keys from the JWKS endpoint and validate incoming tokens against those keys. Only tokens with the correct issuer and audience claims will be accepted.
TokenVerifier
works well when you control both the token issuer and your MCP server, or when integrating with existing JWT-based infrastructure.
→ Complete guide: Token Verification
RemoteAuthProvider
enables authentication with identity providers that support Dynamic Client Registration (DCR), such as WorkOS AuthKit. With DCR, MCP clients can automatically register themselves with the identity provider and obtain credentials without any manual configuration.
This class combines token validation with OAuth discovery metadata. It extends TokenVerifier
functionality by adding OAuth 2.0 protected resource endpoints that advertise your authentication requirements. MCP clients examine these endpoints to understand which identity providers you trust and how to obtain valid tokens.
The key requirement is that your identity provider must support DCR - the ability for clients to dynamically register and obtain credentials. This is what enables the seamless, automated authentication flow that MCP requires.
For example, the built-in AuthKitProvider
uses WorkOS AuthKit, which fully supports DCR:
AuthKitProvider
automatically configures token validation against WorkOS and provides the OAuth metadata that MCP clients need for automatic authentication.
RemoteAuthProvider
is ideal for production applications when your identity provider supports Dynamic Client Registration (DCR). This enables fully automated authentication without manual client configuration.
→ Complete guide: Remote OAuth
New in version: 2.12.0
OAuthProxy
enables authentication with OAuth providers that don’t support Dynamic Client Registration (DCR), such as GitHub, Google, Azure, and most traditional enterprise identity systems.
When identity providers require manual app registration and fixed credentials, OAuthProxy
bridges the gap. It presents a DCR-compliant interface to MCP clients (accepting any registration request) while using your pre-registered credentials with the upstream provider. The proxy handles the complexity of callback forwarding, enabling dynamic client callbacks to work with providers that require fixed redirect URIs.
This class solves the fundamental incompatibility between MCP’s expectation of dynamic registration and traditional OAuth providers’ requirement for manual app registration.
For example, the built-in GitHubProvider
extends OAuthProxy
to work with GitHub’s OAuth system:
OAuthProxy
with GitHub-specific token validation. The proxy handles the complete OAuth flow while making GitHub’s non-DCR authentication work seamlessly with MCP clients.
OAuthProxy
is essential when integrating with OAuth providers that don’t support DCR. This includes most established providers like GitHub, Google, and Azure, which require manual app registration through their developer consoles.
→ Complete guide: OAuth Proxy
OAuthProvider
implements a complete OAuth 2.0 authorization server within your MCP server. This class handles the full authentication lifecycle from user credential verification to token management.
The implementation provides all required OAuth endpoints including authorization, token, and discovery endpoints. It manages client registration, user consent, and token lifecycle while integrating with your user storage and authentication logic.
OAuthProvider
should be used only when you have specific requirements that external providers cannot meet and the expertise to implement OAuth securely.
→ Complete guide: Full OAuth Server
New in version: 2.12.1
Environment-based configuration separates authentication settings from application code, enabling the same codebase to work across different deployment environments without modification.
FastMCP automatically detects authentication configuration from environment variables when no explicit auth
parameter is provided. The configuration system supports all authentication providers and their various options.
fastmcp.server.auth.providers.github.GitHubProvider
- GitHub OAuthfastmcp.server.auth.providers.google.GoogleProvider
- Google OAuthfastmcp.server.auth.providers.jwt.JWTVerifier
- JWT token verificationfastmcp.server.auth.providers.workos.WorkOSProvider
- WorkOS OAuthfastmcp.server.auth.providers.workos.AuthKitProvider
- WorkOS AuthKitmycompany.auth.CustomProvider
- Your custom provider class