Skip to main content
New in version 2.13.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. FastMCP validates Azure JWTs against your application’s client_id.

Configuration

Prerequisites

Before you begin, you will need:
  1. An Azure Account with access to create App registrations
  2. Your FastMCP server’s URL (can be localhost for development, e.g., http://localhost:8000)
  3. 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.
  • Expose an API: Configure your Application ID URI and define scopes
    • Go to Expose an API in the App registration sidebar.
    • Click Set next to “Application ID URI” and choose one of:
    • Click Add a scope and create a scope your app will require, for example:
      • Scope name: read (or write, etc.)
      • Admin consent display name/description: as appropriate for your org
      • Who can consent: as needed (Admins only or Admins and users)
  • Configure Access Token Version: Ensure your app uses access token v2
    • Go to Manifest in the App registration sidebar.
    • Find the requestedAccessTokenVersion property and set it to 2:
    • Click Save at the top of the manifest editor.
Access token v2 is required for FastMCP’s Azure integration to work correctly. If this is not set, you may encounter authentication errors.
In FastMCP’s AzureProvider, set identifier_uri to your Application ID URI (optional; defaults to api://{client_id}) and set required_scopes to the unprefixed scope names (e.g., read, write). During authorization, FastMCP automatically prefixes scopes with your identifier_uri.
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 the AzureProvider, 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
Using your specific tenant ID is recommended for better security and control.
Important: The required_scopes parameter is REQUIRED and must include at least one scope. Azure’s OAuth API requires the scope parameter in all authorization requests - you cannot authenticate without specifying at least one scope. Use the unprefixed scope names from your Azure App registration (e.g., ["read", "write"]). These scopes must be created under Expose an API in your App registration.

Scope Handling

FastMCP automatically prefixes required_scopes with your identifier_uri (e.g., api://your-client-id) since these are your custom API scopes. Scopes in additional_authorize_scopes are sent as-is since they target external resources like Microsoft Graph. required_scopes — Your custom API scopes, defined in Azure “Expose an API”: additional_authorize_scopes — External scopes (e.g., Microsoft Graph) for server-side use:
Why aren’t additional_authorize_scopes validated? Azure issues separate tokens per resource. The access token FastMCP receives is for your API—Graph scopes aren’t in its scp claim. To call Graph APIs, your server uses the upstream Azure token in an on-behalf-of (OBO) flow.
OIDC scopes (openid, profile, email, offline_access) are never prefixed and excluded from validation because Azure doesn’t include them in access token scp claims.

Testing

Running the Server

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

Testing with a Client

Create a test client that authenticates with your Azure-protected server:
test_client.py
When you run the client for the first time:
  1. Your browser will open to Microsoft’s authorization page
  2. Sign in with your Microsoft account (work, school, or personal based on your tenant configuration)
  3. Grant the requested permissions
  4. After authorization, you’ll be redirected back
  5. 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.

Production Configuration

New in version 2.13.0 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.

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.

FASTMCP_SERVER_AUTH
default:"Not set"
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 via FASTMCP_SERVER_AUTH.

FASTMCP_SERVER_AUTH_AZURE_CLIENT_ID
required
Your Azure App registration Client ID (e.g., 835f09b6-0f0f-40cc-85cb-f32c5829a149)
FASTMCP_SERVER_AUTH_AZURE_CLIENT_SECRET
required
Your Azure App registration Client Secret
FASTMCP_SERVER_AUTH_AZURE_TENANT_ID
required
Your Azure tenant ID (specific ID, “organizations”, or “consumers”)
This is REQUIRED. Find your tenant ID in Azure Portal under Microsoft Entra ID → Overview.
FASTMCP_SERVER_AUTH_AZURE_BASE_URL
default:"http://localhost:8000"
Public URL where OAuth endpoints will be accessible (includes any mount path)
FASTMCP_SERVER_AUTH_AZURE_ISSUER_URL
default:"Uses BASE_URL"
Issuer URL for OAuth metadata (defaults to BASE_URL). Set to root-level URL when mounting under a path prefix to avoid 404 logs. See HTTP Deployment guide for details.
FASTMCP_SERVER_AUTH_AZURE_REDIRECT_PATH
default:"/auth/callback"
Redirect path configured in your Azure App registration
FASTMCP_SERVER_AUTH_AZURE_REQUIRED_SCOPES
required
Comma-, space-, or JSON-separated list of required scopes for your API (at least one scope required). These are validated on tokens and used as defaults if the client does not request specific scopes. Use unprefixed scope names from your Azure App registration (e.g., read,write).You can include standard OIDC scopes (openid, profile, email, offline_access) in required_scopes. FastMCP automatically handles them correctly: they’re sent to Azure unprefixed and excluded from token validation (since Azure doesn’t include OIDC scopes in access token scp claims).
Azure’s OAuth API requires the scope parameter - you must provide at least one scope.
FASTMCP_SERVER_AUTH_AZURE_ADDITIONAL_AUTHORIZE_SCOPES
default:""
Comma-, space-, or JSON-separated list of additional scopes to include in the authorization request without prefixing. Use this to request upstream scopes such as Microsoft Graph permissions. These are not used for token validation.
FASTMCP_SERVER_AUTH_AZURE_IDENTIFIER_URI
default:"api://{client_id}"
Application ID URI used to prefix scopes during authorization.
FASTMCP_SERVER_AUTH_AZURE_BASE_AUTHORITY
default:"login.microsoftonline.com"
Azure authority base URL. Override this to use Azure Government:
  • login.microsoftonline.com - Azure Public Cloud (default)
  • login.microsoftonline.us - Azure Government
This setting affects all Azure OAuth endpoints (authorization, token, issuer, JWKS).
Example .env file:
With environment variables set, your server code simplifies to:
server.py