Skip to main content
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:
  1. A Discord Account with access to create applications
  2. 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
The redirect URL must match exactly. The default path is /auth/callback, but you can customize it using the redirect_path parameter. Discord allows http://localhost URLs for development. For production, use HTTPS.
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
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 the DiscordProvider, which handles Discord’s OAuth flow automatically:
server.py

Testing

Running the Server

Start your FastMCP server with HTTP transport to enable OAuth flows:
Your server is now running and protected by Discord OAuth authentication.

Testing with a Client

Create a test client that authenticates with your Discord-protected server:
test_client.py
When you run the client for the first time:
  1. Your browser will open to Discord’s authorization page
  2. Sign in with your Discord account and authorize the app
  3. After authorization, you’ll be redirected back
  4. 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, configure jwt_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.