by aws-samples
Provides automated cost‑analysis and optimization recommendations for AWS accounts by integrating Cost Explorer, Cost Optimization Hub, Compute Optimizer, Trusted Advisor, and Performance Insights, and exposing the functionality through a Model Context Protocol (MCP) server.
Cfm Tips Cost Optimization MCP Server delivers a full‑stack, read‑only cost‑analysis engine for AWS environments. It pulls data from native AWS services (Cost Explorer, Compute Optimizer, Trusted Advisor, etc.), runs a library of predefined optimization playbooks, and returns actionable recommendations in JSON or Markdown via an MCP‑compatible interface.
Installation
git clone https://github.com/aws-samples/sample-cfm-tips-mcp.git
cd sample-cfm-tips-mcp
pip install -r requirements.txt
python3 setup.py to install MCP configuration files.Running the MCP server
python3 mcp_server_with_runbooks.py
The server communicates over stdio, which can be wired into Amazon Q CLI or any MCP‑compatible client:
q chat # then ask for cost recommendations
Or configure in the Q Developer Plugin:
Typical commands (via chat or API) include:
get_cost_explorer_dataec2_rightsizingebs_optimizationrds_idlelambda_unusedcomprehensive_analysisQ: Does the server make any changes to my AWS resources? A: No. It operates with read‑only permissions only and returns recommendations; any remediation must be performed manually or via separate automation.
Q: Which AWS regions are supported?
A: All regions supported by the underlying AWS services. Specify the region in your queries or set AWS_DEFAULT_REGION.
Q: How are savings estimates calculated? A: The server uses pricing data from Cost Explorer and the utilization metrics from CloudWatch to project monthly cost reductions for each recommendation.
Q: Can I extend the playbooks?
A: Yes. Add new Python functions in runbook_functions.py and reference them in mcp_runbooks.json.
Q: What if I get permission errors? A: Verify that the IAM policy from the README is attached and that Cost Optimization Hub is enabled in the AWS console.
A comprehensive Model Context Protocol (MCP) server for AWS cost analysis and optimization recommendations, designed to work seamlessly with Amazon Q CLI and other MCP-compatible clients.
sample-cfm-tips-mcp/
├── playbooks/ # CFM Tips optimization playbooks engine
├── services/ # AWS Services as datasources for the cost optimization
├── mcp_server_with_runbooks.py # Main MCP server
├── runbook_functions.py # Cost optimization runbook implementations
├── mcp_runbooks.json # Template file for MCP configuration file
├── requirements.txt # Python dependencies
├── test_runbooks.py # Integration tests
├── diagnose_cost_optimization_hub_v2.py # Diagnostic utilities
├── RUNBOOKS_GUIDE.md # Detailed usage guide
└── README.md # Project ReadMe
The MCP tools require specific AWS permissions to function.
The below creates an IAM policy with for list, read and describe actions only:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"cost-optimization-hub:ListEnrollmentStatuses",
"cost-optimization-hub:ListRecommendations",
"cost-optimization-hub:GetRecommendation",
"cost-optimization-hub:ListRecommendationSummaries",
"ce:GetCostAndUsage",
"ce:GetCostForecast",
"compute-optimizer:GetEC2InstanceRecommendations",
"compute-optimizer:GetEBSVolumeRecommendations",
"compute-optimizer:GetLambdaFunctionRecommendations",
"ec2:DescribeInstances",
"ec2:DescribeVolumes",
"rds:DescribeDBInstances",
"lambda:ListFunctions",
"cloudwatch:GetMetricStatistics",
"s3:ListBucket",
"s3:ListObjectsV2",
"support:DescribeTrustedAdvisorChecks",
"support:DescribeTrustedAdvisorCheckResult",
"pi:GetResourceMetrics",
"cloudtrail:DescribeTrails",
"cloudtrail:GetTrailStatus",
"cloudtrail:GetEventSelectors"
],
"Resource": "*"
}
]
}
Clone the Repository
git clone https://github.com/aws-samples/sample-cfm-tips-mcp.git
cd sample-cfm-tips-mcp
Install Dependencies
pip install -r requirements.txt
Configure AWS Credentials
aws configure
# Or set environment variables:
# export AWS_ACCESS_KEY_ID=your_access_key
# export AWS_SECRET_ACCESS_KEY=your_secret_key
# export AWS_DEFAULT_REGION=us-east-1
Apply IAM Permissions
Install the MCP Configurations
python3 setup.py
Usage Option 1: Using the Q CLI Chat
q chat
Show me cost optimization recommendations
Usage Option 2: Integrate with Amazon Q Developer Plugin or Kiro
- Scope: Global
- Name: cfm-tips
- Transport: stdio
- Command: python3
- Arguments: <replace-with-path-to-folder>/mcp_server_with_runbooks.py
- Timeout: 60
get_cost_explorer_data - Retrieve AWS cost and usage datalist_coh_enrollment - Check Cost Optimization Hub enrollmentget_coh_recommendations - Get cost optimization recommendationsget_coh_summaries - Get recommendation summariesget_compute_optimizer_recommendations - Get compute optimization recommendationsec2_rightsizing - Analyze EC2 instances for right-sizing opportunitiesec2_report - Generate detailed EC2 optimization reportsebs_optimization - Analyze EBS volumes for optimizationebs_unused - Identify unused EBS volumesebs_report - Generate EBS optimization reportsrds_optimization - Analyze RDS instances for optimizationrds_idle - Identify idle RDS instancesrds_report - Generate RDS optimization reportslambda_optimization - Analyze Lambda functions for optimizationlambda_unused - Identify unused Lambda functionslambda_report - Generate Lambda optimization reportscomprehensive_analysis - Multi-service cost analysisget_trusted_advisor_checks - Get Trusted Advisor recommendationsget_performance_insights_metrics - Get RDS Performance Insights data"Get my AWS costs for the last month"
"Show me cost optimization recommendations"
"What are my biggest cost drivers?"
"Find underutilized EC2 instances in us-east-1"
"Show me unused EBS volumes that I can delete"
"Identify idle RDS databases"
"Find unused Lambda functions"
"Generate a comprehensive cost optimization report"
"Create an EC2 right-sizing report in markdown format"
"Generate an EBS optimization report with cost savings"
"Run comprehensive cost analysis for all services in us-east-1"
"Analyze my AWS infrastructure for cost optimization opportunities"
"Show me immediate cost savings opportunities"
Cost Optimization Hub Not Working
python3 diagnose_cost_optimization_hub_v2.py
No Metrics Found
Permission Errors
Import Errors
# Check Python path and dependencies
python3 -c "import boto3, mcp; print('Dependencies OK')"
python3 diagnose_cost_optimization_hub_v2.pypython3 test_runbooks.pyAdd-on AWS Pricing MCP Server MCP server for accessing real-time AWS pricing information and providing cost analysis capabilities https://github.com/awslabs/mcp/tree/main/src/aws-pricing-mcp-server
# Example usage with Add-on AWS Pricing MCP Server:
"Review the CDK by comparing it to the actual spend from my AWS account's stackset. Suggest cost optimization opportunities for the app accordingly"
The CFM Tips cost optimization server can help you:
We welcome contributions! Please see our contributing guidelines:
This project is licensed under the MIT License - see the LICENSE file for details.
Please log in to share your review and rating for this MCP.
{
"mcpServers": {
"cfm-tips": {
"command": "python3",
"args": [
"mcp_server_with_runbooks.py"
],
"env": {}
}
}
}claude mcp add cfm-tips python3 mcp_server_with_runbooks.pyExplore related MCPs that share similar capabilities and solve comparable challenges
by awslabs
Provides specialized servers that expose AWS capabilities through the Model Context Protocol, enabling AI assistants to retrieve up-to-date documentation, execute API calls, and automate infrastructure workflows directly within development environments.
by cloudflare
Provides a collection of Model Context Protocol servers that enable MCP‑compatible clients to interact with Cloudflare services such as Workers, Observability, Radar, and more, allowing natural‑language driven management of configurations, data, and operations.
by Flux159
Connects to a Kubernetes cluster and offers a unified MCP interface for kubectl, Helm, port‑forwarding, diagnostics, and non‑destructive read‑only mode.
by TencentEdgeOne
Deploy HTML, folders, or zip archives to EdgeOne Pages and instantly obtain a public URL for fast edge delivery.
by rishikavikondala
Provides Model Context Protocol tools for performing AWS S3 and DynamoDB operations, with automatic logging and audit access via the `audit://aws-operations` endpoint.
by confluentinc
Enables AI assistants to manage Confluent Cloud resources such as Kafka topics, connectors, and Flink SQL statements through natural‑language interactions.
by aliyun
Enables AI assistants to operate Alibaba Cloud resources such as ECS, Cloud Monitor, OOS and other services through seamless integration with Alibaba Cloud APIs via the Model Context Protocol.
by heroku
Enables large language models to manage and operate Heroku platform resources directly through the Heroku CLI, exposing a set of tools for app, dyno, add‑on, pipeline, database, and team operations.
by aws-samples
Retrieve PDF documents and other S3 objects through Model Context Protocol resources, enabling LLMs to pull data directly from AWS S3 buckets.