aws-cost-mcp
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@aws-cost-mcp Why did our AWS bill jump 40% last week?"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
aws-cost-mcp
An MCP server that lets AI agents (Claude, Cursor, Copilot, any MCP client) answer questions about your AWS bill — with guardrails, caching and zero write access.
You: "Why did our AWS bill jump 40% last week?"
Agent → aws-cost-mcp.get_cost_breakdown(groupBy: SERVICE, granularity: DAILY)
Agent → aws-cost-mcp.get_anomalies(last: 14d)
Agent: "Most of the increase comes from NAT Gateway data transfer in us-east-1, starting Tuesday…"Why
Cost questions are some of the most common — and most painful — questions an engineering team asks. The answer lives in Cost Explorer, behind several clicks, filters and tag conventions that only one person on the team understands.
This project exposes AWS Cost Explorer as a read-only, well-typed MCP server, so that any agent can investigate spend, explain variations and suggest savings, using the same data a FinOps engineer would.
It was built from real experience migrating a campaign platform to AWS and driving its infrastructure cost down — the questions this server answers are the ones I had to answer by hand.
Related MCP server: Cost Explorer MCP Server
Features
Tool | What it does | AWS API |
| Cost for a period, grouped by service, account, region, tag or usage type |
|
| Diff between two periods, ranked by absolute and % change |
|
| Forecast until end of month / custom date |
|
| Recent cost anomalies with root causes |
|
| EC2 rightsizing recommendations with estimated savings |
|
| Discover cost allocation tags so the agent can filter correctly |
|
Prompts
investigate-cost-spike— guided workflow: compare → break down → attribute by tag → check anomalies → forecast → explain.
Planned: the aws-cost://summary/month-to-date resource and a monthly-finops-report prompt.
Design principles
Read-only by construction. The server only calls
ce:Get*APIs. A minimal IAM policy is provided below.Cheap to run. Cost Explorer charges per API request, so responses are cached in memory (LRU, TTL from
AWS_COST_MCP_CACHE_TTL,0disables it) and concurrent identical requests share one call. Failed calls are never cached.Agent-friendly output. Responses are compact, sorted and truncated (top-N + "others") to save context tokens. Raw JSON is available with
format: "json".Strict input validation. All tool inputs are validated with Zod; invalid ranges and granularities return actionable errors the agent can fix itself.
Quick start
1. Requirements
Node.js ≥ 20
AWS credentials with the policy below (profile, SSO or env vars)
Cost Explorer enabled in the account
2. Use with Claude Desktop / Claude Code / Cursor
{
"mcpServers": {
"aws-cost": {
"command": "npx",
"args": ["-y", "aws-cost-mcp"],
"env": {
"AWS_PROFILE": "my-readonly-profile",
"AWS_COST_MCP_CACHE_TTL": "900"
}
}
}
}3. Run as a remote server (Streamable HTTP)
stdio is the default. For a shared deployment, serve MCP over HTTP instead:
AWS_COST_MCP_TRANSPORT=http \
AWS_COST_MCP_HTTP_TOKEN="$(openssl rand -hex 24)" \
npx aws-cost-mcp # POST http://127.0.0.1:3333/mcpEvery request must send Authorization: Bearer <token>. The server is stateless (no sessions, so any replica can answer), and GET /healthz is open for load balancers. It binds to loopback by default and refuses to start on any other interface without a token. Put TLS in front of it (reverse proxy or load balancer); it speaks plain HTTP.
4. Run locally (development)
git clone https://github.com/VictorCarvalho16/aws-cost-mcp
cd aws-cost-mcp
npm install
npm run dev # stdio server with hot reload
npm run inspector # opens the MCP Inspector against the local serverMinimal IAM policy
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ce:GetCostAndUsage",
"ce:GetCostForecast",
"ce:GetAnomalies",
"ce:GetRightsizingRecommendation",
"ce:GetTags"
],
"Resource": "*"
}
]
}Configuration
Variable | Default | Description |
| SDK default chain | Standard AWS credentials |
|
| Cache TTL in seconds |
|
| Max rows returned before grouping into "others" |
|
| Display currency |
|
|
|
|
|
|
|
| Interface to bind; non-loopback requires a token |
|
| Port for the HTTP transport |
| unset | Bearer token (≥ 16 chars) required on every request |
Architecture
┌──────────────┐ stdio ┌──────────────────────────────┐
│ MCP client │ ────────────────────────▶ │ aws-cost-mcp │
│ (Claude etc.)│ │ ├─ tools/ (Zod schemas) │
└──────────────┘ │ ├─ services/cost-explorer.ts│
│ ├─ cache/ (LRU + dedupe) │
│ └─ format/ (md tables) │
└──────────────┬───────────────┘
│ AWS SDK v3
▼
AWS Cost Explorer APIsrc/
├── index.ts # entrypoint (stdio or HTTP transport)
├── http.ts # stateless Streamable HTTP server with bearer auth
├── server.ts # McpServer registration (tools, prompts)
├── tools/ # one file per tool: schema + handler
├── prompts/ # guided workflows
├── services/
│ └── cost-explorer.ts # thin typed wrapper over @aws-sdk/client-cost-explorer
├── cache/ # TTL + LRU cache with in-flight request sharing
├── format/ # markdown/JSON formatters, top-N truncation
├── dates.ts # UTC date helpers and range checks
└── config.ts
test/
├── unit/ # handlers with mocked SDK (aws-sdk-client-mock), in-memory MCP, HTTP
└── e2e/ # the real entrypoint as a child process, over stdioStack: TypeScript · @modelcontextprotocol/sdk · AWS SDK v3 · Zod · Vitest · tsup · GitHub Actions
Testing
npm test # unit + e2e tests (no AWS needed — SDK is mocked / never reached)
npm run lint && npm run typecheckRoadmap
v0.1 — MVP
Project scaffold (TypeScript, tsup, Vitest, ESLint, Prettier)
get_cost_breakdownwith Zod validationMarkdown formatter with top-N truncation
Unit tests with
aws-sdk-client-mockCI on GitHub Actions (lint, typecheck, test)
v0.2 — Useful
compare_periods,get_forecast,list_tag_valuesLRU cache + request dedupe
investigate-cost-spikepromptPublish to npm, add to the MCP Registry
v0.3 — Production-grade (code complete, not yet run against real AWS)
get_anomalies,get_rightsizingStreamable HTTP transport (for remote/shared deployments)
E2E tests over stdio
Verify against a real AWS account (v0.3 was built and tested against mocks only)
Demo GIF in this README
Blog post: "Giving an AI agent read-only access to your AWS bill"
Ideas
Multi-account (Organizations) support
Savings Plans / RI coverage tools
Export a report as CSV resource
Security
Never request write permissions — the server has no code path that mutates AWS resources.
Logs go to stderr only (stdout is reserved for the MCP protocol).
Credentials are resolved by the AWS SDK default chain and never logged or returned to the client.
Found a vulnerability? Please open a private security advisory instead of an issue.
Contributing
Issues and PRs are welcome. Run npm test before opening a PR and follow Conventional Commits.
License
MIT © Victor Hugo Araújo de Carvalho
Available Tools
6 toolscompare_periodsCompare AWS cost between two periodsARead-onlyIdempotent
Diff AWS cost between two periods per service, account, region, usage type or tag, ranked by absolute change. Use it to find what drove a rise or drop. With no dates it compares month-to-date against the equally long period right before it.
Inputs: format, metric, tagKey, groupBy, +4 more.
get_anomaliesAWS cost anomaliesARead-onlyIdempotent
Recent cost anomalies flagged by AWS Cost Anomaly Detection, biggest impact first, with the service, region, account and usage type that caused each. Needs an anomaly monitor set up in the Billing console.
Inputs: end, start, format, minImpact.
get_cost_breakdownAWS cost breakdownARead-onlyIdempotent
AWS cost for a date range, grouped by service, account, region, usage type or cost allocation tag. Defaults to month-to-date by service. Returns the top groups sorted by cost, with the rest collapsed into 'Others'.
Inputs: end, start, format, metric, +3 more.
get_forecastAWS cost forecastARead-onlyIdempotent
Forecast AWS spend from today until the end of the month (or a custom end date). Covers only the remaining days; combine with get_cost_breakdown for spend already incurred.
Inputs: end, format, metric, granularity.
get_rightsizingEC2 rightsizing recommendationsARead-onlyIdempotent
EC2 instances AWS recommends to downsize or terminate, largest estimated monthly savings first. Needs rightsizing recommendations enabled in Cost Explorer preferences.
Inputs: format, target, benefitsConsidered.
list_tag_valuesList AWS cost allocation tagsARead-onlyIdempotent
Discover the cost allocation tag keys in use, or the values of one key, so cost breakdowns can be filtered or grouped by tags that actually exist.
Inputs: end, start, format, search, +1 more.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 6 tools
Each tool maps to a distinct cost-analysis task: single-period breakdown, period-over-period diff, forecast, tag discovery, anomaly detection, and rightsizing. The only potential overlap (get_cost_breakdown vs compare_periods) is explicitly clarified by descriptions that differ in output shape and intent. No tool appears to duplicate another's purpose.
All six names follow a consistent verb_noun snake_case pattern (get_*, list_*, compare_*). The conventions are predictable and readable throughout, with no mixed casing or stylistic outliers.
Six tools is a tight, well-scoped surface for AWS cost analysis, with each tool earning its place. There is no filler or redundant tool, and the set is not so thin that core workflows would be impossible.
The surface covers the main cost lifecycle: breakdown, comparison, forecast, tag discovery, anomalies, and rightsizing. Minor gaps exist around commitment utilization (Savings Plans/RI coverage), budget status, and resource-level cost detail, but agents can work around these for most spend-investigation tasks.
Maintenance
Related MCP Connectors
AWS Cost Explorer cost, forecast, and anomaly reporting through user-connected IAM credentials.
Amazon Ads, Seller Central, Vendor Central and AMC data for AI agents. Read-only by default.
Read-only finance and operations controls for AI agents with evidence and safe next actions.
Cloud cost + FinOps knowledge for AI agents: AWS/Azure/GCP optimisation, AI spend, waste playbooks.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceEnables querying and analyzing AWS cost and usage data through the AWS Cost Explorer API. Supports cost comparisons, forecasting, dimension filtering, and cost change driver analysis with streamable HTTP deployment to Amazon Bedrock Agentcore Runtime.-
- AlicenseNot gradedqualityDmaintenanceEnables analysis of AWS costs and usage through the AWS Cost Explorer API, supporting multi-account architectures with role assumption and cost comparison, forecasting, and anomaly detection.Apache 2.0
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to query and analyze AWS costs and usage via the Cost Explorer API.MIT
- AlicenseNot gradedqualityDmaintenanceEnables querying AWS costs and usage data from Claude Desktop through the Cost Explorer API.1MIT