foundry-mcp-auth-whoami-demo
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@foundry-mcp-auth-whoami-demoam I calling as a signed-in user or just an application?"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Foundry MCP auth demo: who does the tool see?
A tiny MCP server with one tool, whoami. It validates a real Microsoft Entra access token and tells
the caller what it sees: a user or only an application. That is the practical difference between
the MCP authentication methods in Microsoft Foundry.
Method in Foundry | What the MCP server sees |
Key based | A shared secret, no person |
Microsoft Entra, agent identity | An application, no person |
Microsoft Entra, project managed identity | An application, no person |
OAuth identity passthrough | The signed in user |
Source for the table: Set up authentication for MCP tools.
Run it locally with Docker (OrbStack) and your az login
az login # once
scripts/try_with_az.sh # builds, starts, calls as your az user, stopsOr step by step:
export TENANT_ID=$(az account show --query tenantId -o tsv)
docker compose up -d --build
uv run scripts/call_whoami.py user # token of your az account, expect callerType "user"
docker compose downFor the application side set AZURE_TENANT_ID, AZURE_CLIENT_ID and AZURE_CLIENT_SECRET of a service
principal you already have and run uv run scripts/call_whoami.py app. Expect callerType application.
Identifiers are masked by default. Set MASK_IDENTIFIERS=false to see full values, and mask them again
before you publish a screenshot.
Related MCP server: mcp-keycloak
Tests
uv run pytestThe tests sign their own tokens, so they need no tenant and no network. They cover missing, garbage, expired, wrong audience, wrong tenant and wrongly signed tokens, plus the user and application cases.
Settings
Variable | Meaning | Default |
| Tenant whose tokens are accepted | required |
| Comma separated accepted | required |
| URL of the MCP endpoint |
|
| Mask ids and user names in the answer |
|
| Host headers to allow when it runs behind a real host name | localhost only |
| Override the key endpoint, for tests | tenant default |
Read this before you reuse it
For the local test the accepted audience is the Azure Resource Manager (
https://management.azure.com), becauseazcan mint that token without an app registration. That is fine for a toy on your laptop. In a real deployment setAUDIENCESto your own API. Never accept tokens that were issued for another service.The Foundry docs say Agent Service blocks Microsoft audience tokens to custom MCP servers (
Cannot pass Microsoft token to untrusted MCP endpoint). Use your own app registration and an audience you control.Agent Service only reaches remote MCP endpoints. To try this server from a Foundry agent, host it on a public HTTPS endpoint such as Azure Container Apps. That is not part of this demo.
The server never logs or returns the token itself.
This server cannot be deployed
Maintenance
Related MCP Connectors
Prove end users to agents and apps: login-links, OIDC clients, and API keys over remote MCP
Remote MCP for A2A caller identity, scope policy, verdict receipts, and audit history.
- StytchOAuthdev.stytch.mcp
The Stytch MCP server is a reference implementation that demonstrates remote MCP server authentication and authorization using Stytch Connected Apps. It provides OAuth 2.1-compliant authorization (including PKCE), Dynamic Client Registration, and validates Stytch-issued access tokens to enable AI agents to securely interact with external services through permissioned access, supporting scopes like openid, email, profile, and manage:project_data.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceImplements the on-behalf-of flow with Entra ID to enable authorized calls to Microsoft Graph API via MCP tools.9-
- FlicenseNot gradedqualityDmaintenanceEnables secure MCP tool calls (add and multiply numbers) by validating OAuth2 tokens via Keycloak token introspection.-
- AlicenseNot gradedqualityCmaintenanceEnables MCP clients to fetch the signed-in Microsoft Entra user's profile from Microsoft Graph via the GET /me endpoint using the provided bearer token.Apache 2.0
- AlicenseNot gradedqualityBmaintenanceEnables MCP clients to exchange an MCP-audience token for a Microsoft Graph token and call Graph as the signed-in user, with tools for identity verification and recent mail access.MIT