MCP Server
The Metrx MCP Server (@metrxbot/mcp-server) exposes 23 cost intelligence tools via the Model Context Protocol that any MCP-compatible AI agent — Claude, GPT, Gemini, or custom agents — can call to track costs, optimize models, manage budgets, and prove ROI.
Version: 0.2.5 · License: MIT · npm
stdio vs hosted. The numbers above describe the npm package you install with
npx— 23 tools across 10 domains. The hosted endpoint athttps://metrxbot.com/api/mcpis built from the Metrx monorepo and currently runs ahead of it: 38 tools across 14 domains, adding health scores and rankings, the upgrade business case, the three verification-billing tools, and the three loop-metrics and loop-object tools. Those fourteen are not available over stdio.
Quick Start
1. Get an API key
Sign up at app.metrxbot.com and copy your key from Settings → Security.
2. Test the connection
METRX_API_KEY=sk_live_xxx npx @metrxbot/mcp-server --test3. Add to your MCP client
Claude Desktop (claude_desktop_config.json):
{
"mcpServers": {
"metrx": {
"command": "npx",
"args": ["@metrxbot/mcp-server"],
"env": {
"METRX_API_KEY": "sk_live_your_key_here"
}
}
}
}Cursor (.cursor/mcp.json):
{
"mcpServers": {
"metrx": {
"command": "npx",
"args": ["@metrxbot/mcp-server"],
"env": {
"METRX_API_KEY": "sk_live_your_key_here"
}
}
}
}Windsurf (~/.codeium/windsurf/mcp_config.json):
{
"mcpServers": {
"metrx": {
"command": "npx",
"args": ["@metrxbot/mcp-server"],
"env": {
"METRX_API_KEY": "sk_live_your_key_here"
}
}
}
}Environment Variables
| Variable | Required | Description |
|---|---|---|
METRX_API_KEY | Yes | Your Metrx API key (sk_live_* or sk_test_*) |
METRX_API_URL | No | Override API base URL (default: https://app.metrxbot.com/api) |
Tools Reference
All tools are prefixed with metrx_ in MCP (e.g., metrx_get_cost_summary).
Dashboard (3 tools)
metrx_get_cost_summary
Get a comprehensive cost summary for your AI agent fleet.
| Parameter | Type | Default | Description |
|---|---|---|---|
days | number (1–90) | 30 | Number of days to include |
Returns total spend, call counts, error rates, agent breakdown, revenue attribution, and optimization opportunities.
metrx_list_agents
List all AI agents in your organization.
| Parameter | Type | Default | Description |
|---|---|---|---|
status | active | idle | error | archived | — | Filter by status |
category | string | — | Filter by category (e.g., “sales”, “support”) |
metrx_get_agent_detail
Get detailed information about a specific agent.
| Parameter | Type | Default | Description |
|---|---|---|---|
agent_id | UUID | required | The agent UUID to look up |
Optimization (4 tools)
metrx_get_optimization_recommendations
Get AI-powered cost optimization recommendations including model switching, token guardrails, provider arbitrage, and revenue intelligence insights.
| Parameter | Type | Default | Description |
|---|---|---|---|
agent_id | UUID | — | Specific agent to analyze (omit for fleet-wide) |
include_revenue | boolean | true | Include revenue-side insights |
metrx_apply_optimization
Apply a one-click optimization recommendation to an agent. Only works for suggestions marked as one_click: true.
| Parameter | Type | Default | Description |
|---|---|---|---|
agent_id | UUID | required | The agent to optimize |
optimization_type | string | required | Type of optimization (e.g., “token_guardrails”, “model_switch”) |
payload | object | — | Override the default optimization payload |
metrx_route_model
Get a model routing recommendation for a specific task based on complexity. Routes simple tasks to cheaper models while keeping complex tasks on premium models.
| Parameter | Type | Default | Description |
|---|---|---|---|
agent_id | UUID | required | The agent to route for |
task_complexity | low | medium | high | required | Estimated task complexity |
current_model | string | — | Currently configured model (e.g., “gpt-4o”) |
metrx_compare_models
Compare LLM model pricing and capabilities across providers. Works without usage data (Day 0 value).
| Parameter | Type | Default | Description |
|---|---|---|---|
current_model | string | — | Model to compare against (e.g., “gpt-4o”) |
tier | frontier | balanced | efficient | budget | — | Capability tier filter |
provider | string | — | Provider filter (e.g., “openai”, “anthropic”, “google”) |
Budgets (3 tools)
metrx_get_budget_status
Get the current status of all budget configurations. Shows spending vs limits, warning/exceeded counts, and enforcement modes.
No parameters.
metrx_set_budget
Create or update a budget configuration for an agent or the entire organization.
| Parameter | Type | Default | Description |
|---|---|---|---|
agent_id | UUID | — | Agent to set budget for (omit for org-wide) |
period | daily | monthly | required | Budget period |
limit_dollars | number | required | Spending limit in dollars |
warning_pct | integer (1–99) | 80 | Percentage that triggers a warning |
enforcement_mode | alert_only | soft_block | hard_block | alert_only | How to enforce the limit |
metrx_update_budget_mode
Change the enforcement mode of an existing budget or pause/resume it.
| Parameter | Type | Default | Description |
|---|---|---|---|
budget_id | UUID | required | Budget configuration ID |
enforcement_mode | alert_only | soft_block | hard_block | — | New enforcement mode |
paused | boolean | — | Pause or resume the budget |
Alerts (3 tools)
metrx_get_alerts
Get active alerts and notifications — cost spikes, error rate increases, budget warnings, and system health notifications.
| Parameter | Type | Default | Description |
|---|---|---|---|
severity | info | warning | critical | — | Filter by severity |
unread_only | boolean | true | Only return unread alerts |
limit | integer (1–100) | 25 | Maximum alerts to return |
metrx_acknowledge_alert
Mark one or more alerts as read/acknowledged.
| Parameter | Type | Default | Description |
|---|---|---|---|
alert_ids | UUID[] (1–50) | required | Alert IDs to acknowledge |
metrx_get_failure_predictions
Get predictive failure analysis — upcoming risk of error rate breaches, latency degradation, cost overruns, and budget exhaustion.
| Parameter | Type | Default | Description |
|---|---|---|---|
agent_id | UUID | — | Filter for a specific agent |
severity | info | warning | critical | — | Filter by severity |
status | active | acknowledged | resolved | active | Filter by status |
Experiments (3 tools)
metrx_create_model_experiment
Start an A/B test comparing two LLM models. Routes a percentage of traffic to the treatment model and tracks cost, latency, error rate, and quality metrics.
| Parameter | Type | Default | Description |
|---|---|---|---|
agent_id | UUID | required | Agent to run the experiment on |
name | string (1–100) | required | Human-readable experiment name |
treatment_model | string | required | Candidate model (e.g., “gpt-4o-mini”) |
traffic_pct | integer (1–50) | 10 | Percentage of traffic to the treatment |
primary_metric | cost_per_call | latency_p50 | latency_p95 | error_rate | quality_score | cost_per_call | Metric to optimize for |
max_duration_days | integer (1–30) | 14 | Maximum experiment duration |
auto_promote | boolean | false | Auto-apply the winner when experiment concludes |
metrx_get_experiment_results
Get results of a model experiment — sample counts, metric comparisons, statistical significance, and the current winner.
| Parameter | Type | Default | Description |
|---|---|---|---|
agent_id | UUID | — | Filter by agent |
status | running | paused | completed | cancelled | — | Filter by status |
metrx_stop_experiment
Stop a running experiment. Results are preserved.
| Parameter | Type | Default | Description |
|---|---|---|---|
experiment_id | UUID | required | Experiment ID to stop |
promote_winner | boolean | false | Apply the winning model as the new default |
Cost Leak Detector (1 tool)
metrx_run_cost_leak_scan
Run a comprehensive cost leak audit. Identifies 7 types of cost inefficiencies: idle agents, model overprovisioning, missing caching, high error rates, context bloat, missing budgets, and cross-provider arbitrage opportunities.
| Parameter | Type | Default | Description |
|---|---|---|---|
agent_id | UUID | — | Scan a specific agent (omit for fleet-wide) |
include_low_severity | boolean | false | Include low-severity findings |
output_format | text | json | text | Output format (json for CI/CD pipelines) |
Attribution (3 tools)
metrx_attribute_task
Link an agent task/event to a business outcome for ROI tracking.
| Parameter | Type | Default | Description |
|---|---|---|---|
agent_id | UUID | required | Agent to attribute |
event_id | string | — | Specific event/task ID |
outcome_type | revenue | cost_saving | efficiency | quality | required | Type of outcome |
outcome_source | stripe | calendly | hubspot | zendesk | webhook | manual | required | Source of the outcome data |
value_cents | integer | — | Outcome value in cents |
description | string | — | Description of the outcome |
metrx_get_task_roi
Calculate return on investment for an agent — total costs, total outcomes, ROI multiplier, and breakdown by model and outcome type.
| Parameter | Type | Default | Description |
|---|---|---|---|
agent_id | UUID | required | Agent to calculate ROI for |
days | integer (1–365) | 30 | Number of days to analyze |
metrx_get_attribution_report
Get an attribution report showing which agent actions led to business outcomes.
| Parameter | Type | Default | Description |
|---|---|---|---|
agent_id | UUID | — | Filter to specific agent |
days | integer (1–365) | 30 | Number of days to include |
model | direct | last_touch | first_touch | direct | Attribution model |
Alert Configuration (1 tool)
metrx_configure_alert_threshold
Set up cost or operational alert thresholds. Alerts run server-side and can trigger email notifications, webhooks, or automatically pause the agent.
| Parameter | Type | Default | Description |
|---|---|---|---|
agent_id | UUID | — | Specific agent (omit for org-wide) |
metric | daily_cost | monthly_cost | error_rate | latency_p99 | required | Metric to monitor |
threshold_value | number | required | Threshold (costs: cents, rates: decimal, latency: ms) |
action | email | webhook | pause_agent | required | Action when threshold is breached |
ROI Audit (1 tool)
metrx_generate_roi_audit
Generate a comprehensive ROI audit report for your fleet. Includes per-agent cost/revenue breakdown, attribution confidence scores, optimization opportunities, and risk flags. Suitable for board reporting and compliance.
| Parameter | Type | Default | Description |
|---|---|---|---|
days | integer (7–365) | 30 | Analysis period |
include_methodology | boolean | true | Include methodology notes for auditors |
agent_ids | UUID[] | — | Specific agents (omit for full fleet) |
Upgrade Justification (1 tool)
metrx_get_upgrade_justification
Generate an ROI report for upgrading from Free to a paid tier. Analyzes usage patterns and calculates optimization potential.
| Parameter | Type | Default | Description |
|---|---|---|---|
days | integer (7–90) | 30 | Days to analyze |
Upgrade Business Case (1 tool) — hosted endpoint only
Hosted endpoint only. Not in the npm package; reachable over
https://metrxbot.com/api/mcp, not overnpxstdio.
metrx_get_upgrade_business_case
Generate a personalized ROI business case for upgrading to a higher tier with projected savings and payback period.
| Parameter | Type | Default | Description |
|---|---|---|---|
current_tier | starter | lite | pro | required | Current subscription tier |
monthly_spend | number | — | Known monthly LLM spend in cents |
agent_count | integer | — | Number of active agents |
primary_use_case | customer_support | data_processing | content_generation | code_assistant | — | Primary use case |
Health & Rankings (2 tools) — hosted endpoint only
Hosted endpoint only. Not in the npm package; reachable over
https://metrxbot.com/api/mcp, not overnpxstdio.
metrx_get_health_scores
Health score, grade, and data completeness for every agent in the organization. Scores are composite 0–100 values blending cost efficiency, ROI, error rate, quality drift, failure risk, and latency. Grades: A (80–100), B (60–79), C (40–59), D (20–39), F (0–19).
Takes no parameters.
metrx_get_rankings
Agents sorted by health score with percentile ranking, plus a fleet summary (average score and grade) and stale-score warnings. Use it to find top and bottom performers.
Takes no parameters.
Verify Billing (3 tools) — hosted endpoint only
Hosted endpoint only. Not in the npm package; reachable over
https://metrxbot.com/api/mcp, not overnpxstdio.
A verification is a causal verdict on whether a model switch holds quality on your own production traffic. The unit noun is “verification” — never “credits”. No verdict, no charge.
metrx_get_balance
How many verifications your organization has remaining. Free to call. Use it before metrx_verify_switch to know whether a purchase is needed first.
Takes no parameters.
metrx_buy_verification
Purchase one verification. Returns a Stripe checkout URL for a human (or payment-capable agent) to complete, plus claim instructions when the purchase is anonymous. This tool does not charge anything itself — payment happens on the returned URL.
| Parameter | Type | Default | Description |
|---|---|---|---|
callback_url | string (URL) | — | Optional post-checkout redirect base URL |
metrx_verify_switch
Start a purchased verification: would candidate_model hold quality against prod_model on your production traffic? Async — returns a request handle immediately and never blocks; verdicts complete after enough of your own traffic accrues. Poll GET /api/verify/requests/{id}. If the balance is 0 this returns purchase guidance instead of spending.
| Parameter | Type | Default | Description |
|---|---|---|---|
prod_model | string | required | Current production model |
candidate_model | string | required | Candidate model to verify against it |
agent_id | UUID | — | Agent to scope the verification to |
policy_id | UUID | — | Routing policy to attach to |
Loop Metrics (8 tools) — hosted endpoint only
Hosted endpoint only. Not in the npm package; reachable over
https://metrxbot.com/api/mcp, not overnpxstdio.
These tools return measured-value envelopes: every numeric leaf is
{value, ci_low, ci_high, method, data_through}. CI fields are populated only
where the source payload carries a real confidence interval — never fabricated.
Raw counts use method: "count".
metrx_get_signal_readiness
Org-scoped signal-readiness diagnostics — per-agent event coverage, label lag, join rate, volume-vs-power (days to trial-ready at current volume), estimator eligibility with reasons, and blocked-on-signal proposals cross-linked to the failing readiness dimension. The “what unlocks your first verified verdict” surface.
Takes no parameters.
metrx_get_dashboard_headline
The three-number headline regime: measured spend, attributed (modeled) savings,
and verified savings-with-CI — each with basis, provenance, and tone. Values
are micro-dollars (dollars = value / 1e6). Requires the optimization_model_v3
flag; while it is off the tool returns a clear next-step error.
| Parameter | Type | Default | Description |
|---|---|---|---|
days | 7 | 30 | 90 | 30 | Window in days |
metrx_get_report_snapshot
Fetch one frozen executive-report snapshot by its public share token (the token
is the capability). Returns the stored snapshot only — never recomputed — plus
its snapshot_hash and methodology_version integrity stamps.
| Parameter | Type | Default | Description |
|---|---|---|---|
share_token | string (16–64 hex) | required | The report share token |
metrx_get_verdicts
Org-scoped current causal-verdict summaries — per (agent, prod model,
candidate model, task category): verdict, evidence mode/regime, pair counts,
non-inferiority, savings CI, judge model, expiry. Observational (:value) rows
are flagged. Summaries only: no gate flags and no evidence-pack contents (those
remain dashboard-session-only). Read-only twin route (/api/loop-views/verdicts).
Takes no parameters.
metrx_get_trials
Org-scoped pre-registered trial plans: regime, primary metric, margin, the frozen sample plan (pre-registration), models, status (registered/concluded/voided) and the concluding verdict id. Read-only.
Takes no parameters.
metrx_get_proposals
Org-scoped current candidate proposals: action type/class, D-class, status
with blocked_reason, estimated impact, taxonomy axes. Config payloads
(config_diff, guardrails, rollback mechanics) are deliberately excluded.
Read-only.
Takes no parameters.
metrx_get_actuations
Org-scoped policy actuation records: action class, authority, actor and timing,
rollback state with reason, acknowledgement state. Config contents are
excluded. Requires the optimization_model_v3 flag (404 while off). Read-only.
Takes no parameters.
metrx_get_decision_queue
The operator decision queue, derived from real loop objects (approvable
verdicts, blocked proposals, breaker events, expiring evidence). Read-only:
approve/snooze/acknowledge actions remain dashboard-session-only and are not
exposed to API-key callers. Requires the optimization_model_v3 flag.
Takes no parameters.
Guided Prompts
MCP prompts are interactive templates that walk agents through multi-step workflows. Use them from any MCP-compatible client.
analyze-costs
Step-by-step cost analysis: fetches cost summary → lists agents → gets optimization recommendations → returns a prioritized breakdown.
| Argument | Type | Description |
|---|---|---|
days | string (optional) | Number of days to analyze (default: “30”) |
find-savings
Discovers optimization opportunities: checks recommendations → runs cost leak scan → explains savings in dollars.
No arguments.
cost-leak-scan
Runs the 7-check waste audit: retry storms, oversized contexts, model mismatch, missing caching, idle agents, missing budgets, and arbitrage gaps.
| Argument | Type | Description |
|---|---|---|
agent_id | string (optional) | Scan a specific agent by UUID, or omit to scan all |
Rate Limiting
The MCP server enforces 60 requests per minute per tool to prevent abuse. Hitting the limit returns an error with a retryAfter value.
Error Handling
All tools return standardized error responses:
{
"content": [{ "type": "text", "text": "Error message" }],
"isError": true
}| Status | Meaning | Fix |
|---|---|---|
| 401 | Invalid or expired API key | Regenerate key |
| 403 | Insufficient permissions | Check key permissions |
| 404 | Resource not found | Use metrx_list_agents to get valid IDs |
| 429 | Rate limited | Wait for retryAfter seconds |
| 5xx | Server error | Retry with backoff |
Troubleshooting
“METRX_API_KEY not set” — Set the environment variable before starting:
export METRX_API_KEY=sk_live_your_key
npx @metrxbot/mcp-server“Rate limit exceeded” — You’ve made more than 60 requests to a single tool within 60 seconds. The MCP client will retry automatically.
“Agent not found” — The agent_id doesn’t exist. Run metrx_list_agents to get valid IDs.
Connection test fails — Run npx @metrxbot/mcp-server --test to verify your API key and network connectivity.