Infracost MCP Server
Enables Claude to interact with Infracost for Terraform cost estimation and cloud governance. Supports generating cost breakdowns, comparing configurations, creating tagging policies, setting up cost guardrails, and posting cost comments to PRs.
README
Infracost MCP Server
MCP server that lets Claude interact with Infracost for Terraform cost estimation and cloud governance. Works with Claude Desktop and Claude Code.
What it does
- Generate cost breakdowns for Terraform configurations
- Compare costs between different configs or branches
- Create and manage tagging policies in Infracost Cloud
- Set up cost guardrails that block expensive PRs
- Post cost comments to GitHub/GitLab/Azure/Bitbucket PRs
- Upload custom properties for resource classification
Prerequisites
- Node.js >= 18
- Infracost CLI (for cost estimation tools)
- Infracost service token from Infracost Cloud > Org Settings > API tokens
Installation
git clone <repo-url> infracost_mcp
cd infracost_mcp
npm install
npm run build
Configuration
Create a .env file in the project root:
INFRACOST_SERVICE_TOKEN=ics_v1_your_token_here
INFRACOST_ORG=your_org_slug
Get your service token from the Infracost Cloud dashboard under Org Settings > API tokens.
Usage
With Claude Code
The repo includes .mcp.json and .claude/agents/ so it works out of the box - just open the project in Claude Code and the Infracost tools will be available.
With Claude Desktop
Add to your Claude Desktop config file:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json - Windows:
%APPDATA%/Claude/claude_desktop_config.json
{
"mcpServers": {
"infracost": {
"command": "node",
"args": ["/absolute/path/to/infracost_mcp/dist/index.js"],
"env": {
"INFRACOST_SERVICE_TOKEN": "ics_v1_your_token"
}
}
}
}
Restart Claude Desktop after updating the config.
Examples
Natural Language Queries
Ask Claude things like:
Cost Estimation:
- "What's the monthly cost of my Terraform in ./infrastructure?"
- "Show me a cost breakdown for ./terraform/prod in table format"
- "Generate an HTML cost report and save it to report.html"
- "Upload the cost estimate from infracost.json to Infracost Cloud"
Cost Comparison:
- "Compare costs between ./staging and ./prod configs"
- "What's the cost difference if I switch from t3.medium to t3.large?"
- "Show me cost changes between the current branch and main"
Tagging Policies:
- "Create a tagging policy that requires Environment and Owner tags"
- "List all tagging policies for my organization"
- "Add a tagging policy that allows only 'dev', 'staging', 'prod' for Environment tags"
- "Update the tagging policy to also require a CostCenter tag"
Cost Guardrails:
- "Set up a guardrail that blocks PRs adding more than $200/month"
- "Create a guardrail that warns when total infrastructure cost exceeds $10k/month"
- "Block PRs with cost increases over 25% for my production repo"
- "List all active guardrails"
Pull Request Integration:
- "Post the cost estimate from infracost.json to GitHub PR #123 in owner/repo"
- "Add a cost comment to the current GitLab merge request"
JSON Examples
Generate cost breakdown:
{
"path": "./terraform/prod",
"format": "json",
"outFile": "cost-estimate.json"
}
Compare configurations:
{
"path": "./terraform/current",
"compareTo": "./terraform/baseline",
"format": "diff"
}
Create tagging policy:
{
"name": "Required tags policy",
"prComment": true,
"blockPr": true,
"tags": [
{
"key": "Environment",
"mandatory": true,
"valueType": "LIST",
"allowedValues": ["dev", "staging", "prod"]
},
{
"key": "Owner",
"mandatory": true,
"valueType": "REGEX",
"allowedRegex": "^[a-z]+\\.[a-z]+@company\\.com$"
}
]
}
Create cost guardrail:
{
"name": "Production cost limit",
"scope": {
"type": "REPO",
"repositories": ["myorg/prod-infrastructure"]
},
"increasePercentThreshold": 10,
"totalThreshold": 50000,
"blockPullRequest": true,
"commentOnPullRequest": true
}
See docs/EXAMPLES.md for more detailed examples.
Available Tools
CLI Tools (require Infracost CLI)
infracost_breakdown- Generate cost breakdown for Terraform infrastructureinfracost_diff- Show cost differences between two configurationsinfracost_output- Combine and format Infracost JSON filesinfracost_upload- Upload cost estimates to Infracost Cloudinfracost_comment- Post cost comments to pull requests
Cloud API Tools (require service token)
Tagging Policies:
infracost_cloud_list_tagging_policies- List all tagging policiesinfracost_cloud_get_tagging_policy- Get a specific tagging policyinfracost_cloud_create_tagging_policy- Create a new tagging policyinfracost_cloud_update_tagging_policy- Update an existing tagging policyinfracost_cloud_delete_tagging_policy- Delete a tagging policy
Guardrails:
infracost_cloud_list_guardrails- List all guardrailsinfracost_cloud_get_guardrail- Get a specific guardrailinfracost_cloud_create_guardrail- Create a cost guardrailinfracost_cloud_update_guardrail- Update an existing guardrailinfracost_cloud_delete_guardrail- Delete a guardrail
Custom Properties:
infracost_cloud_upload_custom_properties- Upload custom property values via CSV
Project Structure
src/- TypeScript source codedist/- Compiled JavaScript output (created bynpm run build)docs/- Additional documentation and examples.claude/- Claude Code agent configuration
Development
npm run build # Compile TypeScript
npm run watch # Watch mode for development
npm start # Run the MCP server
Troubleshooting
CLI tools not working:
- Verify Infracost CLI is installed:
infracost --version - Ensure
INFRACOST_SERVICE_TOKENis set correctly
Cloud API errors:
- Check that your service token has the necessary permissions
- Verify the organization slug is correct
Server not connecting:
- Ensure the path to
dist/index.jsis absolute in your MCP config - Restart Claude Desktop after making config changes
- Check that
npm run buildcompleted successfully
No resources found:
- Run
terraform initin your Terraform directory first - Verify the path to your Terraform files is correct
Resources
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。