Part 2 of a two-part series. In Part 1 we built a VM inventory MCP server in Python and tested it locally. Now we take it live: host it on Azure Container Apps, give it a read-only managed identity, plug it into a Copilot Studio agent, and lock it down with Microsoft Entra ID. By Babulal Ghule — Cloud Solution Architect, Microsoft
Welcome back. In Part 1 we learned what an MCP server is and built a real one — a VM inventory tool that reads your Azure estate with Azure Resource Graph and reports it by region and availability zone — then tested it on our own machine. If you haven’t read Part 1, start there; this part assumes you already have the server running locally. Here we make it something the whole team can use.
Quick recap — Our server is two small files: server.py (creates the MCP server and exposes one tool, get_vm_inventory) and vmcp.py (the Azure Resource Graph logic). It runs with python server.py and serves at /mcp. That is everything we ship to the cloud below.
1. Take it to the cloud: Azure Container Apps
Running on your laptop is great for learning, but a real MCP server needs to be reachable and always on — and Copilot Studio, which runs in the cloud, can’t reach http://localhost at all. Azure Container Apps (ACA) is a perfect home: it runs your container for you, gives you an HTTPS address automatically, and scales on demand.
Add a Dockerfile
A “container” is just your app plus everything it needs, packed into one tidy box that runs the same everywhere. This one serves on port 8000.
📂 Source Code
All code samples, scripts, and configuration files used in this article are available in the GitHub repository below. Feel free to clone the repository, explore the code, and adapt it for your own environment.
GitHub: [GitHub Repository Link]
Dockerfile
Deploy with a few commands
The az acr build command even builds the container in the cloud, so you don’t need Docker installed. Run these from inside the project folder (replace the names and subscription with your own):
terminal (Azure CLI)
az login
az account set --subscription "<your-subscription-id>"
az group create -n mcp-demo-rg -l centralindia
az acr create -g mcp-demo-rg -n vminventoryacr --sku Basic
# build the image from THIS folder
az acr build -r vminventoryacr -t vm-inventory:v1 .
# deploy to Azure Container Apps (serves on port 8000)
az containerapp up -n vm-inventory-mcp -g mcp-demo-rg \
--environment vm-inventory-env \
--image vminventoryacr.azurecr.io/vm-inventory:v1 \
--registry-server vminventoryacr.azurecr.io \
--ingress external --target-port 8000
The deploy prints a URL — your MCP endpoint is that URL plus /mcp. Keep one instance warm so the first request after a quiet spell doesn’t wait for a cold start:
terminal (Azure CLI)
az containerapp update -n vm-inventory-mcp -g mcp-demo-rg --min-replicas 1
Confirm it’s alive (the health check needs no auth):
terminal
curl https://<your-app-fqdn>/health # -> {"status":"healthy"}
Already deployed but a command says “does not exist”? — The app name and resource group must match exactly. List everything with: az containerapp list -o table. Use the real name and resource group from that output in the commands below — a mismatched -g is the usual cause.
2. Give it a read-only managed identity (no secrets)
Here’s the important part. On your laptop the server signed in with your az login. In the cloud it should not use any password or key — instead it uses a managed identity: an identity that Azure creates and manages for the app. There is nothing to store, nothing to rotate, and nothing to leak. Our server.py already detects it automatically, so you don’t change a single line of code.
Figure 6 — In the cloud the server authenticates with a managed identity (no secrets); locally it uses your az login. Same code, both places.Turn on a system-assigned identity and grant it the read-only Reader role on each subscription you want it to inventory. Reader is all it needs — it lists resources, it never changes them.
terminal (Azure CLI)
az containerapp identity assign -n vm-inventory-mcp -g mcp-demo-rg --system-assigned
$PRINCIPAL=$(az containerapp identity show -n vm-inventory-mcp -g mcp-demo-rg \
--query principalId -o tsv)
az role assignment create --assignee $PRINCIPAL --role Reader \
--scope /subscriptions/<your-subscription-id>
How the code chooses — server.py checks for the IDENTITY_ENDPOINT environment variable (Azure sets it inside the container). If present, it uses ManagedIdentityCredential; otherwise it falls back to DefaultAzureCredential (your az login). For a user-assigned identity, also set the AZURE_CLIENT_ID environment variable to that identity’s client id. Role assignments take about a minute to propagate — if the first call says “authorization failed,” wait and retry.
3. Plug it into a Copilot Studio agent
Copilot Studio lets you build your own agents for Teams, websites, and more — no heavy coding required. You connect an MCP server through the Model Context Protocol tool type. Open your agent, go to Tools → Add a tool → Model Context Protocol, and fill in the dialog.
|
Field |
What to enter |
|
Server name |
VM Inventory |
|
Server description |
Read-only Azure VM capacity tool. Returns a region- and availability-zone-wise inventory of virtual machines and VM Scale Sets, with SKU counts, across one or more Azure subscriptions. Backed by Azure Resource Graph. It never creates, changes, or deletes resources. |
|
Server URL (streamable endpoint) |
https://<your-app-fqdn>/mcp |
|
Authentication |
OAuth 2.0 for an Entra-secured app (client id + scope api://<APP_ID>/access_as_user), or No authentication for an unsecured test app. |
After you save, Copilot Studio reads the tool list from the server. Confirm get_vm_inventory appears and is enabled. Then paste a short instruction into the agent’s Instructions box so it knows how to use the tool:
Agent instructions
You are the Azure VM Inventory assistant. You help users see what VMs and
VM Scale Sets are deployed across their Azure subscriptions, by region and zone.
- Use the get_vm_inventory tool whenever the user asks what they run, how many,
in which region, or in which zone. It takes a list of subscription IDs (GUIDs).
- If no subscription is given, ask for it. Never invent a subscription ID.
- Prefer the aggregates for summaries; show a small Region | Zone | SKU | Count table.
- This tool is READ-ONLY. If asked to change resources, say it only reports inventory.
- On an error (bad ID or missing Reader), explain it plainly; don't show raw stack traces.
Why this is powerful — Once connected, your VM inventory server can power a Teams chatbot the whole company uses — anyone can ask “what are we running in East US?” without opening the portal. You built the capability once; Copilot Studio handles the conversation.
https://<your-app-fqdn>/mcp
4. Secure it with Microsoft Entra ID
A public MCP server can act on real systems, so an unprotected one is an open door. There are two layers of security here, and they do different jobs. The managed identity from Section 2 controls what the server can do to Azure (read-only). Microsoft Entra ID authentication, below, controls who is allowed to call the server in the first place.
The idea in one sentence: the AI client must prove who it is with a token before your server will do anything. This is the industry-standard OAuth approach, and Azure Container Apps has it built in — you can switch it on without changing your server code.
Figure 7 — With Entra ID, only requests carrying a valid token ever reach your tool. Everything else is turned away at the door.
In four moves: register your server as an app in Microsoft Entra ID and expose a scope (a named permission like access_as_user); turn on built-in authentication on the Container App and set the “no token” behaviour to return 401; the client obtains a token from Entra ID and sends it on every call in the Authorization: Bearer header; and, optionally, using the On-Behalf-Of flow your server can act as the signed-in person so they only see what they’re allowed to.
Test the secured cloud server
The kit’s test_cloud.py is the same as the local tester plus one thing: a bearer token on every request. Get a token for your app’s API scope, store it in an environment variable, and run the test against your deployed URL:
terminal (PowerShell)
$env:MCP_TOKEN = az account get-access-token --resource api://<APP_ID> --query accessToken -o tsv
$env:AZURE_SUBSCRIPTION_IDS = "<your-subscription-id>"
python test_cloud.py https://<your-app-fqdn>/mcp
With a valid token it lists the tool and returns inventory, exactly like the local run. Remove the token (or let it expire) and the call comes back as 401 Unauthorized — which is precisely the proof that your Entra ID protection is switched on and working.
A very common mix-up — If you get a stubborn 401, check that your client’s auth style matches your hosting model. A bearer token is for a standalone container app with built-in auth; an API-key header is for the platform-managed “dynamic sessions” option. Sending the wrong one is the classic reason a “correct” token still gets rejected.
The golden security rules
- Never trust tool inputs. Everything the AI passes in is arbitrary text — validate it. In Python, Pydantic makes this easy.
- Least privilege. Grant only what’s needed — for our tool that’s read-only Reader, nothing more. Avoid destructive actions that run without a confirmation step.
- Prefer managed identity. It means no keys or connection strings in your image at all. Where a secret is unavoidable, keep it in Azure Key Vault or Container Apps secrets.
- Watch for prompt injection. A malicious message (even hidden in a document the AI reads) can try to trick the agent into misusing your tools. Assume it will happen and design guardrails.
- Log everything, and only trust servers you know. Record which tool ran, by whom, and when; connect agents only to servers you or your organisation control and have reviewed.
- Common problems people hit (and how to avoid them)
I researched what actually trips people up in the real world — and hit a few of these myself. Learn from them and you’ll skip a lot of frustration.
|
The trap |
What goes wrong |
How to avoid it |
|
Pointing Copilot Studio at localhost |
The agent says the tool is “unavailable” because the cloud can’t reach your laptop. |
Use the deployed HTTPS URL ending in /mcp — never http://localhost. |
|
Wrong Python version |
pip install fails and you get “No module named mcp.server.fastmcp.” |
Use Python 3.11 or 3.12; recreate the venv with py -3.12 if you’re on 3.13/3.14. |
|
Library installed but not seen |
“azure-mgmt-resourcegraph is not installed” even after installing it. |
Install into the SAME venv, then RESTART the server — a running server won’t see new packages. |
|
Missing Reader permission |
The inventory is empty or the call errors on authorization. |
Grant Reader on each subscription — to your user locally, to the managed identity in the cloud. |
|
Wrong resource group |
“The containerapp does not exist” even though it does. |
Run az containerapp list -o table and use the exact name and -g resource group it shows. |
|
Cold starts |
The first request after idle time hangs while the cloud spins up an instance. |
Set --min-replicas 1 to keep one instance always ready. |
|
Auth style mismatch |
A “correct” token still returns 401. |
Bearer token for a standalone app; API key for dynamic sessions — match the hosting model. |
Figure 8 — The finished production shape: your MCP server on Azure Container Apps, guarded by Entra ID, reading Azure with a managed identity.
My first-place debugging tip — When something misbehaves, start with the logs. Send your server’s logs to stderr (or use Azure Monitor in the cloud) and watch exactly which tool was called with which inputs. Nine times out of ten the answer is right there.
6. Ideas to spark your innovation
Once you can wrap any system as an MCP server, the ceiling disappears. A few starting points:
- Cloud & Infrastructure: extend the inventory tool to report unattached disks, public IPs, or a monthly cost breakdown by region.
- Sales: “What’s the status of the Contoso deal?” — a server over your CRM that answers in seconds.
- HR: “How many leave days do I have left?” — a server that safely reads each employee’s own balance.
- Operations: live inventory checks, order look-ups, or shipment tracking, all through natural conversation.
- Data & reporting: let non-technical teammates ask questions of a database in plain English, with your server enforcing safe, read-only queries.
The pattern is always the same: pick a system people keep asking about, expose a few safe tools, and let the AI handle the conversation. Start small, ship it, and iterate.
Wrapping up the series: keep learning, keep sharing
Look how far we’ve come. In Part 1 we learned what an MCP server is and built a real one in Python. In Part 2 we deployed it to Azure Container Apps, gave it a read-only managed identity with no secrets, connected it to a Copilot Studio agent, secured it with Microsoft Entra ID, and learned the traps that catch most people. That’s a complete, production-shaped journey — from an idea to a tool your whole team can talk to.
If there is one thing I hope you take away, it is this: an AI agent “unplugged” is only half the story. MCP is what plugs it into your world — and the barrier to building that connection is now low enough for anyone to cross. So pick one small system this week and give your assistant a new superpower.
Your turn — Build the VM inventory server, deploy it, connect it to Copilot Studio, and tell me in the comments what you’d automate first. If this series helped, share it with a colleague who’s curious about AI agents. We grow faster when we learn out loud — keep learning, keep sharing.
References & further reading
- Host MCP servers on Azure Container Apps: https://learn.microsoft.com/en-us/azure/container-apps/mcp-overview
- Secure MCP servers on Azure Container Apps (Microsoft Entra ID): https://learn.microsoft.com/en-us/azure/container-apps/mcp-authentication
- Connect your Copilot Studio agent to an existing MCP server: https://learn.microsoft.com/en-us/microsoft-copilot-studio/mcp-add-existing-server-to-agent
- Managed identities in Azure Container Apps: https://learn.microsoft.com/en-us/azure/container-apps/managed-identity
- Azure Resource Graph documentation: https://learn.microsoft.com/en-us/azure/governance/resource-graph/
About the author: Babulal Ghule is a Cloud Solution Architect at Microsoft India. He enjoys turning complex cloud and AI topics into simple, hands-on guides that anyone can follow. Thanks for reading Parts 1 and 2 — if you build something with MCP, I’d love to hear about it.