New in version:Â 2.12.0
This guide shows you how to secure your FastMCP server using Azure OAuth (Microsoft Entra ID). Since Azure doesnât support Dynamic Client Registration, this integration uses the OAuth Proxy pattern to bridge Azureâs traditional OAuth with MCPâs authentication requirements.
Configuration
Prerequisites
Before you begin, you will need:- An Azure Account with access to create App registrations
- Your FastMCP serverâs URL (can be localhost for development, e.g.,
http://localhost:8000
) - Your Azure tenant ID (found in Azure Portal under Microsoft Entra ID)
Step 1: Create an Azure App Registration
Create an App registration in Azure Portal to get the credentials needed for authentication:1
Navigate to App registrations
Go to the Azure Portal and navigate to Microsoft Entra ID â App registrations.Click âNew registrationâ to create a new application.
2
Configure Your Application
Fill in the application details:
- Name: Choose a name users will recognize (e.g., âMy FastMCP Serverâ)
- Supported account types: Choose based on your needs:
- Single tenant: Only users in your organization
- Multitenant: Users in any Microsoft Entra directory
- Multitenant + personal accounts: Any Microsoft account
- Redirect URI: Select âWebâ and enter your server URL +
/auth/callback
(e.g.,http://localhost:8000/auth/callback
)
The redirect URI must match exactly. The default path is
/auth/callback
, but you can customize it using the redirect_path
parameter. For local development, Azure allows http://localhost
URLs. For production, you must use HTTPS.If you want to use a custom callback path (e.g.,
/auth/azure/callback
), make sure to set the same path in both your Azure App registration and the redirect_path
parameter when configuring the AzureProvider.3
Create Client Secret
After registration, navigate to Certificates & secrets in your appâs settings.
- Click âNew client secretâ
- Add a description (e.g., âFastMCP Serverâ)
- Choose an expiration period
- Click âAddâ
Copy the secret value immediately - it wonât be shown again! Youâll need to create a new secret if you lose it.
4
Note Your Credentials
From the Overview page of your app registration, note:
- Application (client) ID: A UUID like
835f09b6-0f0f-40cc-85cb-f32c5829a149
- Directory (tenant) ID: A UUID like
08541b6e-646d-43de-a0eb-834e6713d6d5
- Client Secret: The value you copied in the previous step
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 theAzureProvider
, which handles Azureâs OAuth flow automatically:
server.py
Important: The
tenant_id
parameter is REQUIRED. Azure no longer supports using âcommonâ for new applications due to security requirements. You must use one of:- Your specific tenant ID: Found in Azure Portal (e.g.,
08541b6e-646d-43de-a0eb-834e6713d6d5
) - âorganizationsâ: For work and school accounts only
- âconsumersâ: For personal Microsoft accounts only
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 Azure-protected server:test_client.py
- Your browser will open to Microsoftâs authorization page
- Sign in with your Microsoft account (work, school, or personal based on your tenant configuration)
- Grant the requested permissions
- 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.
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 Azure provider to be used automatically without explicitly instantiating it in code.Set to
fastmcp.server.auth.providers.azure.AzureProvider
to use Azure authentication.Azure-Specific Configuration
These environment variables provide default values for the Azure provider, whether itâs instantiated manually or configured viaFASTMCP_SERVER_AUTH
.
Your Azure App registration Client ID (e.g.,
835f09b6-0f0f-40cc-85cb-f32c5829a149
)Your Azure App registration Client Secret
Your Azure tenant ID (specific ID, âorganizationsâ, or âconsumersâ)
This is REQUIRED. Find your tenant ID in Azure Portal under Microsoft Entra ID â Overview.
Public URL of your FastMCP server for OAuth callbacks
Redirect path configured in your Azure App registration
FASTMCP_SERVER_AUTH_AZURE_REQUIRED_SCOPES
Comma-, space-, or JSON-separated list of required Microsoft Graph scopes
HTTP request timeout for Microsoft Graph API calls
.env
file:
server.py