Secure your FastMCP server’s HTTP endpoints by validating JWT tokens.
New in version: 2.11.0
Authorization
header with the “Bearer” scheme. The server then validates this token to grant or deny access.
FastMCP supports Bearer Token authentication for its HTTP-based transports (http
and sse
), allowing you to protect your server from unauthorized access.
jwks_uri
is not providedpublic_key
is not providediss
claim valueaud
claim valueJWTVerifier
validates JWT tokens using public key cryptography. Use this when you have JWT tokens issued by an external identity provider and want self-contained validation without network calls.
JWTVerifier
as a string.
IntrospectionTokenVerifier
validates tokens by calling an OAuth 2.0 authorization server’s introspection endpoint (RFC 7662). This is useful when your authorization server is separate from your FastMCP server, you’re using opaque tokens, or you need real-time token validation with immediate revocation support.
StaticTokenVerifier
validates tokens against a predefined dictionary of token strings and claims. Use this for development and testing when you need predictable tokens without setting up a real OAuth server.
client_id
(required), scopes
, sub
, expires_at
, and any custom metadata your application needs.
RSAKeyPair
utility class to generate tokens without needing an external OAuth provider.
RSAKeyPair
utility is intended for development and testing only. For production, use a proper OAuth 2.1 Authorization Server or Identity Provider.create_token()
method accepts these parameters:
get_access_token()
dependency function: