You already have REST APIs that do useful things. Now your AI agents need to call them as MCP (Model Context Protocol) tools. You could write and host a new MCP server for each API, or you could let Azure API Management (APIM) do it for you, with the security, throttling and observability you already get from a gateway.
This post walks through the APIM approach end to end: exposing operations as MCP tools, locking the MCP endpoint down with Microsoft Entra ID, and letting callers authenticate with either an agent-level identity or the project-level identity of your Microsoft Foundry project.
Why APIM for MCP?
- No new server to build or host. APIM turns operations of an existing API into MCP tools.
- One front door. Auth, rate limits, logging and IP rules apply to MCP traffic the same way they do for every other API.
- Selective exposure. You choose which operations become tools, so an agent never sees your whole API surface.
- Entra-native security. Callers present an Entra token, and APIM validates it before anything reaches your backend.
Roles you need
You do not need separate teams for this setup. You need the following roles, held by one person or several.
| Task | Role required |
|---|---|
| Create the app registration, app role and Application ID URI (Step 2) | Entra role: Application Administrator, Cloud Application Administrator, or Application Developer (the creator becomes the app owner) |
| Assign the app role to the agent or project identity (Step 5) | Entra role: Application Administrator or Cloud Application Administrator. For automation, the Microsoft Graph permission AppRoleAssignment.ReadWrite.All
|
| Create the MCP server and add the policy in APIM (Steps 1 and 3) | Azure RBAC: API Management Service Contributor on the APIM instance |
| Add the MCP tool and pick the identity in Foundry (Step 6) | Azure RBAC: Contributor (or the Foundry project management role your organization uses) on the Foundry project |
Role names change over time, so confirm them against the current documentation for your tenant.
Architecture at a glance
Agent --> MCP Tools --> MCP Server --> APIM --> External API
- The agent picks an MCP tool and calls it.
- The agent gets an Entra token for the APIM app (the audience), using its agent identity or the project identity.
- The call reaches the MCP server exposed by APIM, with the token as a Bearer header.
- APIM validates the token and the
MCP.Accessrole, then calls the external API.
Step 1: Expose your API operations as an MCP server
In the Azure portal, open your APIM instance and go to APIs > MCP Servers (the exact blade name may shift while the feature evolves). Create an MCP server from an existing API, then pick only the operations you want as tools. Each selected operation becomes one tool, with its name, description and parameters derived from your OpenAPI definition.
Tip: good tool descriptions matter more than you think. The model chooses tools based on them, so tidy up operation summaries and parameter descriptions in your OpenAPI spec before you expose them.
Step 2: Create the Entra app registration (the resource app)
This app registration represents the APIM MCP server as a protected resource. Callers request tokens for this app. The roles you need for each step are listed in "Roles you need" above.
2.1 Register the app
- Go to Microsoft Entra ID > App registrations > + New registration.
- Name:
apim-mcp-server(or your preferred name). Supported account types: Single tenant. Leave Redirect URI blank. Click Register.
2.2 Set the token version to v2
- Open the app > Manifest.
- Set
requestedAccessTokenVersionto2(underapi). In the older manifest format the property isaccessTokenAcceptedVersion. - Click Save.
2.3 Set the Application ID URI
- Go to Expose an API > Add next to Application ID URI.
- Accept the default
api://<client-id>and Save.
2.4 Create the app role
Go to App roles > Create app role and fill in:
| Field | Value |
|---|---|
| Display name | MCP.Access |
| Allowed member types | Applications |
| Value | MCP.Access |
| Description | Allows authorized Microsoft Foundry identities to invoke MCP server endpoints in APIM. |
| Enable this app role | Checked |
Choosing Applications as the member type matters. It makes this an application permission, meaning only non-human identities (agents, managed identities) can be granted it. No user can sign in and get it.
2.5 Collect four values for the APIM configuration
| Value | Where to find it |
|---|---|
| Tenant ID | App Overview page |
| Client ID | App Overview page |
| Application ID URI | Expose an API page |
| App Role ID |
Manifest > appRoles > the id of MCP.Access
|
Step 3: Validate the token in APIM
Add a validate-jwt policy on the MCP server so that only tokens carrying the MCP.Access role get through:
<inbound>
<base />
<validate-jwt header-name="Authorization"
failed-validation-httpcode="401"
failed-validation-error-message="Unauthorized">
<openid-config url="https://login.microsoftonline.com/{tenant-id}/v2.0/.well-known/openid-configuration" />
<audiences>
<audience>{client-id}</audience>
</audiences>
<issuers>
<issuer>https://login.microsoftonline.com/{tenant-id}/v2.0</issuer>
</issuers>
<required-claims>
<claim name="roles" match="any">
<value>MCP.Access</value>
</claim>
</required-claims>
</validate-jwt>
</inbound>
Two details that trip people up:
-
Audience. Because we set the token version to 2, the
audclaim in the token is the app's client ID, not theapi://...URI. The caller requests the token using the Application ID URI as the scope or resource, but APIM validates against the client ID. -
Issuer. v2 tokens use the
.../{tenant-id}/v2.0issuer. If you left the token version at 1, the issuer and audience would not match this policy, which is why Step 2.2 is not optional.
Step 4: Decide which identity calls the MCP server
This is where the design choice sits. A Foundry agent can authenticate to your APIM MCP endpoint using Entra in two ways, and your app role works with both.
| Agent identity | Project-level identity | |
|---|---|---|
| What it is | A dedicated Entra identity for an individual agent | The managed identity of the Foundry project, shared by everything in that project |
| Granularity | Per agent | Per project |
| Role assignment | One assignment per agent | One assignment covers every agent in the project |
| Audit trail | Token shows which agent called | Token shows the project, not the individual agent |
| Least privilege | Strongest. Each agent only gets the tools you grant it | Coarser. Every agent in the project inherits access |
| Good fit | Production agents with different access needs | Dev/test projects, or projects where all agents legitimately need the same tools |
A practical rule of thumb:
- Start with the project-level identity when you are prototyping, or when a project is dedicated to a single use case. It is one role assignment and you are done.
- Move to agent identity when agents in the same project should not all have the same reach, or when you need per-agent attribution in your logs.
Note that Foundry's identity model has been evolving, including when an agent gets its own distinct identity versus using the project's. Check the current Foundry documentation for how your agents are being identified before you decide.
Step 5: Assign the app role to the identity
Once the agent or project exists in Foundry, grab the Object ID of the identity (the agent identity's service principal, or the project's managed identity) and assign the MCP.Access role to it.
This is an app role assignment on the resource's enterprise application (service principal), not a setting in the app registration blade. The Entra portal does not offer it for agent identities, and may not for the project identity either, so use Microsoft Graph through Graph Explorer, PowerShell or the Azure CLI. All three call the same API.
Sign in to the right tenant first
Yes, sign in to the tenant even though the identities you are assigning are applications. The assignment is a write to your directory, so it must be made by a signed-in principal (you, or a pipeline identity) in the same tenant as the apim-mcp-server app. The app registration is single tenant, so a session in another tenant cannot see it. Each option below shows its own sign-in step.
The most common mistake
Using the app registration's object ID as resourceId. It must be the object ID of the enterprise application with the same name. You need three values for every option:
-
resourceId: object ID of theapim-mcp-serverenterprise application -
principalId: object ID of the agent identity or the Foundry project's managed identity -
appRoleId: the App Role ID collected in Step 2.5
Run the assignment once for the project identity, once per agent identity, or both.
Option A: Graph Explorer
- Open Graph Explorer and sign in with an account in the tenant from Step 2.5 (use the tenant switcher if you belong to several).
- Under Modify permissions, consent to
AppRoleAssignment.ReadWrite.AllandApplication.Read.All. - Set the method to
POSTand the URL tohttps://graph.microsoft.com/v1.0/servicePrincipals/{resource-sp-object-id}/appRoleAssignedTo. - Paste this request body and run it:
{
"principalId": "<agent-or-project-identity-object-id>",
"resourceId": "<resource-sp-object-id>",
"appRoleId": "<mcp-access-role-id>"
}
A 201 Created response means the role is assigned. If the v1.0 endpoint does not resolve an agent identity as principalId, try the same call on the beta endpoint.
Option B: PowerShell
Connect-MgGraph -TenantId "<tenant-id>" -Scopes "AppRoleAssignment.ReadWrite.All","Application.Read.All"
$resourceSpId = "<resource-sp-object-id>" # enterprise app of apim-mcp-server
$principalId = "<agent-or-project-identity-object-id>"
$appRoleId = "<mcp-access-role-id>"
New-MgServicePrincipalAppRoleAssignedTo `
-ServicePrincipalId $resourceSpId `
-PrincipalId $principalId `
-ResourceId $resourceSpId `
-AppRoleId $appRoleId
This needs the Microsoft Graph PowerShell module (Install-Module Microsoft.Graph). Connect-MgGraph -TenantId is the sign-in-to-the-right-tenant step for this option.
Option C: Azure CLI
az login --tenant <tenant-id> --allow-no-subscriptions
RESOURCE_SP_ID=<apim-mcp-server-enterprise-app-object-id>
PRINCIPAL_ID=<agent-or-project-identity-object-id>
APP_ROLE_ID=<mcp-access-role-id>
az rest --method POST \
--uri "https://graph.microsoft.com/v1.0/servicePrincipals/$RESOURCE_SP_ID/appRoleAssignedTo" \
--body "{\"principalId\":\"$PRINCIPAL_ID\",\"resourceId\":\"$RESOURCE_SP_ID\",\"appRoleId\":\"$APP_ROLE_ID\"}"
Use --allow-no-subscriptions if your account has directory access but no Azure subscription.
Step 6: Connect the agent to the MCP server
In Foundry, add the APIM MCP endpoint as a tool for your agent (via a project connection to the MCP server) and choose Microsoft Entra as the authentication type. You then pick whether the token comes from the agent identity or the project managed identity, and supply the Application ID URI as the audience.
The flow at runtime:
- The agent decides to call a tool.
- Foundry gets an Entra token for
api://<client-id>using the chosen identity. - The token carries
roles: ["MCP.Access"]. - APIM validates it and forwards the call to your backend API.
Troubleshooting
| Symptom | Likely cause |
|---|---|
401 from APIM |
Wrong audience (use client ID for v2 tokens), wrong issuer, or token version left at 1 |
401 and the token has no roles claim |
The role was never assigned to that identity, or it was assigned to the app registration object ID instead of the enterprise app |
| Works for one agent but not another | You assigned the role to an agent identity, not the project identity (or vice versa) |
| Role assignment fails | The app role's allowed member type is not Applications |
Wrapping up
The APIM approach gives you MCP tools without building MCP servers, and Entra gives you a clean authorization story: one resource app, one MCP.Access role, and a choice between project-level simplicity and agent-level precision for who gets to hold it.
The whole setup comes down to the roles in the table above. Whoever holds them can run every step, and the four values in Step 2.5 are all you need to carry between steps.
Have you exposed APIs as MCP tools through APIM? I would love to hear which identity model you picked and why.
References
- Expose a REST API in API Management as an MCP server
- MCP server overview in API Management
- Secure access to MCP servers in API Management
- validate-jwt policy
- MCP authentication in Microsoft Foundry agents
- Agent identity in Microsoft Foundry
- Add app roles to an application
- Grant an appRoleAssignment to a service principal (Microsoft Graph)
- Model Context Protocol



Top comments (0)