URL: https://gofastmcp.com/integrations/discord
Title: Discord OAuth 🤝 FastMCP - FastMCP

Documentation Index
Fetch the complete documentation index at:
/llms.txt
Use this file to discover all available pages before exploring further.
Skip to main content
Meet
Prefect Horizon
, the enterprise MCP gateway built by the team behind FastMCP
FastMCP
home page
v3
Prefect Horizon
PrefectHQ/fastmcp
25,596
PrefectHQ/fastmcp
25,596
Search...
Navigation
Auth
Discord OAuth 🤝 FastMCP
Search the docs...
Ctrl
K
Documentation
Get Started
Welcome!
Installation
Quickstart
Servers
Overview
Core Components
Working with Tools
MCP Providers
Interactivity
Extensibility
Auth
Deployment
Apps
Overview
Quickstart
NEW
FastMCPApp
NEW
Interactive Tools
NEW
Generative UI
NEW
Custom HTML
Reference
Clients
Overview
Client-Only Package
Transports
fastmcp-remote
Operations
UPDATED
Authentication
UPDATED
Integrations
Auth
Auth0
AuthKit
AWS Cognito
Azure (Entra ID)
Descope
Discord
Eunomia Auth
GitHub
Google
Keycloak
NEW
Oracle
Permit.io
PropelAuth
Scalekit
Supabase
WorkOS
Web Frameworks
AI Assistants
AI SDKs
MCP.json
More
Settings
CLI
Upgrading
Development
What's New
FAQ
On this page
Configuration
Prerequisites
Step 1: Create a Discord Application
Step 2: FastMCP Configuration
Testing
Running the Server
Testing with a Client
Discord Scopes
Production Configuration
Auth
Discord OAuth 🤝 FastMCP
Copy page
Secure your FastMCP server with Discord OAuth
Copy page
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
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
from
fastmcp
import
FastMCP
from
fastmcp
.
server
.
auth
.
providers
.
discord
import
DiscordProvider
auth_provider
=
DiscordProvider
(
client_id
=
"
12345
"
,
# Your Discord Application Client ID
client_secret
=
"
your-client-secret
"
,
# Your Discord OAuth Client Secret
base_url
=
"
http://localhost:8000
"
,
# Must match your OAuth configuration
)
mcp
=
FastMCP
(
name
=
"
Discord Secured App
"
,
auth
=
auth_provider
)
@
mcp
.
tool
async
def
get_user_info
()
->
dict
:
"""
Returns information about the authenticated Discord user.
"""
from
fastmcp
.
server
.
dependencies
import
get_access_token
token
=
get_access_token
()
return
{
"
discord_id
"
:
token
.
claims
.
get
(
"
sub
"
),
"
username
"
:
token
.
claims
.
get
(
"
username
"
),
"
avatar
"
:
token
.
claims
.
get
(
"
avatar
"
),
}
​
Testing
​
Running the Server
Start your FastMCP server with HTTP transport to enable OAuth flows:
fastmcp
run
server.py
--transport
http
--port
8000
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
from
fastmcp
import
Client
import
asyncio
async
def
main
():
async
with
Client
(
"
http://localhost:8000/mcp
"
,
auth
=
"
oauth
"
)
as
client
:
print
(
"
✓ Authenticated with Discord!
"
)
result
=
await
client
.
call_tool
(
"
get_user_info
"
)
print
(
f
"Discord user:
{
result
[
'
username
'
]
}
"
)
if
__name__
==
"
__main__
"
:
asyncio
.
run
(
main
())
When you run the client for the first time:
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
To request additional scopes:
auth_provider
=
DiscordProvider
(
client_id
=
"
...
"
,
client_secret
=
"
...
"
,
base_url
=
"
http://localhost:8000
"
,
required_scopes
=[
"
identify
"
,
"
email
"
],
)
​
Production Configuration
For production deployments with persistent token management across server restarts, configure
jwt_signing_key
and
client_storage
:
server.py
import
os
from
fastmcp
import
FastMCP
from
fastmcp
.
server
.
auth
.
providers
.
discord
import
DiscordProvider
from
key_value
.
aio
.
stores
.
redis
import
RedisStore
from
key_value
.
aio
.
wrappers
.
encryption
import
FernetEncryptionWrapper
from
cryptography
.
fernet
import
Fernet
auth_provider
=
DiscordProvider
(
client_id
=
"
12345
"
,
client_secret
=
os
.
environ
[
"
DISCORD_CLIENT_SECRET
"
],
base_url
=
"
https://your-production-domain.com
"
,
jwt_signing_key
=
os
.
environ
[
"
JWT_SIGNING_KEY
"
],
client_storage
=
FernetEncryptionWrapper
(
key_value
=
RedisStore
(
host
=
os
.
environ
[
"
REDIS_HOST
"
],
port
=
int
(
os
.
environ
[
"
REDIS_PORT
"
])
),
fernet
=
Fernet
(
os
.
environ
[
"
STORAGE_ENCRYPTION_KEY
"
])
)
)
mcp
=
FastMCP
(
name
=
"
Production Discord App
"
,
auth
=
auth_provider
)
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
.
Descope 🤝 FastMCP
Previous
Eunomia Authorization 🤝 FastMCP
Next
Ctrl
+I
discord
github
website
x
Powered by
This documentation is built and hosted on Mintlify, a developer documentation platform
Assistant
Responses are generated using AI and may contain mistakes.
\n\n
\n
\n \n
\n
