2.11.0
The Full OAuth Server pattern exists to support the MCP protocol specification’s requirements. Your FastMCP server becomes both an Authorization Server and Resource Server, handling the complete authentication lifecycle from user login to token validation.
This documentation exists for completeness - the vast majority of applications should use external identity providers instead.
OAuthProvider
FastMCP provides theOAuthProvider base class that implements the OAuth 2.1 specification. To use this pattern, subclass OAuthProvider and implement the methods below. Its constructor takes your server’s public base_url, plus optional resource_base_url, issuer_url, service_documentation_url, client_registration_options, revocation_options, and required_scopes.
OAuthProvider handles OAuth endpoints, protocol flows, and security requirements, but delegates all storage, user management, and business logic to your implementation of the abstract methods.Required Implementation
You must implement these methods to create a functioning OAuth server:Client Management
Authorization Flow
Token Management
Token Management Methods
Exchange authorization code for access and refresh tokens. Must validate code and create new tokens.
Load refresh token from storage by token string. Return
None if token is invalid or expired.Exchange refresh token for new access/refresh token pair. Must validate scopes and token.