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.
