Skip to main content
New in version 2.12.0 This guide shows you how to secure your FastMCP server using GitHub OAuth. Since GitHub doesn’t support Dynamic Client Registration, this integration uses the OAuth Proxy pattern to bridge GitHub’s traditional OAuth with MCP’s authentication requirements.

Configuration

Prerequisites

Before you begin, you will need:
  1. A GitHub Account with access to create OAuth Apps
  2. Your FastMCP server’s URL (can be localhost for development, e.g., http://localhost:8000)

Step 1: Create a GitHub OAuth App

Create an OAuth App in your GitHub settings to get the credentials needed for authentication:
1

Navigate to OAuth Apps

Go to Settings → Developer settings → OAuth Apps in your GitHub account, or visit github.com/settings/developers.Click “New OAuth App” to create a new application.
2

Configure Your OAuth App

Fill in the application details:
  • Application name: Choose a name users will recognize (e.g., “My FastMCP Server”)
  • Homepage URL: Your application’s homepage or documentation URL
  • Authorization callback URL: Your server URL + /auth/callback (e.g., http://localhost:8000/auth/callback)
The callback URL must match exactly. The default path is /auth/callback, but you can customize it using the redirect_path parameter. For local development, GitHub allows http://localhost URLs. For production, you must use HTTPS.
If you want to use a custom callback path (e.g., /auth/github/callback), make sure to set the same path in both your GitHub OAuth App settings and the redirect_path parameter when configuring the GitHubProvider.
3

Save Your Credentials

After creating the app, you’ll see:
  • Client ID: A public identifier like Ov23liAbcDefGhiJkLmN
  • Client Secret: Click “Generate a new client secret” and save the value securely
Store these credentials securely. Never commit them to version control. Use environment variables or a secrets manager in production.

Step 2: FastMCP Configuration

Create your FastMCP server using the GitHubProvider, which handles GitHub’s OAuth quirks automatically:
server.py

Testing

Running the Server

Start your FastMCP server with HTTP transport to enable OAuth flows:
Your server is now running and protected by GitHub OAuth authentication.

Testing with a Client

Create a test client that authenticates with your GitHub-protected server:
test_client.py
When you run the client for the first time:
  1. Your browser will open to GitHub’s authorization page
  2. After you authorize the app, you’ll be redirected back
  3. 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 GitHub provider to be used automatically without explicitly instantiating it in code.

FASTMCP_SERVER_AUTH
default:"Not set"
Set to fastmcp.server.auth.providers.github.GitHubProvider to use GitHub authentication.

GitHub-Specific Configuration

These environment variables provide default values for the GitHub provider, whether it’s instantiated manually or configured via FASTMCP_SERVER_AUTH.

FASTMCP_SERVER_AUTH_GITHUB_CLIENT_ID
required
Your GitHub OAuth App Client ID (e.g., Ov23liAbcDefGhiJkLmN)
FASTMCP_SERVER_AUTH_GITHUB_CLIENT_SECRET
required
Your GitHub OAuth App Client Secret
FASTMCP_SERVER_AUTH_GITHUB_BASE_URL
default:"http://localhost:8000"
Public URL where OAuth endpoints will be accessible (includes any mount path)
FASTMCP_SERVER_AUTH_GITHUB_ISSUER_URL
default:"Uses BASE_URL"
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.
FASTMCP_SERVER_AUTH_GITHUB_REDIRECT_PATH
default:"/auth/callback"
Redirect path configured in your GitHub OAuth App
FASTMCP_SERVER_AUTH_GITHUB_REQUIRED_SCOPES
default:"[\"user\"]"
Comma-, space-, or JSON-separated list of required GitHub scopes (e.g., user repo or ["user","repo"])
FASTMCP_SERVER_AUTH_GITHUB_TIMEOUT_SECONDS
default:"10"
HTTP request timeout for GitHub API calls
Example .env file:
With environment variables set, your server code simplifies to:
server.py