2.13.2
This guide shows you how to secure your FastMCP server using Discord OAuth. Since Discord doesnât support Dynamic Client Registration, this integration uses the OAuth Proxy pattern to bridge Discordâs traditional OAuth with MCPâs authentication requirements.
Configuration
Prerequisites
Before you begin, you will need:- A Discord Account with access to create applications
- Your FastMCP serverâs URL (can be localhost for development, e.g.,
http://localhost:8000)
Step 1: Create a Discord Application
Create an application in the Discord Developer Portal to get the credentials needed for authentication:1
Navigate to Discord Developer Portal
Go to the Discord Developer Portal.Click âNew Applicationâ and give it a name users will recognize (e.g., âMy FastMCP Serverâ).
2
Configure OAuth2 Settings
In the left sidebar, click âOAuth2â.In the Redirects section, click âAdd Redirectâ and enter your callback URL:
- For development:
http://localhost:8000/auth/callback - For production:
https://your-domain.com/auth/callback
3
Save Your Credentials
On the same OAuth2 page, youâll find:
- Client ID: A numeric string like
12345 - Client Secret: Click âReset Secretâ to generate one
Step 2: FastMCP Configuration
Create your FastMCP server using theDiscordProvider, which handles Discordâ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 Discord-protected server:test_client.py
- Your browser will open to Discordâs authorization page
- Sign in with your Discord account and authorize the app
- 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.
Discord Scopes
Discord OAuth supports several scopes for accessing different types of user data:
To request additional scopes:
Production Configuration
For production deployments with persistent token management across server restarts, configurejwt_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
For production deployments, use environment variables instead of hardcoding credentials.Provider Selection
Setting this environment variable allows the Discord provider to be used automatically without explicitly instantiating it in code.default:"Not set"
Set to
fastmcp.server.auth.providers.discord.DiscordProvider to use Discord authentication.Discord-Specific Configuration
These environment variables provide default values for the Discord provider, whether itâs instantiated manually or configured viaFASTMCP_SERVER_AUTH.
required
Your Discord Application Client ID (e.g.,
12345)required
Your Discord OAuth Client Secret
default:"http://localhost:8000"
Public URL where OAuth endpoints will be accessible (includes any mount path)
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.default:"/auth/callback"
Redirect path configured in your Discord OAuth settings
default:"[\"identify\"]"
Comma-, space-, or JSON-separated list of required Discord scopes (e.g.,
identify,email or ["identify","email"])default:"10"
HTTP request timeout for Discord API calls
.env file:
server.py