Skip to main content
The auth option uses FastMCP’s built-in OAuth Proxy that acts as a secure intermediary between MCP clients and upstream OAuth providers. The proxy handles the complete OAuth 2.1 authorization flow, including Dynamic Client Registration (DCR), PKCE, consent management, and token management with encryption and token swap patterns enabled by default.

Key Features

  • Secure by Default: Automatic encryption (AES-256-GCM) and token swap pattern
  • Zero Configuration: Auto-generates keys and handles OAuth flows automatically
  • Pre-configured Providers: Built-in support for Google, GitHub, and Azure
  • RFC Compliant: Implements DCR (RFC 7591), PKCE, and OAuth 2.1
  • Optional JWKS: Support for RS256/ES256 token verification (via optional jose dependency)

Quick Start

The simplest way to use the OAuth Proxy is through the auth option with a pre-configured provider:
That’s it! All OAuth endpoints are automatically available:
  • /oauth/register - Dynamic Client Registration
  • /oauth/authorize - Authorization endpoint
  • /oauth/callback - OAuth callback handler
  • /oauth/consent - User consent screen
  • /oauth/token - Token exchange endpoint

Pre-configured Providers

Setup:
  1. Go to Google Cloud Console
  2. Create OAuth 2.0 Client ID
  3. Add redirect URI: https://your-server.com/oauth/callback

Advanced Configuration

For more control over OAuth behavior, use the oauth option directly with an OAuthProxy:

Token Swap Pattern

Token swap prevents upstream tokens from reaching the client. This is enabled by default for enhanced security.
If you don’t provide jwtSigningKey, one will be auto-generated. For production, it’s recommended to provide your own derived key for consistency across server restarts.

Loading Upstream Tokens

When using token swap, load the upstream tokens in your tools:

Persistent Token Storage

Use DiskStore for production deployments:
Benefits:
  • Tokens persist across server restarts
  • Automatic cleanup of expired entries
  • Thread-safe concurrent operations

Encrypted Token Storage

Storage is automatically encrypted with AES-256-GCM:
To disable encryption (only for development/testing):

Custom Claims Passthrough

Pass custom claims from upstream tokens (roles, permissions, etc.) to your proxy-issued JWTs. Enabled by default:

Using Claims for Authorization

Configuration Options

Security Best Practices

1

Use HTTPS in Production

2

Derive Keys from Secrets

3

Use Different Keys for Different Purposes

4

Enable Consent Screen

5

Use Persistent Encrypted Storage

6

Validate Redirect URIs

Next Steps

Authentication

Learn about authentication options and tool authorization

Custom Routes

Add authenticated custom HTTP routes to your server