About Foundry Agents SDK Demo
Foundry Agents SDK Demo is an MCP server in the Healthcare category: repo for demonstrating custom MCP Tool Governance in Azure AI Foundry.
Install
git clone https://github.com/hashim54/foundry_agents_sdk_demoThis server has no ConduID identity, so agent calls to it are not receipted. Pin the version you install and review the source before granting it credentials.
Ask AI
Ask AI about Foundry Agents SDK Demo
Powered by Claude · Grounded in docs
Security checks
- ✓README presentThe repository ships documentation.
5 checks have not been run yet.
README
Foundry MCP Tool Governance Demo (APIM + Entra OAuth Passthrough)
Use Case
This repository demonstrates user-level governance for custom MCP tools used by Azure AI Foundry agents.
Goal:
- Keep agents and tools in Foundry.
- Use OAuth identity passthrough in the Foundry MCP tool configuration.
- Enforce user/group access in APIM using Entra-issued claims (roles/groups).
Result:
- Foundry agent invokes MCP tool through APIM.
- APIM validates Entra token and required role/group claims.
- Only authorized users can invoke the MCP tool.
End-to-End Architecture
- User signs in and invokes agent.
- Foundry MCP tool uses OAuth passthrough to obtain delegated user token.
- APIM MCP endpoint validates token audience and claims.
- APIM forwards valid calls to backend API/tool implementation.
Prerequisites
- A working API in APIM (already tested independently).
- An MCP server created in APIM from that working API.
- A Foundry project with a deployed model.
- Python 3.10+ and Azure CLI (
az login) for local script execution.
1. Microsoft Entra Configuration
1.1 Create API App Registration (resource API)
- Create app registration, for example
mcp-api-app. - In
Expose an API, set Application ID URI, for exampleapi://<API_APP_CLIENT_ID>. - Add delegated scope
mcp.invoke. - Add app role:
- Display name:
McpInvoke - Value:
McpInvoke - Allowed member types:
Users/Groups - Description:
Allows invoking MCP tools through APIM.
- Display name:
1.2 Create Client App Registration (OAuth client)
- Create app registration, for example
foundry-mcp-client. - In
Authentication, add platformWeb. - Add Foundry-generated redirect URI (from MCP tool OAuth setup flow).
- In
API permissions, add delegated permission toapi://<API_APP_CLIENT_ID>/mcp.invoke. - Grant admin consent if your tenant requires it.
1.3 Enterprise Application Assignments
- Go to
Enterprise applications -> <API app enterprise app> -> Users and groups. - Assign users or groups to role
McpInvoke. - Optional: set
Assignment required = Yeson client enterprise app to control who can use client sign-in.
Expected claims in access token at APIM:
aud = api://<API_APP_CLIENT_ID>rolescontainsMcpInvoke(role-based governance)scpmay includemcp.invoke(delegated scope)
2. APIM Configuration
2.1 Create MCP Server from Existing API
- Start from an already working API in APIM.
- Create MCP server from that API and select tool operations to expose.
2.2 MCP Policy to Enforce Role Assignment
Apply this policy on the MCP endpoint (.../mcp) and keep validation above <base />.
<policies>
<inbound>
<validate-azure-ad-token tenant-id="<TENANT_ID>">
<audiences>
<audience>api://<API_APP_CLIENT_ID></audience>
</audiences>
<required-claims>
<claim name="roles">
<value>McpInvoke</value>
</claim>
</required-claims>
</validate-azure-ad-token>
<base />
</inbound>
<backend><base /></backend>
<outbound><base /></outbound>
<on-error><base /></on-error>
</policies>
Important:
- Keep MCP endpoint policy minimal. Avoid request/response rewrites on MCP route.
- Keep backend routing/transforms on the underlying API operations, not on MCP route.
- If testing auth behavior, disable subscription enforcement everywhere unless intentionally used.
3. Foundry Tool and Agent Setup
3.1 Create Custom MCP Tool in Foundry
- In Foundry project, add custom MCP tool.
- Set server URL to APIM MCP endpoint, for example
https://<apim-name>.azure-api.net/<mcp-server-name>/mcp. - Configure
OAuth identity passthrough. - Provide OAuth client/API settings (from Entra apps):
- Client ID:
<CLIENT_APP_CLIENT_ID> - Client Secret:
<CLIENT_APP_CLIENT_SECRET_VALUE> - Scope:
api://<API_APP_CLIENT_ID>/mcp.invoke - Authorize URL:
https://login.microsoftonline.com/<TENANT_ID>/oauth2/v2.0/authorize - Token URL:
https://login.microsoftonline.com/<TENANT_ID>/oauth2/v2.0/token - Refresh URL:
https://login.microsoftonline.com/<TENANT_ID>/oauth2/v2.0/token
- Client ID:
- Complete consent flow and confirm tool connectivity.
3.2 Create Agent in Foundry
- Create a Foundry agent in the same project.
- Attach the MCP tool created above.
- Save and use this agent reference for runtime invocation.
4. Using create_and_run.py for OAuth Passthrough Agents
File: scenario2_foundry_hosted_agent/create_and_run.py
4.1 Prepare Environment
- Copy
.env.exampleto.env. - Set:
FOUNDRY_PROJECT_ENDPOINTFOUNDRY_MODEL_DEPLOYMENT_NAMEFOUNDRY_EXISTING_AGENT_REFERENCE=<agent-name>:<version>FOUNDRY_MCP_SERVER_LABELFORCED_TOOL_QUERYOPEN_OAUTH_CONSENT_IN_BROWSER=true|false
4.2 Install Dependencies
python -m venv .venv
.venv\Scripts\activate
pip install -r requirements.txt
4.3 Run
python scenario2_foundry_hosted_agent/create_and_run.py
4.4 Runtime Behavior
- Uses
DefaultAzureCredential(youraz loginuser) for agent invocation. - Invokes existing agent reference.
- Detects
oauth_consent_request; prints consent URL and can open browser when enabled. - Auto-approves
mcp_approval_requestand continues run. - Writes full payload to
scenario2_foundry_hosted_agent/runtime_response_debug.json.
Optional: Script-Based Agent Creation
The script currently defaults to invoking an existing agent.
There is a commented scaffold in main() for service-principal-based agent creation with MCP tool attachment:
- Set SP values in
.env(FOUNDRY_SP_TENANT_ID,FOUNDRY_SP_CLIENT_ID,FOUNDRY_SP_CLIENT_SECRET). - Uncomment the SP creation block in
main(). - If using script creation, agent creation in Foundry portal can be skipped.
Files
scenario2_foundry_hosted_agent/create_and_run.py.env.examplerequirements.txt
README copy captured when this server was indexed; it may lag the repository. The original is authoritative.