How do I set up MCP agent attribution in Cognocient?
Add three headers to Claude MCP or LangGraph agent calls to get a full workflow cost tree — which tool called what, how much each step cost, and which agent drove the spend.
Goal: Replace "my agent cost $180 yesterday" with "web-search MCP: $94 · code-executor: $62 · document-reader: $24" — a full breakdown of which tool call, agent step, and handoff drove the cost.
Time: 15 minutes. Workflow tree appears in the dashboard after the first instrumented run.
Prerequisite: Cognocient proxy already connected. See Quickstart if not.
Step 1 — Add the three MCP attribution headers
All three headers work alongside your existing X-Cost-Feature and X-Cost-Run-ID headers. Add them to the calls made within your agent's tool execution logic.
| Header | What it tags | Example |
|---|---|---|
X-Cost-Parent-Run-Id | The parent workflow run (shared by all steps) | run-4a7c2b1e-... |
X-Cost-MCP-Server | The MCP server or tool making this call | web-search |
X-Cost-Agent-Handoff | Whether this is a sub-agent handoff | true |
Step 2 — Instrument a Claude + MCP workflow
The most common pattern: Claude as orchestrator, MCP servers as tools. Pass X-Cost-Parent-Run-Id on the orchestrator call and X-Cost-MCP-Server on each tool call.
Step 3 — Instrument a LangGraph multi-agent handoff
For supervisor/sub-agent patterns, add X-Cost-Agent-Handoff: true on sub-agent calls so Cognocient shows handoffs separately in the workflow tree.
Start with just X-Cost-MCP-Server
If you only add one header, add X-Cost-MCP-Server. Cost by MCP server is immediately the most actionable insight — it tells you which tool to optimise first without needing the full workflow tree.
Step 4 — View the workflow tree in the dashboard
Go to Dashboard → Agent Workflows. After the first instrumented run you'll see:
- Cost by MCP server — bar chart showing spend per tool (web-search, code-executor, etc.)
- Workflow tree per run — each step, which MCP server called it, tokens, cost, and latency at each node
- Most expensive runs — ranked by total cost with anomaly flags
- Handoff cost — what fraction of total cost came from agent-to-agent handoffs vs. direct calls
Example workflow tree in the dashboard:
Related: MCP / A2A Attribution · Track Cost Per Agent Run · Debug Runaway Agent Loops
Related articles
Tag Your First AI Call
Add 2 headers to your existing code and see per-feature spend in under 5 minutes.
Set a Monthly Spending Limit
Create a hard budget enforced at the proxy before charges reach your provider bill.
Cut Your AI Bill with One Click
Use AI Advisor recommendations to apply model downgrades and caching without code changes.