New in version: 2.12.0
Secure your FastMCP server with WorkOS Connect authentication. This integration uses the OAuth Proxy pattern to handle authentication through WorkOS Connect while maintaining compatibility with MCP clients.
This guide covers WorkOS Connect applications. For Dynamic Client Registration (DCR) with AuthKit, see the AuthKit integration instead.
Configuration
Prerequisites
Before you begin, you will need:- A WorkOS Account with access to create OAuth Apps
- Your FastMCP server’s URL (can be localhost for development, e.g.,
http://localhost:8000
)
Step 1: Create a WorkOS OAuth App
Create an OAuth App in your WorkOS dashboard to get the credentials needed for authentication:1
Create OAuth Application
In your WorkOS dashboard:
- Navigate to Applications
- Click Create Application
- Select OAuth Application
- Name your application
2
Get Credentials
In your OAuth application settings:
- Copy your Client ID (starts with
client_
) - Click Generate Client Secret and save it securely
- Copy your AuthKit Domain (e.g.,
https://your-app.authkit.app
)
3
Configure Redirect URI
In the Redirect URIs section:
- Add:
http://localhost:8000/auth/callback
(for development) - For production, add your server’s public URL +
/auth/callback
The callback URL must match exactly. The default path is
/auth/callback
, but you can customize it using the redirect_path
parameter.Step 2: FastMCP Configuration
Create your FastMCP server using theWorkOSProvider
:
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 WorkOS-protected server:client.py
- Your browser will open to WorkOS’s authorization page
- After you authorize the app, 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.
Environment Variables
New in version: 2.12.1
For production deployments, use environment variables instead of hardcoding credentials.
Provider Selection
Setting this environment variable allows the WorkOS provider to be used automatically without explicitly instantiating it in code.Set to
fastmcp.server.auth.providers.workos.WorkOSProvider
to use WorkOS authentication.WorkOS-Specific Configuration
These environment variables provide default values for the WorkOS provider, whether it’s instantiated manually or configured viaFASTMCP_SERVER_AUTH
.
Your WorkOS OAuth App Client ID (e.g.,
client_01K33Y6GGS7T3AWMPJWKW42Y3Q
)Your WorkOS OAuth App Client Secret
Your WorkOS AuthKit domain (e.g.,
https://your-app.authkit.app
)Public URL of your FastMCP server for OAuth callbacks
Redirect path configured in your WorkOS OAuth App
Comma-, space-, or JSON-separated list of required OAuth scopes (e.g.,
openid profile email
or ["openid","profile","email"]
)HTTP request timeout for WorkOS API calls
.env
file:
server.py
server.py
Configuration Options
WorkOS OAuth application client ID
WorkOS OAuth application client secret
Your WorkOS AuthKit domain URL (e.g.,
https://your-app.authkit.app
)Your FastMCP server’s public URL
OAuth scopes to request
OAuth callback path
API request timeout