Back to MCP Catalog

AWS Cost Explorer MCP Server

Cloud PlatformsPython
Analyze and visualize AWS cloud spending data through natural language queries
Available Tools

get_aws_spend_by_service

Retrieves AWS spending data broken down by service for a specified time period

get_aws_spend_by_day

Retrieves AWS spending data broken down by day for a specified time period

get_aws_spend_by_region

Retrieves AWS spending data broken down by region for a specified time period

get_ec2_spend_by_instance_type

Retrieves EC2 spending data broken down by instance type

get_bedrock_spend_by_model

Retrieves Amazon Bedrock spending data broken down by model

get_bedrock_spend_by_user

Retrieves Amazon Bedrock spending data broken down by user

get_bedrock_spend_by_region

Retrieves Amazon Bedrock spending data broken down by region

AWS Cost Explorer provides a convenient way to analyze and visualize AWS cloud spending data using natural language queries. It connects to AWS Cost Explorer API and Amazon CloudWatch to retrieve detailed cost information about your AWS services, with particular focus on EC2 instances and Amazon Bedrock usage. This tool allows you to get granular cost breakdowns by day, region, service, and instance type, making it easy to understand your cloud spending patterns. It can also access AWS spend information from multiple accounts when properly configured with cross-account roles.

Overview

AWS Cost Explorer MCP Server connects to AWS services to provide detailed cost analysis capabilities through natural language. It allows you to query your AWS spending data, analyze trends, and get insights about your cloud costs without having to navigate the AWS console or write complex queries.

Installation

Prerequisites

  1. Python 3.12
  2. AWS credentials with Cost Explorer access
  3. CloudWatch Logs access (for Bedrock model invocation logs)
  4. [Optional] Amazon Bedrock access (for LangGraph Agent)
  5. [Optional] Amazon EC2 for running a remote MCP server

Setup Steps

  1. Install uv package manager:
# On macOS and Linux
curl -LsSf https://astral.sh/uv/install.sh | sh

# On Windows
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
  1. Clone the repository:
git clone https://github.com/aarora79/aws-cost-explorer-mcp-server.git
cd aws-cost-explorer-mcp-server
  1. Set up the Python virtual environment and install dependencies:
uv venv --python 3.12
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
uv pip install --requirement pyproject.toml
  1. Configure your AWS credentials:
mkdir -p ~/.aws
# Set up your credentials in ~/.aws/credentials and ~/.aws/config

If you use AWS IAM Identity Center, follow the AWS documentation to configure your short-term credentials.

Configuration

AWS Permissions

Ensure that the IAM user/role being used has:

  • Read-only access to Amazon Cost Explorer
  • Read-only access to Amazon CloudWatch Logs

Model Invocation Logs

To analyze Bedrock usage, set up model invocation logs in Amazon CloudWatch following the AWS documentation.

Cross-Account Access

To access AWS spend information from other accounts:

  1. Create a role in each target account that your MCP server's role can assume
  2. Set the CROSS_ACCOUNT_ROLE_NAME parameter when starting the server

Usage

Local Setup (stdio transport)

Start the server with:

export MCP_TRANSPORT=stdio
export BEDROCK_LOG_GROUP_NAME=YOUR_BEDROCK_CW_LOG_GROUP_NAME
export CROSS_ACCOUNT_ROLE_NAME=ROLE_NAME_FOR_THE_ROLE_TO_ASSUME_IN_OTHER_ACCOUNTS
python server.py

Remote Setup (SSE transport)

For a more secure setup, you can run the MCP server remotely:

  1. Start the server on an EC2 instance:
export MCP_TRANSPORT=sse
export BEDROCK_LOG_GROUP_NAME=YOUR_BEDROCK_CW_LOG_GROUP_NAME
export CROSS_ACCOUNT_ROLE_NAME=ROLE_NAME_FOR_THE_ROLE_TO_ASSUME_IN_OTHER_ACCOUNTS
python server.py
  1. Configure a reverse proxy with HTTPS (e.g., using Nginx)

  2. Use the provided client scripts to connect to your remote server

Claude Desktop Integration

There are two ways to configure this tool with Claude Desktop:

Option 1: Using Docker

Add the following to your Claude Desktop configuration file (located at ~/Library/Application Support/Claude/claude_desktop_config.json on macOS or %APPDATA%\Claude\claude_desktop_config.js on Windows):

{
  "mcpServers": {
    "aws-cost-explorer": {
      "command": "docker",
      "args": [
        "run",
        "--rm",
        "-e",
        "AWS_PROFILE=YOUR_AWS_PROFILE",
        "-e",
        "BEDROCK_LOG_GROUP_NAME=YOUR_BEDROCK_CW_LOG_GROUP_NAME",
        "-e",
        "MCP_TRANSPORT=stdio",
        "-v",
        "~/.aws:/root/.aws",
        "aarora79/aws-cost-explorer-mcp-server:latest"
      ]
    }
  }
}

Option 2: Using Local Python

Add the following to your Claude Desktop configuration file:

{
  "mcpServers": {
    "aws-cost-explorer": {
      "command": "python",
      "args": [
        "/path/to/aws-cost-explorer-mcp-server/server.py"
      ],
      "env": {
        "MCP_TRANSPORT": "stdio",
        "BEDROCK_LOG_GROUP_NAME": "YOUR_BEDROCK_CW_LOG_GROUP_NAME"
      }
    }
  }
}

Example Queries

Once configured, you can ask Claude questions like:

  • "What was my total AWS spend in the last 30 days?"
  • "Show me a breakdown of EC2 costs by instance type"
  • "How much did I spend on Amazon Bedrock last month?"
  • "What's my daily spend trend for the past week?"
  • "Which AWS region has the highest costs?"
  • "Show me the spend for AWS account 123456789012"

Troubleshooting

  • Authentication Issues: Ensure your AWS credentials are properly configured and have the necessary permissions
  • Missing Data: Verify that Cost Explorer is enabled in your AWS account
  • Bedrock Data Not Showing: Confirm that model invocation logging is properly set up
  • Cross-Account Access: Check that the roles are properly configured and trust relationships are established

Related MCPs

AWS CLI
Cloud PlatformsPython

Execute AWS CLI commands securely through AI assistants

Kubernetes
Cloud PlatformsGo

Connect to and manage Kubernetes clusters through natural language

Cloudflare
Cloud PlatformsTypeScript

A Model Context Protocol server for Cloudflare services

About Model Context Protocol

Model Context Protocol (MCP) allows AI models to access external tools and services, extending their capabilities beyond their training data.

Generate Cursor Documentation

Save time on coding by generating custom documentation and prompts for Cursor IDE.