Skip to content

Cloud Cost Management & FinOps

Cloud cost management with AI connects Cursor, Claude Code, and Codex to billing MCP servers — the AWS Labs Billing and Cost Management server, Vantage for multi-cloud — so the agent reads live spend, ranks the services driving growth, proposes phased right-sizing tagged by risk level, and drafts cost allocation and forecasts. The agent generates the change commands; a human decides whether to run them.

Your cloud bill jumped 40% this month. Finance wants an explanation by Friday, engineering swears nothing changed, and the staging cluster nobody tagged is buried somewhere in EC2-Other. The Cost Explorer console takes twenty clicks to answer a question you will have to re-answer next week, and the dashboard shows 200 line items with no story.

You do not need a FinOps platform for this. You need your coding agent to read the billing data, rank the waste, and hand you the exact commands to fix it — which five services moved, by how much, and why.

What you’ll walk away with on cloud cost management

Section titled “What you’ll walk away with on cloud cost management”
  • A working MCP setup for the AWS Labs Billing and Cost Management server and Vantage (multi-cloud), configured identically across Cursor, Claude Code, and Codex
  • A copy-paste prompt that returns your top cost drivers grouped by service, ranked right-sizing actions, and a risk note per action
  • A prompt for the untagged-spend hunt — the most common reason a bill is “unexplained”
  • A phased right-sizing plan tagged with risk levels, not a flat list of instances, plus the three-tool mechanics for turning one recommendation into a reviewed Terraform diff
  • An anomaly-detection prompt that distinguishes expected growth from genuine bill shock
  • A 20-line script that pipes Cost Explorer JSON into Claude Opus 5 for ranked recommendations, when you would rather script it than chat
  • A clear sense of when this workflow breaks — API charges, rate limits, stale tags, a 48-hour data lag — and how to recover

These servers expose billing and usage APIs as tools the assistant can call directly. The server definition — command, args, env — is identical across Cursor, Claude Code, and Codex; only the file each tool reads differs (.cursor/mcp.json or Cursor Settings, .mcp.json for Claude Code, ~/.codex/config.toml for Codex).

AWS Labs publishes the official Billing and Cost Management MCP server, the successor to the older cost-analysis server. It exposes Cost Explorer, budgets, Compute Optimizer right-sizing, Cost Optimization Hub, Savings Plans recommendations, and month-over-month comparisons through your existing AWS credentials — which makes it the one server to start with, because the narrower awslabs.cost-explorer-mcp-server answers spend questions but carries none of the optimizer recommendations the right-sizing prompts below depend on.

It runs via uvx, so install uv first and make sure aws configure (or AWS_PROFILE) resolves to a role with ce:Get*, compute-optimizer:Get*, and cost-optimization-hub:* read permissions.

Add the server to .cursor/mcp.json (project) or your global Cursor MCP settings, then enable it in Settings → MCP. Cursor surfaces the tools to agent mode automatically:

{
"mcpServers": {
"awslabs.billing-cost-management-mcp-server": {
"command": "uvx",
"args": ["awslabs.billing-cost-management-mcp-server@latest"],
"env": {
"FASTMCP_LOG_LEVEL": "ERROR",
"AWS_PROFILE": "your-aws-profile",
"AWS_REGION": "us-east-1"
}
}
}
}

Open the agent panel (Cmd/Ctrl+I), switch to Agent mode, and confirm the billing tools appear in the MCP tool list before prompting.

Vantage aggregates AWS, Azure, GCP, Kubernetes, and SaaS spend behind one API. The official MCP server runs via npx and authenticates with a read-only bearer token generated from your Vantage account under API access — the assistant never needs write access to analyze spend.

{
"mcpServers": {
"vantage": {
"command": "npx",
"args": ["-y", "vantage-mcp-server"],
"env": {
"VANTAGE_TOKEN": "your-read-only-vantage-token"
}
}
}
}

In Codex’s TOML the same server reads:

[mcp_servers.vantage]
command = "npx"
args = ["-y", "vantage-mcp-server"]
env = { VANTAGE_TOKEN = "your-read-only-vantage-token" }

For Azure and GCP, the equivalents are @azure/mcp (npx -y @azure/mcp@latest server start) and @google-cloud/gcloud-mcp (npx -y @google-cloud/gcloud-mcp), each reading their native credential chain. Add them only when you actually operate in those clouds.

