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:- A GitHub Account with access to create OAuth Apps
- 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 theGitHubProvider
, which handles GitHubâs OAuth quirks 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 GitHub-protected server:test_client.py
- Your browser will open to GitHubâs authorization page
- After you authorize the app, 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.
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.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 viaFASTMCP_SERVER_AUTH
.
Your GitHub OAuth App Client ID (e.g.,
Ov23liAbcDefGhiJkLmN
)Your GitHub OAuth App Client Secret
Public URL of your FastMCP server for OAuth callbacks
Redirect path configured in your GitHub OAuth App
Comma-, space-, or JSON-separated list of required GitHub scopes (e.g.,
user repo
or ["user","repo"]
)HTTP request timeout for GitHub API calls
.env
file:
server.py