Secure access to MCP servers in API Management

By using MCP server support in API Management, you can expose and govern access to MCP servers and their tools. This article describes how to secure access to MCP servers managed in API Management, including both MCP servers exposed from managed REST APIs and existing MCP servers hosted outside of API Management.

You can secure either or both inbound access to the MCP server (from an MCP client to API Management) and outbound access (from API Management to the MCP server).

Secure inbound access

Key-based authentication

If the MCP server is protected with an API Management subscription key passed in the Ocp-Apim-Subscription-Key header, MCP clients can present the key in incoming requests, and API Management validates the key. For example, in Visual Studio Code, you can add a headers section to the MCP server configuration to include the subscription key in request headers:

{
  "name": "My MCP Server",
  "type": "remote",
  "url": "https://my-api-management-instance.azure-api.cn/my-mcp-server",    
  "transport": "streamable-http",
  "headers": {
    "Ocp-Apim-Subscription-Key": "<subscription-key>"
  }
}

Note

Securely manage subscription keys by using Visual Studio Code workspace settings or secure inputs.

Token-based authentication (OAuth 2.1 with Microsoft Entra ID)

MCP clients can present OAuth tokens or JWTs issued by Microsoft Entra ID by using an Authorization header and validated by API Management.

For example, use the validate-azure-ad-token policy to validate Microsoft Entra ID tokens:

<validate-azure-ad-token tenant-id="your-entra-tenant-id" header-name="Authorization" failed-validation-httpcode="401" failed-validation-error-message="Unauthorized. Access token is missing or invalid.">     
    <client-application-ids>
        <application-id>your-client-application-id</application-id>
    </client-application-ids> 
</validate-azure-ad-token>

Forward tokens to backend

Request headers are automatically forwarded (with certain exclusions) to MCP tool invocations. This feature simplifies integration with downstream APIs that rely on headers for routing, context, or authentication.

If you need to explicitly forward the Authorization header to validate incoming requests, use one of the following approaches:

  • Explicitly define Authorization as a required header in the API settings and forward the header in the Outbound policy.

    Example policy snippet:

    <!-- Forward Authorization header to backend --> 
    <set-header name="Authorization" exists-action="override"> 
        <value>@(context.Request.Headers.GetValueOrDefault("Authorization"))</value> 
    </set-header> 
    
  • Use API Management credential manager and policies (get-authorization-context, set-header) to securely forward the token. To learn more, see Secure outbound access.

For more inbound authorization options and samples, see: