Zero Labs
Industry News / AI

Deploying an Azure MCP Server on Azure Container Apps Using Managed Identity

Source · Towards AI By Aayush Gupta

From the publisher’s feed, collected in the ZeroLabs newsroom.

The Azure MCP (Model Context Protocol) Server enables AI agents and MCP-compatible clients to interact with Azure resources through a standardized protocol. While the default setup works well for local development, production deployments require stronger security guarantees.This article walks through deploying the Azure MCP Server on Azure Container Apps, secured using Azure Active Directory (Entra ID) and Managed Identity, with no client secrets or certificates. Authentication relies entirely on Azure AD token flows and workload identity.Source: GeminiArchitecture OverviewThis deployment consists of four core pieces working together:Azure Container App — Hosts the MCP server as a containerized workload with managed ingress, scaling, and TLS termination.Azure AD App Registration (Service Principal) — Represents the MCP server as a protected API and exposes a custom OAuth scope used by clients.User-Assigned Managed Identity — Allows the MCP server to authenticate itself to Azure AD using a signed assertion, avoiding secrets.Azure CLI (or other MCP clients) — Acts as an OAuth client, requesting access tokens scoped to the MCP server API.Request Flow (High Level)A client authenticates with Azure AD and requests the MCP scope.Azure AD issues an access token containing the MCP scope.The client calls the MCP server with Authorization: Bearer .The MCP server validates the token.The MCP server uses its managed identity to interact with Azure APIs as needed.This design cleanly separates client identity from server identity, while keeping all credentials managed by Azure.Containerizing the Azure MCP ServerThe Azure MCP Server is distributed via the @azure/mcp NPM package, which provides the azmcp CLI used to run the server.DockerfileFROM node:22RUN apt-get update && apt-get install -y --no-install-recommends \ curl ca-certificates apt-transport-https gnupg lsb-release \ libc6 libgcc-s1 libgssapi-krb5-2 libicu72 libssl3 libstdc++6 zlib1g \ && apt-get clean \ && rm -rf /var/lib/apt/lists/*RUN npm install -g @azure/mcp@latest### The env variables can be configured in Container apps instead.ENV ASPNETCORE_ENVIRONMENT=Production \ ASPNETCORE_URLS="http://+:5000" \ AzureAd__Instance="https://login.microsoftonline.com/" \ AzureAd__TenantId="" \ AzureAd__ClientId="" \ AZURE_MCP_DANGEROUSLY_DISABLE_HTTPS_REDIRECTION="true" \ AZURE_MCP_DANGEROUSLY_ENABLE_FORWARDED_HEADERS="true" \ AzureAd__ClientCredentials__0__SourceType="SignedAssertionFromManagedIdentity" \ AzureAd__ClientCredentials__0__ManagedIdentityClientId=""EXPOSE 5000CMD ["azmcp", "server", "start", "--transport", "http", "--read-only"]Why These Settings MatterHTTP instead of HTTPS — Azure Container Apps terminates TLS at the ingress layer. The container itself should listen on HTTP only.Managed Identity assertion flow — SignedAssertionFromManagedIdentity instructs the MCP server to authenticate to Azure AD using the platform-issued identity token rather than a secret.No secrets anywhere — There is no client secret, certificate, or key stored in the container or configuration.Build and push the image to a registry accessible by Container Apps (e.g., Azure Container Registry).Azure AD App Registration (MCP API)The App Registration defines the MCP server as a protected API and controls who can call it.Required ConfigurationRegister a new applicationSave the Application (Client) IDSave the Tenant ID2. Expose an APIApplication ID URI: api://3. Create a custom scope Mcp.Tools.ReadWriteFull scope value: api:///Mcp.Tools.ReadWrite4. Pre-authorize Azure CLIClient ID: 04b07795–8ddb-461a-bbee-02f9e1bf7b46Grant access to Mcp.Tools.ReadWriteThis allows Azure CLI users to request MCP tokens without repeated consent prompts.Do not create a client secret. It is intentionally unnecessary.Managed Identity SetupCreate a User-Assigned Managed Identity:az identity create \ --resource-group \ --name mcpServerIdentityCapture the Client ID of the identity. This value must match AzureAd__ClientCredentials__0__ManagedIdentityClientId.The MCP server uses this identity to authenticate itself to Azure AD using a signed assertion. If the identity is missing or mismatched, authentication will fail at runtime.Deploying to Azure Container AppsDeploy the container and bind the managed identity:az containerapp create \ --name azmcp-server \ --resource-group \ --environment \ --image \ --target-port 5000 \ --ingress external \ --assign-identity Important Notes:Do not override container commands via --args unless you fully control the JSON format. Rely on the Dockerfile CMD.Confirm the managed identity appears under the Container App’s Identity blade.Authenticating with Azure CLILogin and Request MCP Scopeaz login \ --tenant "" \ --scope "api:///Mcp.Tools.ReadWrite" \ --scope "https://management.azure.com/user_impersonation"Fetch Access Tokenaz account get-access-token \ --resource "api://" \ --tenant "" \ --query accessToken \ -o tsvUse this token when calling the MCP server:Authorization: Bearer Admin Consent (One-Time)If required, grant admin consent using a browser flow:$consentUrl = "https://login.microsoftonline.com//oauth2/v2.0/authorize" + "?client_id=" + "&response_type=code" + "&redirect_uri=https://login.microsoftonline.com/common/oauth2/nativeclient" + "&scope=api:///Mcp.Tools.ReadWrite https://management.azure.com/user_impersonation" + "&prompt=consent"Start-Process $consentUrlThis step is required only once per tenant.Using the MCP ServerOnce deployed:Authenticate via Azure CLI or another OAuth client.Obtain an access token with Mcp.Tools.ReadWrite.Call MCP endpoints using standard HTTP requests.The MCP server validates the token and executes operations.The server can operate in read-only or read-write mode depending on startup flags and assigned Azure RBAC roles.npx @modelcontextprotocol/inspector; Source: Screenshot by AuthorCommon PitfallsScope URI mismatch (api:// must match exactly)Managed identity not attached to the Container AppIncorrect identity Client ID in environment variablesMissing admin consentToken requested for the wrong resourceOverriding container startup commands incorrectlyContainer logs are the fastest way to diagnose most failures:az containerapp logs show -n azmcp-server -g --followConclusionThis setup provides:Secretless authentication using Managed IdentityStrong access control via Azure AD scopesA production-ready MCP deployment on Azure Container AppsMinimal operational overhead and clean security boundariesFor internal tooling, automation, and controlled AI integrations in Azure, this pattern is both secure and maintainable — and scales cleanly as MCP adoption grows.Appendix: Using a Client Service Principal (SPN) for MCP AuthenticationIn addition to user- or CLI-based authentication, the Azure MCP Server also supports application-to-application (daemon) access using an Azure AD Service Principal (SPN). This model is ideal for automation, CI/CD pipelines, and non-interactive agents where no user context exists.This approach combines SPN-based client authentication with Managed Identity-based server execution, cleanly separating who can call the MCP server from how the MCP server accesses Azure resources.High-Level Architecture (SPN-Based Client)azmcp-client (Service Principal) └── Uses OAuth 2.0 client_credentials └── Requests application role: Mcp.Tools.ReadWrite.AllAzure MCP Server └── Validates the roles claim in the incoming token └── Authorizes requests based on application rolesManaged Identity (hosting environment) └── Used by the MCP server for outbound Azure callsAzure Resource Manager / Storage └── Accessed using the server's managed identityThis pattern ensures:Clients are authenticated via SPNServer never uses client credentialsAzure access is always performed as the managed identityEntra ID Configuration1. Server Application (azmcp-server)This App Registration represents the MCP server API.Config Value: — Application ID URI api:// — App Role (Application) Mcp.Tools.ReadWrite.All — Allowed member type: Applications — OAuth Scope (Delegated) Mcp.Tools.ReadWrite — for user-based flows onlyServer Service Principal; Source: Screenshot by AuthorThe MCP server authorizes SPN clients by validating the roles claim, not scp.2. Client Application (azmcp-client)This App Registration represents the non-interactive MCP client.Config Value API Permissions azmcp-server → Application → Mcp.Tools.ReadWrite.All Admin Consent ✅ Must be granted Client Secret✅ Required (used only by the client, never by the server)Client App Registration; Source: Screenshot by AuthorMCP Server Container Configuration (SPN-Compatible)The MCP server itself does not use the client SPN. It continues to rely on its hosting environment identity (Managed Identity) for outbound calls.Dockerfile (Server)FROM node:22RUN apt-get update && apt-get install -y --no-install-recommends \ curl ca-certificates apt-transport-https gnupg lsb-release \ libc6 libgcc-s1 libgssapi-krb5-2 libicu72 libssl3 libstdc++6 zlib1g \ && apt-get clean && rm -rf /var/lib/apt/lists/*RUN npm install -g @azure/mcp@latestENV ASPNETCORE_ENVIRONMENT=Production \ ASPNETCORE_URLS="http://+:5000" \ AzureAd__Instance="https://login.microsoftonline.com/" \ AzureAd__TenantId="" \ AzureAd__ClientId="" \ AZURE_MCP_DANGEROUSLY_DISABLE_HTTPS_REDIRECTION="true" \ AZURE_MCP_DANGEROUSLY_ENABLE_FORWARDED_HEADERS="true"EXPOSE 5000CMD ["azmcp", "server", "start", "--transport", "http", "--outgoing-auth-strategy", "UseHostingEnvironmentIdentity", "--read-only", "--debug"]Important Flags ExplainedFlag Purpose UseHostingEnvironmentIdentity Forces all outbound Azure SDK calls to use the container's managed identity AzureAd__ClientId Identifies the MCP server API (used only for token validation) AZURE_CLIENT_ID Identifies the managed identity assigned to the Container AppAcquiring a Token Using Client CredentialsAn SPN client authenticates using the OAuth 2.0 client credentials flow.PowerShell Example$tenantId = ""$clientId = "" # azmcp-client$clientSecret = ""$token = Invoke-RestMethod ` -Method POST ` -Uri "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token" ` -ContentType "application/x-www-form-urlencoded" ` -Body @{ client_id = $clientId client_secret = $clientSecret scope = "api://$clientId/.default" grant_type = "client_credentials" }$accessToken = $token.access_tokenWrite-Host "✅ Token acquired"Key points:.default scope instructs Azure AD to issue application rolesThe resulting token contains a roles claimNo user interaction or consent prompt is involvedAuthorization Model DifferencesWhen using an SPN client, authorization is based on roles (not scp). The MCP server enforces access using Mcp.Tools.ReadWrite.All.This makes SPN authentication ideal for: CI/CD pipelines, scheduled jobs, headless agents, and enterprise integrations.When to Use Each ModelManaged Identity + CLI/User tokensHuman operators involvedFine-grained user auditing required2. SPN client + Managed Identity serverFully automated, no user contextStrong separation of duties requiredBoth models can coexist on the same MCP server.Final NotesThis SPN-based approach completes the MCP security model:Clients authenticate using Azure ADServer validates tokens and rolesAzure access is always performed via Managed IdentityNo secrets are shared across trust boundariesTogether with the Managed Identity-only client flow described earlier, this gives you a production-grade, enterprise-ready authentication strategy for Azure MCP Server deployments.Reference:— Azure-Samples/azmcp-obo-template — mcp/servers/Azure.Mcp.Server at main · microsoft/mcp — mcp/servers/Azure.Mcp.Server/docs/azmcp-commands.md at main · microsoft/mcpDeploying an Azure MCP Server on Azure Container Apps Using Managed Identity was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.