The pattern is the same regardless of tool: connect a cost MCP server, ask a focused question, then verify the recommendation against the actual resource before you act. The AI is fast at finding candidates; you own the decision to change production.

A vague prompt (“analyze my costs”) wastes a turn. The one below is deliberately opinionated — it names the grouping, the metric, the window, and the output shape.

The do not run any modifications line matters. Without it, an agent in auto-approve mode may try to apply a right-sizing through a write tool. You want the analysis and the commands — the apply decision stays human.

Once you have the ranked list, the follow-up that earns its keep is the untagged-spend hunt, the single most common reason a bill is “unexplained”:

If your spend spans more than AWS, run the same question across providers with Vantage in the mix. The mechanics differ slightly per tool:

Open the agent panel and reference the servers by name. Cursor keeps the analysis in your editor so you can drop findings straight into a runbook or Terraform change.

@vantage @aws-cost Pull last month's spend grouped by service and linked
account. For the five services that grew the most versus the prior month, tell
me the dollar delta, the likely driver (usage vs. price vs. new resources), and
whether the growth looks expected for a product scaling its user base. Output a
table, then a short prioritized list of what to investigate first.

Cursor returns a table you can iterate on inline — ask follow-ups like “drill into RDS” without restating context.

A typical response groups spend, ranks the movers, and flags which growth is benign — RDS grew because three read replicas were added (expected for a traffic ramp) while a 45% jump in inter-region transfer has no matching deploy and warrants investigation. Treat the dollar figures as a starting point and confirm them against the provider console before you brief finance, because tag coverage and account boundaries shape what the API returns.

Prompts that return decisions, not dashboards

Section titled “Prompts that return decisions, not dashboards”

These are the reusable recipes. They name real services and ask for opinionated output, so they work with minimal editing — swap the provider or threshold and run.

Turning a recommendation into a reviewed change

Section titled “Turning a recommendation into a reviewed change”

Visibility tells you what to fix. The next step is having the agent turn one recommendation into a reviewed change in your IaC. The recommendation is identical across tools — “downsize this over-provisioned m5.2xlarge to an m5.large” — but how you drive each tool to edit the Terraform differs.

Open the Terraform module in the editor. In Agent mode, reference the file and the MCP finding so Cursor edits inline and shows you a diff to accept or reject:

@main.tf The AWS cost MCP flagged `aws_instance.api` (m5.2xlarge) at 9% average
CPU over 30 days. Change it to the Compute Optimizer recommended size, add a
comment with the date and the % savings, and show me a `terraform plan` summary
of what changes. Do not apply.

Use Cursor’s checkpoint before accepting so you can roll the edit back in one click if the plan looks wrong.

Two follow-on jobs round out a FinOps practice: turning history into a forward budget, and making spend traceable to teams.

A linear “we spent X last month so we’ll spend X again” projection is wrong the moment usage has any seasonality. The agent has two honest options — ask the MCP for Cost Explorer’s own forecast, or pull the raw history and fit it. For most teams the built-in forecast is enough:

That prompt answers “are we about to blow a budget this quarter?”. Annual planning is a different question, and it wants relative history plus explicit buffers rather than a single number:

Anchoring on relative history (“last four quarters → next year”) keeps the analysis evergreen instead of pinned to a calendar year that will go stale. Then make the spend traceable:

Spot-check the allocation against one team’s real invoice and confirm the forecast’s growth multiplier matches your product plan before either number reaches a budget review.

To feed a dashboard or a scheduled report, skip the chat and pipe the data into Claude directly. This script pulls real Cost Explorer history and asks Claude Opus 5 for a ranked, structured set of recommendations:

// rank-cost-drivers.ts — run: npx tsx rank-cost-drivers.ts
import { CostExplorer } from '@aws-sdk/client-cost-explorer';
import Anthropic from '@anthropic-ai/sdk';
const ce = new CostExplorer({ region: 'us-east-1' });
const anthropic = new Anthropic(); // reads ANTHROPIC_API_KEY
const end = new Date().toISOString().slice(0, 10);
const start = new Date(Date.now() - 30 * 864e5).toISOString().slice(0, 10);
const { ResultsByTime } = await ce.getCostAndUsage({
TimePeriod: { Start: start, End: end },
Granularity: 'DAILY',
Metrics: ['UnblendedCost'],
GroupBy: [{ Type: 'DIMENSION', Key: 'SERVICE' }],
});
const msg = await anthropic.messages.create({
model: 'claude-opus-5',
max_tokens: 1500,
messages: [{
role: 'user',
content: `Here is 30 days of AWS daily cost grouped by service as JSON. Return the top
5 cost drivers, any service trending up more than 20% week-over-week, and one concrete
rightsizing or scheduling action per driver with an estimated monthly saving.
\n\n${JSON.stringify(ResultsByTime)}`,
}],
});
console.log(msg.content);

