New in version: 2.12.0
This guide shows you how to secure your FastMCP server using Google OAuth. Since Google doesn’t support Dynamic Client Registration, this integration uses the OAuth Proxy pattern to bridge Google’s traditional OAuth with MCP’s authentication requirements.
Configuration
Prerequisites
Before you begin, you will need:- A Google Cloud Account with access to create OAuth 2.0 Client IDs
- Your FastMCP server’s URL (can be localhost for development, e.g.,
http://localhost:8000)
Step 1: Create a Google OAuth 2.0 Client ID
Create an OAuth 2.0 Client ID in your Google Cloud Console to get the credentials needed for authentication:1
Navigate to OAuth Consent Screen
Go to the Google Cloud Console and select your project (or create a new one).First, configure the OAuth consent screen by navigating to APIs & Services → OAuth consent screen. Choose “External” for testing or “Internal” for G Suite organizations.
2
Create OAuth 2.0 Client ID
Navigate to APIs & Services → Credentials and click ”+ CREATE CREDENTIALS” → “OAuth client ID”.Configure your OAuth client:
- Application type: Web application
- Name: Choose a descriptive name (e.g., “FastMCP Server”)
- Authorized JavaScript origins: Add your server’s base URL (e.g.,
http://localhost:8000) - Authorized redirect URIs: Add your server URL +
/auth/callback(e.g.,http://localhost:8000/auth/callback)
3
Save Your Credentials
After creating the client, you’ll receive:
- Client ID: A string ending in
.apps.googleusercontent.com - Client Secret: A string starting with
GOCSPX-
Step 2: FastMCP Configuration
Create your FastMCP server using theGoogleProvider, which handles Google’s OAuth flow automatically:
server.py
Testing
Running the Server
Start your FastMCP server with HTTP transport to enable OAuth flows:Testing with a Client
Create a test client that authenticates with your Google-protected server:test_client.py
- Your browser will open to Google’s authorization page
- Sign in with your Google account and grant the requested permissions
- After authorization, you’ll be redirected back
- The client receives the token and can make authenticated requests
The client caches tokens locally, so you won’t need to re-authenticate for subsequent runs unless the token expires or you explicitly clear the cache.
Production Configuration
New in version: 2.13.0
For production deployments with persistent token management across server restarts, configure jwt_signing_key and client_storage:
server.py
Parameters (
jwt_signing_key and client_storage) work together to ensure tokens and client registrations survive server restarts. Wrap your storage in FernetEncryptionWrapper to encrypt sensitive OAuth tokens at rest - without it, tokens are stored in plaintext. Store secrets in environment variables and use a persistent storage backend like Redis for distributed deployments.For complete details on these parameters, see the OAuth Proxy documentation.Environment Variables
New in version: 2.12.1
For production deployments, use environment variables instead of hardcoding credentials.
Provider Selection
Setting this environment variable allows the Google provider to be used automatically without explicitly instantiating it in code.Set to
fastmcp.server.auth.providers.google.GoogleProvider to use Google authentication.Google-Specific Configuration
These environment variables provide default values for the Google provider, whether it’s instantiated manually or configured viaFASTMCP_SERVER_AUTH.
Your Google OAuth 2.0 Client ID (e.g.,
123456789.apps.googleusercontent.com)Your Google OAuth 2.0 Client Secret (e.g.,
GOCSPX-abc123...)Public URL where OAuth endpoints will be accessible (includes any mount path)
Issuer URL for OAuth metadata (defaults to
BASE_URL). Set to root-level URL when mounting under a path prefix to avoid 404 logs. See HTTP Deployment guide for details.Redirect path configured in your Google OAuth Client
Comma-, space-, or JSON-separated list of required Google scopes (e.g.,
"openid,https://www.googleapis.com/auth/userinfo.email" or ["openid", "https://www.googleapis.com/auth/userinfo.email"])HTTP request timeout for Google API calls
.env file:
server.py

