New in version: 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:| Scope | Description |
|---|---|
identify | Access username, avatar, and discriminator (default) |
email | Access the user’s email address |
guilds | Access the user’s list of servers |
guilds.join | Ability to add the user to a server |
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.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.
Your Discord Application Client ID (e.g.,
12345)Your Discord OAuth Client Secret
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 Discord OAuth settings
Comma-, space-, or JSON-separated list of required Discord scopes (e.g.,
identify,email or ["identify","email"])HTTP request timeout for Discord API calls
.env file:
server.py

