How do I attribute costs across MCP and multi-agent workflows?
Agent workflows are a black box for most finance teams — you know the total AI cost but not which tool call, which agent step, or which handoff drove it. MCP/A2A Attribution breaks down every dollar by MCP server, parent run, and handoff hop.
MCP/A2A Attribution breaks down every dollar by MCP server, parent run, and agent handoff hop. Pass X-Cost-MCP-Server and X-Cost-Parent-Run-Id headers on your agent calls to get a full workflow cost tree showing exactly what each step cost.
| Without MCP headers | With X-Cost-MCP-Server |
|---|---|
| My agent cost $180 yesterday. No idea which tool calls drove it. | web-search MCP: $94 (52%) · code-executor: $62 (34%) · document-reader: $24 (13%) |
The three MCP/A2A attribution headers
X-Cost-MCP-Server: web-search
Name of the MCP server making this call. Use the MCP server's identifier — e.g., "web-search", "code-executor", "document-reader". Cognocient aggregates cost by MCP server in the Agent Workflows dashboard.
X-Cost-Parent-Run-Id: run-4a7c2b1e-...
The parent workflow run ID — the same UUID shared by all agent steps in a single execution. This ties individual MCP tool calls back to the orchestrating run so you can see total per-run cost in the workflow tree.
X-Cost-Agent-Handoff: true
Set to "true" when this call is an agent-to-agent handoff — i.e., one agent is invoking a sub-agent via an API call. Cognocient uses this to build the workflow tree and attribute costs to handoff hops specifically.
These headers work alongside the existing attribution headers. Use X-Cost-Feature for the workflow name and X-Cost-Run-ID (same as X-Cost-Parent-Run-Id) for the run. The MCP-specific headers provide the additional layer of tool-level granularity.
Python — Claude tool use with MCP
The most common pattern: a Claude agent uses tool calls to invoke MCP servers. Pass the MCP server name in the header for every call that originates from a tool invocation.
Node.js — LangGraph agent with handoffs
For multi-agent systems where a supervisor hands off to specialist sub-agents, use X-Cost-Agent-Handoff: true on the sub-agent's calls so Cognocient builds the correct workflow tree.
Agent Workflows dashboard
Once you add these headers, the Agent Workflows tab shows:
- Cost by MCP server (bar chart) — Which tool is driving the most spend. Sortable by day/week/month.
- Workflow tree view — Per run: a tree showing each step, which MCP server was called, tokens used, cost, and latency at each node.
- Handoff cost attribution — What fraction of total run cost came from agent handoffs vs. direct orchestrator calls.
- Most expensive runs — Table of runs ranked by total cost, with step count and flagged anomalies.
Example workflow tree:
Start with X-Cost-MCP-Server
If you only add one header, add X-Cost-MCP-Server. Cost by MCP server is the most actionable insight — it immediately tells you which tool to optimise first.
Next steps: Attribution Headers · Sessions · Budget Enforcement
Related articles