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.