
CFM Tips - Cost Optimization MCP Server
A comprehensive Model Context Protocol server that analyzes AWS costs and provides optimization recommendations by integrating with services like Cost Explorer, Cost Optimization Hub, and Trusted Advisor.
README
CFM Tips - Cost Optimization MCP Server
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.
🚀 Quick Start
# 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
# Add the MCP server config to Amazon Q using the mcp_runbooks.json as a template
vi ~/.aws/amazonq/mcp.json
# Example usage in Q chat:
"Run comprehensive cost analysis for us-east-1"
"Find unused EBS volumes costing money"
"Generate EC2 right-sizing report in markdown"
🧩 Add-on MCPs
Add-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"
✅ Features
Core AWS Services Integration
- Cost Explorer - Retrieve cost data and usage metrics
- Cost Optimization Hub - Get AWS cost optimization recommendations
- Compute Optimizer - Right-sizing recommendations for compute resources
- Trusted Advisor - Cost optimization checks and recommendations
- Performance Insights - RDS performance metrics and analysis
- CUR Reports - Cost and Usage Report analysis from S3
Cost Optimization Playbooks
- 🔧 EC2 Right Sizing - Identify underutilized EC2 instances
- 💾 EBS Optimization - Find unused and underutilized volumes
- 🗄️ RDS Optimization - Identify idle and underutilized databases
- ⚡ Lambda Optimization - Find overprovisioned and unused functions
- 📊 Comprehensive Analysis - Multi-service cost analysis
Advanced Features
- Real CloudWatch Metrics - Uses actual AWS metrics for analysis
- Multiple Output Formats - JSON and Markdown report generation
- Cost Calculations - Estimated savings and cost breakdowns
- Actionable Recommendations - Priority-based optimization suggestions
📁 Project Structure
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
🔐 Required AWS Permissions
Your AWS credentials need these permissions. The MCP server uses your role to perform actions, hence proceed with least privilege access only. 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"
],
"Resource": "*"
}
]
}
🛠️ Installation
Prerequisites
- Python 3.11 or higher
- AWS CLI configured with appropriate credentials
- Amazon Q CLI (for MCP integration) - https://docs.aws.amazon.com/amazonq/latest/qdeveloper-ug/command-line-installing.html
Setup Steps
-
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
- Create an IAM policy with the permissions listed above
- Attach the policy to your IAM user or role
-
Test the Installation
python3 test_runbooks.py
-
Start the MCP Server
python3 mcp_server_with_runbooks.py &
-
Start the Q Chat
q chat
🔧 Available Tools
Cost Analysis Tools
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 recommendations
EC2 Optimization
ec2_rightsizing
- Analyze EC2 instances for right-sizing opportunitiesec2_report
- Generate detailed EC2 optimization reports
EBS Optimization
ebs_optimization
- Analyze EBS volumes for optimizationebs_unused
- Identify unused EBS volumesebs_report
- Generate EBS optimization reports
RDS Optimization
rds_optimization
- Analyze RDS instances for optimizationrds_idle
- Identify idle RDS instancesrds_report
- Generate RDS optimization reports
Lambda Optimization
lambda_optimization
- Analyze Lambda functions for optimizationlambda_unused
- Identify unused Lambda functionslambda_report
- Generate Lambda optimization reports
Comprehensive Analysis
comprehensive_analysis
- Multi-service cost analysis
Additional Tools
list_cur_reports
- List Cost and Usage Reports in S3get_trusted_advisor_checks
- Get Trusted Advisor recommendationsget_performance_insights_metrics
- Get RDS Performance Insights data
📊 Example Usage
Basic Cost Analysis
"Get my AWS costs for the last month"
"Show me cost optimization recommendations"
"What are my biggest cost drivers?"
Resource Optimization
"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"
Report Generation
"Generate a comprehensive cost optimization report"
"Create an EC2 right-sizing report in markdown format"
"Generate an EBS optimization report with cost savings"
Multi-Service Analysis
"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"
🔍 Troubleshooting
Common Issues
-
Cost Optimization Hub Not Working
python3 diagnose_cost_optimization_hub_v2.py
-
No Metrics Found
- Ensure resources have been running for at least 14 days
- Verify CloudWatch metrics are enabled
- Check that you're analyzing the correct region
-
Permission Errors
- Verify IAM permissions are correctly applied
- Check AWS credentials configuration
- Ensure Cost Optimization Hub is enabled in AWS Console
-
Import Errors
# Check Python path and dependencies python3 -c "import boto3, mcp; print('Dependencies OK')"
Getting Help
- Check the RUNBOOKS_GUIDE.md for detailed usage instructions
- Run the diagnostic script:
python3 diagnose_cost_optimization_hub_v2.py
- Run integration tests:
python3 test_runbooks.py
🎯 Key Benefits
- Immediate Cost Savings - Identify unused resources for deletion
- Right-Sizing Opportunities - Optimize overprovisioned resources
- Real Metrics Analysis - Uses actual CloudWatch data
- Actionable Reports - Clear recommendations with cost estimates
- Comprehensive Coverage - Analyze EC2, EBS, RDS, Lambda, and more
- Easy Integration - Works seamlessly with Amazon Q CLI
📈 Expected Results
The CFM Tips cost optimization server can help you:
- Identify cost savings on average
- Find unused resources costing hundreds of dollars monthly
- Right-size overprovisioned instances for optimal performance/cost ratio
- Optimize storage costs through volume type recommendations
- Eliminate idle resources that provide no business value
🤝 Contributing
We welcome contributions! Please see our contributing guidelines:
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Submit a pull request
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.