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
Wire up the cost MCP servers
Section titled “Wire up the cost MCP servers”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: Billing and Cost Management
Section titled “AWS: Billing and Cost Management”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.
Register the stdio server with one command. Options come before the name; -- separates the name from the command:
claude mcp add --transport stdio \ --env FASTMCP_LOG_LEVEL=ERROR \ --env AWS_PROFILE=your-aws-profile \ --env AWS_REGION=us-east-1 \ aws-cost \ -- uvx awslabs.billing-cost-management-mcp-server@latestUse --scope project to share it with the repo via .mcp.json, or leave the default local scope for a personal, credential-bearing setup. Verify with claude mcp list.
Add the server to ~/.codex/config.toml under an [mcp_servers.<id>] table:
[mcp_servers.aws-cost]command = "uvx"args = ["awslabs.billing-cost-management-mcp-server@latest"]
[mcp_servers.aws-cost.env]FASTMCP_LOG_LEVEL = "ERROR"AWS_PROFILE = "your-aws-profile"AWS_REGION = "us-east-1"Codex reads config.toml on startup across App, CLI, and IDE surfaces. Confirm the tools loaded by typing / in the TUI and checking the MCP tool list.
Vantage, for multi-cloud
Section titled “Vantage, for multi-cloud”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.
From bill shock to a defensible plan
Section titled “From bill shock to a defensible plan”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 linkedaccount. For the five services that grew the most versus the prior month, tellme the dollar delta, the likely driver (usage vs. price vs. new resources), andwhether the growth looks expected for a product scaling its user base. Output atable, 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.
Run it from the terminal so the analysis lives next to your infra repo and can feed a script or a PR.
claude "Using the vantage and aws-cost MCP servers, find my top 5 cost-growthdrivers for last month vs. the prior month. For each, give the dollar delta, thelikely cause, and an expected-vs-anomalous verdict. End with a prioritizedinvestigation list."Claude Code coordinates both servers, aggregates the data, and writes a Markdown summary you can commit to your ops docs.
Codex reads the same servers from ~/.codex/config.toml and works across CLI, IDE, and Cloud.
codex "Analyze our multi-cloud spend via the vantage and aws-cost MCP serversand produce a phased cost-reduction plan: top 5 growth drivers, dollar deltas,likely causes, and an expected-vs-anomalous call for each."Run it in a Codex Cloud task to keep the analysis off your laptop, or in the IDE extension to fold results into a change you’re already drafting.
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% averageCPU over 30 days. Change it to the Compute Optimizer recommended size, add acomment with the date and the % savings, and show me a `terraform plan` summaryof 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.
From the repo root, let the CLI read the module and the live recommendation in one pass:
claude "Read infra/main.tf. Using the aws-cost MCP, get the Compute Optimizer \recommendation for the instance behind aws_instance.api, apply the recommended \instance_type in the file, and run 'terraform plan' to show the diff. \Stop before apply and summarize the plan."For a recurring sweep, wire it into a script or a pre-deploy hook so every release checks for over-provisioned resources flagged since the last run.
Run Codex in the repo with on-request approval so it pauses before touching files or running terraform:
codex --ask-for-approval on-request \ "Use the aws-cost MCP to get the rightsizing recommendation for the instance \ defined as aws_instance.api in infra/main.tf, update the instance_type, then \ run terraform plan and show me the diff. Do not apply."Because Codex spans App, CLI, IDE, and Cloud, you can hand the same task to a Cloud task for a long-running multi-module sweep and review the resulting PR.
Forecasting and cost allocation
Section titled “Forecasting and cost allocation”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.
When you would rather script it than chat
Section titled “When you would rather script it than chat”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.tsimport { 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 top5 cost drivers, any service trending up more than 20% week-over-week, and one concreterightsizing 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 }],});Kubernetes and multi-cloud
Section titled “Kubernetes and multi-cloud”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.
When AI-assisted cost analysis breaks
Section titled “When AI-assisted cost analysis breaks”-
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_PROFILEresolves to the wrong account or a role withoutce:Get*. Runaws sts get-caller-identitywith 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-scopedVANTAGE_TOKEN. -
uvxisn’t found or the server fails to launch. The config is correct butuvisn’t installed or isn’t on the PATH the tool sees. Installuv, 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@latestshould start and wait on stdio. -
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.
-
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.
-
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.
-
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.
-
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-requestin Codex, accept/reject diffs in Cursor, review before running in Claude Code) for anything that mutates infrastructure. -
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.
Where to go next with FinOps
Section titled “Where to go next with FinOps”- Infrastructure as Code with AI — turn a right-sizing plan into reviewed Terraform changes
- Monitoring and Observability — correlate cost spikes with the deploys and traffic that caused them
- CI/CD Pipelines — add cost-estimate gates to pull requests so spend is reviewed before it ships
- Security Operations with AI — wire scanning MCPs into the same three-tool loop
- Compliance Automation — keep cost attribution and audit trails in sync through tagging and policy data