DEV Community

Cover image for I Built an AI Agent to Reduce My AWS, GCP and Azure Bills (MCP + FastAPI)
Moiz Ali Moomin
Moiz Ali Moomin

Posted on

I Built an AI Agent to Reduce My AWS, GCP and Azure Bills (MCP + FastAPI)

*I gave this one prompt to an AI… and the results honestly surprised me:
*

*fetch 90 days data for aws cost and billing and give recommendation for better cost optimization
*

🚀 I Built an MCP Server That Analyzes AWS Costs Using AI (FastAPI + FinOps)

You can visit my repo the link is below:

https://github.com/Moiz-Ali-Moomin/mcp-cloud-finops-ai-agent

*Cloud bills are confusing.
*

Most of us don’t realize:
• where money is being wasted
• which resources are idle
• what to actually fix

So I built something to solve this.

👉 An MCP (Model Context Protocol) server + AI agent that analyzes AWS costs and gives actionable optimization recommendations.


*🤖 What I Built
*

I created an MCP server using FastAPI that:

• connects with AWS billing and infrastructure data
• allows an AI agent to analyze usage
• returns real optimization insights
• provides exact CLI commands to fix issues


*⚡ How It Works
*

  1. MCP server exposes tools (billing + infra data)
  2. AI agent calls these tools
  3. Data is analyzed (90 days usage)
  4. System generates: • cost insights • anomalies • optimization suggestions

*🧪 The Prompt
*

I gave a simple instruction:

“Fetch 90 days AWS cost and suggest optimizations”


*📊 What the System Returned
*

• Total spend: $11.44
• Top cost driver: EC2-Other
• Estimated savings: ~40%

👉 Almost half the cost could be optimized.


*🔍 Key Insights (Automatically Generated)
*

  1. AWS Cost Explorer was costing money
    • I was paying just to query billing data
    • Suggested fix: use S3 Cost & Usage Reports + caching

  2. Unused resources detected
    • orphaned EBS volumes
    • unused Elastic IPs
    • idle infra

Suggested command:
aws ec2 describe-volumes --filters Name=status,Values=available

  1. Idle NAT Gateway • charging even without usage

Suggested fix:
terraform destroy

  1. Cost spikes explained • Jan spike → ECS usage • March spike → Kubernetes testing

👉 AI correlated infra activity with billing automatically


*🧠 Why MCP Makes This Powerful
*

Instead of hardcoding logic:

• MCP enables tool-based architecture
• AI dynamically decides what to fetch and analyze
• system becomes flexible and extensible


💻 Example Output

{
"resource": "EC2",
"issue": "Underutilized",
"recommendation": "Downgrade instance",
"estimated_savings": "30%"
}


*🧪 Try It Yourself
*

GitHub repo:
https://github.com/Moiz-Ali-Moomin/mcp-cloud-finops-ai-agent/

Steps:

  1. git clone https://github.com/Moiz-Ali-Moomin/mcp-cloud-finops-ai-agent
  2. pip install -r requirements.txt
  3. uvicorn main:app --reload

*🤝 Contributing
*

If this sounds interesting, contributions are welcome.

You can help by:

• adding support for more cloud services
• improving cost analysis logic
• building a frontend/dashboard
• adding auto-remediation features

Feel free to:
• open issues
• suggest improvements
• submit pull requests

👉 Even small contributions are appreciated.


*🚀 What’s Next
*

• real-time monitoring
• multi-cloud support
• auto-remediation (AI fixing issues automatically)


*💬 Final Thoughts
*

Before this, cloud cost optimization meant:
• dashboards
• manual effort
• guesswork

Now it’s:

👉 Ask AI → get exact fixes


If you're into DevOps, cloud, or AI agents, would love your feedback.

Top comments (0)