Every month someone asks me the same two questions: "Why is Azure up, and who owns it?" The first answer sits in Cost Management. The second is buried in a budget-alert email, a Teams thread, or someone's memory. I wanted one prompt that could answer both.
This isn't a feature tour. It's a real build in our Foetron tenant: a small MCP server, a Cowork plugin, and Work IQ working together. It includes the seven things that broke before the first successful run.

Cost Analysis for the demo subscription
1. Why Cowork, why now
Copilot Cowork is the agentic mode of Microsoft 365 Copilot. You describe an outcome, and it plans steps, calls tools, works in the background and asks before it changes anything. Two things made it the right host:
- Work IQ is already there. Cowork grounds itself in your mail, chats, meetings and files. I didn't have to build the "context" half.
- Plugins accept remote MCP servers. A Cowork plugin bundles skills (Markdown instructions) and connectors (remote MCP servers over Streamable HTTP). Cost data was the missing connector.
2. What I set out to build
One prompt, "Run my weekly Azure cost review… find who owns the top spenders… draft an email to the owners", should return:
- Month-to-date spend and the projected month-end total for each subscription.
- The top resource groups by cost.
- The owner of each top spender, found by Work IQ in mail and Teams, plus any budget alerts.
- A draft email to those owners that I decide whether to send.
Constraints: read-only, an allow-list of subscriptions, and no secrets inside the plugin.
3. Architecture
Cowork prompt → Skill (azure-cost-review/SKILL.md) → Azure Cost MCP connector (Container Apps, Streamable HTTP, Entra token) → Cost Management Query & Forecast APIs and in parallel → Work IQ (mail, Teams, People) → summary table + Outlook draft (approval before send)
Two identities do two different jobs:
- Inbound (user to server): Cowork gets an Entra token for my API app,
azure-cost-mcp, with aCosts.Readscope, through the plugin vault. The server validates that token. - Outbound (server to Azure): the Container App's system-assigned managed identity calls Cost Management. It has Cost Management Reader on two subscriptions and nothing else.
4. Walkthrough
4.1 The MCP server (Python, about 200 lines)
Four tools, all read-only:
get_costs, get_forecast, top_spenders and list_scopes. They share one helper for Cost Management calls:Two details mattered more than I expected:
The tool does the arithmetic itself, so the model never adds up raw rows. The
note field turned out to be useful, as you'll see in the results. _scope() rejects any subscription that isn't in ALLOWED_SCOPES.4.2 Inbound auth
Cowork connectors don't support API keys yet, so the server validates an Entra v2 token in a Starlette middleware:

Entra app with Costs.Read scope
4.3 Deploy
4.4 OAuth registration for the plugin vault
In the Teams Developer Portal (Tools → OAuth client registration), I registered the Entra endpoints, client ID and secret, and the scope
api://<app-id>/Costs.Read offline_access. I also added https://teams.microsoft.com/api/platform/v1.0/oAuthRedirect as a redirect URI on the Entra app. The registration ID it generates becomes referenceId in the manifest.
OAuth client registration
4.5 The plugin package
The skill is plain Markdown. This is the part that tells Cowork when to switch from cost data to Work IQ:
Upload is Plugins → Cowork → Add → Upload, shared with Only you:

Publish to only you

Plugin added
4.6 The run

Cowork plan with Azure Cost and Work IQ
list_scopes, hits the Cost Management throttle, and runs Work IQ searches of my mail and Teams while it waits.After about a minute and a half:

Forecast table

Owners table

Follow-ups and draft
A few things in that output impressed me:
- It used my
notefield. For the cancelled subscription, it said there was "no real forecast" and treated the actual spend as the minimum for the month. It didn't invent a projection. - It caught a mismatch. The budget email said 80%, but the live figure was 76.6%, and it worked out that the alert was older.
- It noticed a gap in my tool. It said it couldn't break down one resource group by service, because
get_costshas no filter parameter. That's going into v2. - It was honest about missing owners. For the second subscription it reported "Not found" instead of guessing.
5. The seven flaws I hit (the honest bit)
Flaw 1: The MCP Python SDK moved under me
My first container crashed on
from mcp.server.fastmcp import FastMCP. mcp 2.x renamed it to MCPServer. I pinned mcp>=1.9,<2 for now. If you copy older samples, check the major version first.Flaw 2: "Invalid Host header" in the cloud
The server worked locally and failed behind Container Apps. The SDK's DNS-rebinding protection only allows
localhost by default. The fix was TransportSecuritySettings(allowed_hosts=[...]), with the public FQDN passed in an env var. Along the way I also found that az containerapp up --env-vars replaces every environment variable instead of adding to them, and the next revision crashed with KeyError: 'TENANT_ID'.Flaw 3: Cost Management throttles faster than you think
I got a
429 after three manual calls, and Cowork hit the same throttle in the real run (Figure 6). Query cost is metered in QPUs per tenant. My tool reports Retry-After instead of failing silently, and the skill tells Cowork not to repeat calls. Next I'll add caching.Flaw 4: The API ignores your aggregation alias
I asked for
"totalCost": {"name": "Cost", "function": "Sum"} and got a column called Cost. My first version read totalCost and got nothing. The fix was to normalise the column names.Flaw 5: The tool-description file was "not found" when it was right there
The first upload failed with
InvalidAgentConnector: ... MCP tool description file ./tools/azure-cost-tools.json not found in the app package. The file was in the zip. It went through after I changed the path to tools/azure-cost-tools.json (no leading ./) and rebuilt the zip without directory entries.
InvalidAgentConnector
Flaw 6: "Authentication is still processing" forever
After the upload, the connector showed "Could not verify connection". Clicking Connect did nothing except leave "Authentication is still processing". No popup opened and no sign-in reached Entra. The cause was the OAuth registration's "Restrict usage by app → Existing Teams app ID" setting, which I'd pointed at my manifest ID. Switching it to "Any Teams app" made the real Microsoft sign-in appear straight away. Keep the restriction at the organization level and test before you tighten it.

Could not verify connection
Flaw 7: Your test subscription can disappear
Halfway through, I found that one of the two demo subscriptions had been cancelled. Its cost history could still be queried, but nothing could be deployed into it. Cowork handled it well, because the forecast tool explained why there was no forecast. Even so, check your subscription's state before you plan a demo around it.
Conclusion
The pattern works. A read-only MCP server, one skill file and Work IQ turned a monthly spreadsheet chase into one Cowork prompt. That prompt joins live Azure spend to owners found in mail and Teams, and ends with a draft I approve myself.
The friction was all at the edges: SDK churn, hosting defaults, a throttled cost API, and plugin packaging and OAuth settings that the docs don't yet explain well. None of these is a blocker, but each cost me time. Plan for them, and the build itself is small. My next iteration adds a resource-group filter, response caching, and on-behalf-of auth, so each user sees only the subscriptions they can see.
Sample code (MCP server, Dockerfile, plugin package): https://github.com/Yadui/cowork-azure-cost-mcp
References