For high-volume, simple classification passes — labelling thousands of resources by environment from their names, say — drop to the cheapest model instead of the flagship:

const msg = await anthropic.messages.create({
model: 'claude-haiku-4-5', // cheapest tier, ~$1/$5 per Mtok — fine for bulk tagging
max_tokens: 256,
messages: [{ role: 'user', content: tagInferencePrompt }],
});

If your spend lives in Kubernetes rather than raw EC2, swap the AWS MCP for a cluster MCP so the agent can read resource requests versus actual usage — the data behind almost every pod-level waste finding. Two real, separate packages do this: the community mcp-server-kubernetes and the unscoped kubernetes-mcp-server (npx -y kubernetes-mcp-server@latest). Pick one and use its exact name; the scoped @kubernetes/mcp-server does not exist and a prompt referencing it will silently do nothing.

Add it the same way (claude mcp add --transport stdio k8s -- npx -y mcp-server-kubernetes, or the matching .cursor/mcp.json / config.toml block), then:

For genuine multi-cloud cost comparison, be honest about tooling: there is no single trustworthy “arbitrage” MCP. Use each provider’s own server — the AWS billing MCP above, Vantage for a unified view, @azure/mcp and @google-cloud/gcloud-mcp for native data — and have the agent normalize the numbers. Treat cross-cloud migration savings as a model, not a guarantee, because egress and re-architecture costs routinely erase the headline difference.

  1. The MCP tools never appear, or every call returns an auth error. The server starts but Cost Explorer 403s, or every query comes back empty. Almost always AWS_PROFILE resolves to the wrong account or a role without ce:Get*. Run aws sts get-caller-identity with that profile, confirm the account, and check the IAM policy includes Cost Explorer, Compute Optimizer, and Cost Optimization Hub read actions. Cost Explorer also has to be enabled in the billing console before any API returns data. On the Vantage side, the equivalent is a missing or wrong-scoped VANTAGE_TOKEN.

  2. uvx isn’t found or the server fails to launch. The config is correct but uv isn’t installed or isn’t on the PATH the tool sees. Install uv, restart the tool so it picks up the new PATH, and test the raw command in a terminal: uvx awslabs.billing-cost-management-mcp-server@latest should start and wait on stdio.

  3. Cost Explorer API charges and rate limits bite. Each request is $0.01 and the API throttles under bursty load. An agent that fans out hundreds of daily-granularity calls can rack up cost and start failing with throttling errors. Scope queries to monthly granularity first and drill into daily only where it matters.

  4. The numbers look a day or two stale. Cost Explorer data lags 24-48 hours and updates up to three times a day — it is not real-time. If the agent reports yesterday’s spike as missing, that is expected. For anything closer to live you need CUR exports or CloudWatch billing metrics, not Cost Explorer.

  5. Stale or missing cost-allocation tags distort everything downstream. Allocation and chargeback are only as accurate as your tags, and a large “untagged” bucket silently skews every per-team figure. Treat tag coverage as a prerequisite, not a nice-to-have.

  6. Right-sizing causes throttling. Downsizing an instance that looks idle on average can starve it during traffic bursts, and a recommendation built on a quiet lookback window misses your monthly peak entirely. Check peak rather than mean utilization, make the agent state the lookback window, change one tier at a time, and watch latency and error rates after each change.

  7. The agent wants to apply a destructive change. It proposes terminating an instance or downsizing prod and — in auto-approve mode — tries to run it. This is why every prompt above ends with “do not apply” and why the MCP profile is read-only. Keep approvals on (--ask-for-approval on-request in Codex, accept/reject diffs in Cursor, review before running in Claude Code) for anything that mutates infrastructure.

  8. Hallucinated server names. If a prompt references a server you never configured, the tool call silently does nothing and the assistant may invent plausible numbers to fill the gap. Use the exact server keys from your own config, and verify any package name before wiring it in.