Microsoft Foundry with Managed Identity consuming a MCP Server protected by Microsoft Entra ID #437
Talles Destefani de Souza Valiattti (TallesValiatti)
started this conversation in
Show and Tell
Replies: 1 comment
|
I am not able to do this for a Hosted Agent. My Project User Assigned Managed identity has access to call the MCP server when I am trying to explicitly use the project UAMI from inside the Hosted Agent: Invalid clientId. It should match either the AgentIdentityId or AgentBlueprintId. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Introduction
Hello everyone 👋
I recently published an article showing how to protect a custom Model Context Protocol (MCP) server built with .NET using Microsoft Entra ID, so that only one specific Microsoft Foundry project identity is allowed to call it. Microsoft Foundry is at the center of the scenario: the agent lives in the Foundry Agent Service, and the MCP Server is connected as a tool using the Project Managed Identity authentication mode, where Foundry itself obtains an app-only token and presents it on every call.
The demo server,
Books.Mcp, exposes book CRUD tools. On the API side, the authorization policy checks that the incoming token is app-only (oidequalssub), that the tenant matches, and that the object id is exactly the Foundry project identity. Any other caller in the same tenant gets rejected. The article walks through the App Registration, the Application ID URI, the ASP.NET Core authentication and authorization wiring, the deployment to Azure App Service, and the end-to-end test in the Foundry sandbox.The article is available here:
https://www.azurebrasil.cloud/blog/microsoft-foundry-com-managed-identity-consumindo-um-mcp-server-protegido-pelo-microsoft-entra-id/
The post is written in pt-BR, since it was aimed at my local community here in Brazil 🇧🇷, but it translates easily to en-US. It is meant for developers who need to expose sensitive MCP tools to a Foundry agent with strong, identity-based access control instead of shared secrets or open endpoints.
Features and Screenshots
Technical Details
Challenges and Solutions
Challenges and Solutions
The hard part was not exposing the MCP tools, it was proving that a request really came from the Foundry project and from nowhere else. A valid token from the same tenant is not enough, so the policy validates three things together: that
oidandsubare equal, which is what identifies an app-only token instead of a delegated user token; thattidmatches the configured tenant; and thatoidmatches the Foundry project identity's object id. Only when all three hold does the/mcpendpoint accept the call.I also had to decide between Project Managed Identity and OAuth identity passthrough. Passthrough is the right answer when the agent must act on behalf of the end user and inherit their permissions. Here the agent represents the application itself, so app-only tokens with an ACL-style check on the object id were the more direct path, and
AllowWebApiToBeAuthorizedByACLlet me skip app roles entirely for a single trusted caller. RestrictingValidAudiencesto the client id and theapi://<client-id>URI, and keeping/healthanonymous while the MCP endpoint stays behind the policy, kept the whole thing simple to deploy and easy to reason about.All reactions