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:- 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: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.
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)
-
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:
- Keep the default
api://{client_id} - Set a custom value, following the supported formats (see Identifier URI restrictions)
- Keep the default
- Click Add a scope and create a scope your app will require, for example:
- Scope name:
read(orwrite, etc.) - Admin consent display name/description: as appropriate for your org
- Who can consent: as needed (Admins only or Admins and users)
- Scope name:
-
Configure Access Token Version: Ensure your app uses access token v2
- Go to Manifest in the App registration sidebar.
- Find the
requestedAccessTokenVersionproperty and set it to2: - Click Save at the top of the manifest editor.
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.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”
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
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 prefixesrequired_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”:
| You write | Sent to Azure | Validated on tokens |
|---|---|---|
mcp-read | api://xxx/mcp-read | ✓ |
my.scope | api://xxx/my.scope | ✓ |
openid | openid | ✗ (OIDC scope) |
api://xxx/read | api://xxx/read | ✓ |
additional_authorize_scopes — External scopes (e.g., Microsoft Graph) for server-side use:
| You write | Sent to Azure | Validated on tokens |
|---|---|---|
User.Read | User.Read | ✗ |
Mail.Send | Mail.Send | ✗ |
offline_access is automatically included to obtain refresh tokens. FastMCP manages token refreshing automatically.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: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.
Production Configuration
New in version2.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.Token Verification Only (Managed Identity)
New in version2.15.0
For deployments where your server only needs to validate incoming tokens — such as Azure Container Apps with Managed Identity — use AzureJWTVerifier with RemoteAuthProvider instead of the full AzureProvider.
This pattern is ideal when:
- Your infrastructure handles authentication (e.g., Managed Identity)
- You don’t need the OAuth proxy flow (no
client_secretrequired) - You just need to verify that incoming Azure AD tokens are valid
server.py
AzureJWTVerifier handles Azure’s scope format automatically. You write scope names exactly as they appear in Azure Portal under Expose an API (e.g., access_as_user). The verifier validates tokens using the short-form scopes that Azure puts in the scp claim, while advertising the full URI scopes (e.g., api://your-client-id/access_as_user) in OAuth metadata so MCP clients know what to request.
For Azure Government, pass
base_authority="login.microsoftonline.us" to AzureJWTVerifier.On-Behalf-Of (OBO)
New in version3.0.0
The On-Behalf-Of (OBO) flow allows your FastMCP server to call downstream Microsoft APIs—like Microsoft Graph—using the authenticated user’s identity. When a user authenticates to your MCP server, you receive a token for your API. OBO exchanges that token for a new token that can call other services, maintaining the user’s identity and permissions throughout the chain.
This pattern is useful when your tools need to access user-specific data from Microsoft services: reading emails, accessing calendar events, querying SharePoint, or any other Graph API operation that requires user context.
OBO features require the
azure extra:Azure Portal Setup
OBO requires additional configuration in your Azure App registration beyond basic authentication.Add API Permissions
In your App registration, navigate to API permissions and add the Microsoft Graph permissions your tools will need.
- Click Add a permission → Microsoft Graph → Delegated permissions
- Select the permissions required for your use case (e.g.,
Mail.Read,Calendars.Read,User.Read) - Repeat for any other APIs you need to call
Grant Admin Consent
OBO requires admin consent for the permissions you’ve added. In the API permissions page, click Grant admin consent for [Your Organization].Without admin consent, OBO token exchanges will fail with an
AADSTS65001 error indicating the user or administrator hasn’t consented to use the application.Configure AzureProvider for OBO
Theadditional_authorize_scopes parameter tells Azure which downstream API permissions to include during the initial authorization. These scopes establish what your server can request through OBO later.
server.py
additional_authorize_scopes are requested during the initial OAuth flow but aren’t validated on incoming tokens. They establish permission for your server to later exchange the user’s token for downstream API access.
Use fully-qualified scope URIs for downstream APIs (e.g.,
https://graph.microsoft.com/Mail.Read). Short forms like Mail.Read work for authorization requests, but fully-qualified URIs are clearer and avoid ambiguity.EntraOBOToken Dependency
TheEntraOBOToken dependency handles the complete OBO flow automatically. Declare it as a parameter default with the scopes you need, and FastMCP exchanges the user’s token for a downstream API token before your function runs.
graph_token parameter receives a ready-to-use access token for Microsoft Graph. FastMCP handles the OBO exchange transparently—your function just uses the token to call the API.

