AWS Cost Explorer and Bedrock Usage Analytics

by aarora79

84 stars
484 downloads
Not rated
GitHub

About

Integrates with AWS Cost Explorer and CloudWatch to analyze cloud spending patterns and Bedrock model usage statistics for detailed cost monitoring and optimization.

Details

Author
aarora79
Repository
aarora79/aws-cost-explorer-mcp-server
GitHub stars
84
Downloads
484
License
MIT License
Categories
Cloud Service, Other, Infrastructure, Design, Developer Tools, AI, API
Tags
#analytics

- Amazon EC2 Spend Analysis: View detailed breakdowns of EC2 spending for the last day
- Amazon Bedrock Spend Analysis: View breakdown by region, users and models over the last 30 days
- Service Spend Reports: Analyze spending across all AWS services for the last 30 days
- Detailed Cost Breakdown: Get granular cost data by day, region, service, and instance type
- Interactive Interface: Use Claude to query your cost data through natural language

Setting up with Highlight

This MCP is not yet compatible with Highlight’s one-click setup. However, you can still use it with Highlight by following these steps:

  1. Download and install Highlight from highlightai.com/download
  2. Navigate to the plugins tab and select "Add Custom Plugin"
  3. Configure the plugin with the settings below
    Plugin Name AWS Cost Explorer and Bedrock Usage Analytics
    Command (node, npx, python, etc.) docker
    Arguments
    • Argument 1 run
    • Argument 2 -i
    • Argument 3 --rm
    • Argument 4 -e
    • Argument 5 AWS_ACCESS_KEY_ID
    • Argument 6 -e
    • Argument 7 AWS_SECRET_ACCESS_KEY
    • Argument 8 -e
    • Argument 9 AWS_REGION
    • Argument 10 -e
    • Argument 11 BEDROCK_LOG_GROUP_NAME
    • Argument 12 -e
    • Argument 13 MCP_TRANSPORT
    • Argument 14 -e
    • Argument 15 CROSS_ACCOUNT_ROLE_NAME
    • Argument 16 aws-cost-explorer-mcp:latest
    Environment
    • AWS_REGION us-east-1
    • MCP_TRANSPORT stdio
    • AWS_ACCESS_KEY_ID YOUR_ACCESS_KEY_ID
    • AWS_SECRET_ACCESS_KEY YOUR_SECRET_ACCESS_KEY
    • BEDROCK_LOG_GROUP_NAME YOUR_CLOUDWATCH_BEDROCK_MODEL_INVOCATION_LOG_GROUP_NAME
    • CROSS_ACCOUNT_ROLE_NAME ROLE_NAME_FOR_THE_ROLE_TO_ASSUME_IN_OTHER_ACCOUNTS

    Please refer to the README for specific instructions on how to obtain API keys or other required environment variables.

  4. Enable "Start Automatically" if you want the plugin to start when Highlight launches

From the repository

``
If you useAWS IAM Identity Center, follow the docs to configure your short-term credentials

Uses stdio as a transport for MCP, both the MCP server and client are running on your local machine.

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

Uses sse` as a transport for MCP, the MCP servers on EC2 and the client is running on your local machine. Note that Claude Desktop does not support remote MCP servers at this time (see this GitHub issue).

get_ec2_spend_last_day()

Retrieves EC2 spending data for the previous day.

get_detailed_breakdown_by_day(days=7)

Delivers a comprehensive analysis of costs by region, service, and instance type.

get_bedrock_daily_usage_stats(days=7, region='us-east-1', log_group_name='BedrockModelInvocationLogGroup')

Delivers a per-day breakdown of model usage by region and users.

get_bedrock_hourly_usage_stats(days=7, region='us-east-1', log_group_name='BedrockModelInvocationLogGroup')

Delivers a per-day per-hour breakdown of model usage by region and users.

The server exposes the following tools that Claude can use:

1. get_ec2_spend_last_day(): Retrieves EC2 spending data for the previous day
1. get_detailed_breakdown_by_day(days=7): Delivers a comprehensive analysis of costs by region, service, and instance type
1. get_bedrock_daily_usage_stats(days=7, region='us-east-1', log_group_name='BedrockModelInvocationLogGroup'): Delivers a per-day breakdown of model usage by region and users.
1. get_bedrock_hourly_usage_stats(days=7, region='us-east-1', log_group_name='BedrockModelInvocationLogGroup'): Delivers a per-day per-hour breakdown of model usage by region and users.

Claude Desktop / Cursor

Paste into your MCP client config file to install this server.

{
    "mcpServers": {
        "aws cost explorer and bedrock usage analytics": {
            "env": {
                "AWS_REGION": "us-east-1",
                "MCP_TRANSPORT": "stdio",
                "AWS_ACCESS_KEY_ID": "YOUR_ACCESS_KEY_ID",
                "AWS_SECRET_ACCESS_KEY": "YOUR_SECRET_ACCESS_KEY",
                "BEDROCK_LOG_GROUP_NAME": "YOUR_CLOUDWATCH_BEDROCK_MODEL_INVOCATION_LOG_GROUP_NAME",
                "CROSS_ACCOUNT_ROLE_NAME": "ROLE_NAME_FOR_THE_ROLE_TO_ASSUME_IN_OTHER_ACCOUNTS"
            },
            "args": [
                "run",
                "-i",
                "--rm",
                "-e",
                "AWS_ACCESS_KEY_ID",
                "-e",
                "AWS_SECRET_ACCESS_KEY",
                "-e",
                "AWS_REGION",
                "-e",
                "BEDROCK_LOG_GROUP_NAME",
                "-e",
                "MCP_TRANSPORT",
                "-e",
                "CROSS_ACCOUNT_ROLE_NAME",
                "aws-cost-explorer-mcp:latest"
            ],
            "command": "docker"
        }
    }
}

Linux

{
    "env": {
        "AWS_REGION": "us-east-1",
        "MCP_TRANSPORT": "stdio",
        "AWS_ACCESS_KEY_ID": "YOUR_ACCESS_KEY_ID",
        "AWS_SECRET_ACCESS_KEY": "YOUR_SECRET_ACCESS_KEY",
        "BEDROCK_LOG_GROUP_NAME": "YOUR_CLOUDWATCH_BEDROCK_MODEL_INVOCATION_LOG_GROUP_NAME",
        "CROSS_ACCOUNT_ROLE_NAME": "ROLE_NAME_FOR_THE_ROLE_TO_ASSUME_IN_OTHER_ACCOUNTS"
    },
    "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "AWS_ACCESS_KEY_ID",
        "-e",
        "AWS_SECRET_ACCESS_KEY",
        "-e",
        "AWS_REGION",
        "-e",
        "BEDROCK_LOG_GROUP_NAME",
        "-e",
        "MCP_TRANSPORT",
        "-e",
        "CROSS_ACCOUNT_ROLE_NAME",
        "aws-cost-explorer-mcp:latest"
    ],
    "command": "docker"
}

Macos

{
    "env": {
        "AWS_REGION": "us-east-1",
        "MCP_TRANSPORT": "stdio",
        "AWS_ACCESS_KEY_ID": "YOUR_ACCESS_KEY_ID",
        "AWS_SECRET_ACCESS_KEY": "YOUR_SECRET_ACCESS_KEY",
        "BEDROCK_LOG_GROUP_NAME": "YOUR_CLOUDWATCH_BEDROCK_MODEL_INVOCATION_LOG_GROUP_NAME",
        "CROSS_ACCOUNT_ROLE_NAME": "ROLE_NAME_FOR_THE_ROLE_TO_ASSUME_IN_OTHER_ACCOUNTS"
    },
    "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "AWS_ACCESS_KEY_ID",
        "-e",
        "AWS_SECRET_ACCESS_KEY",
        "-e",
        "AWS_REGION",
        "-e",
        "BEDROCK_LOG_GROUP_NAME",
        "-e",
        "MCP_TRANSPORT",
        "-e",
        "CROSS_ACCOUNT_ROLE_NAME",
        "aws-cost-explorer-mcp:latest"
    ],
    "command": "docker"
}

Windows

{
    "env": {
        "AWS_REGION": "us-east-1",
        "MCP_TRANSPORT": "stdio",
        "AWS_ACCESS_KEY_ID": "YOUR_ACCESS_KEY_ID",
        "AWS_SECRET_ACCESS_KEY": "YOUR_SECRET_ACCESS_KEY",
        "BEDROCK_LOG_GROUP_NAME": "YOUR_CLOUDWATCH_BEDROCK_MODEL_INVOCATION_LOG_GROUP_NAME",
        "CROSS_ACCOUNT_ROLE_NAME": "ROLE_NAME_FOR_THE_ROLE_TO_ASSUME_IN_OTHER_ACCOUNTS"
    },
    "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "AWS_ACCESS_KEY_ID",
        "-e",
        "AWS_SECRET_ACCESS_KEY",
        "-e",
        "AWS_REGION",
        "-e",
        "BEDROCK_LOG_GROUP_NAME",
        "-e",
        "MCP_TRANSPORT",
        "-e",
        "CROSS_ACCOUNT_ROLE_NAME",
        "aws-cost-explorer-mcp:latest"
    ],
    "command": "docker"
}

Usage

Prerequisites

1. Setup model invocation logs in Amazon CloudWatch.
1. Ensure that the IAM user/role being used has full read-only access to Amazon Cost Explorer and Amazon CloudWatch, this is required for the MCP server to retrieve data from these services.
See here and here for sample policy examples that you can use & modify as per your requirements.
1. To allow your MCP server to access AWS spend information from other accounts set the the CROSS_ACCOUNT_ROLE_NAME parameter while starting the server and now you can provide the account AWS account id for another account while interacting with your agent and then agent will pass the account id to the server.

Local setup

Uses stdio as a transport for MCP, both the MCP server and client are running on your local machine.

Starting the Server (local)

Run the server using:

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 # can be ignored if you do not want AWS spend info from other accounts
python server.py

Claude Desktop Configuration

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

Option 1: Using Docker

Add the following to your Claude Desktop configuration file. The file can be found out these paths depending upon you operating system.

- macOS: ~/Library/Application Support/Claude/claude_desktop_config.json.
- Windows: %APPDATA%\Claude\claude_desktop_config.json.
- Linux: ~/.config/Claude/claude_desktop_config.json.

{
  "mcpServers": {
    "aws-cost-explorer": {
      "command": "docker",
      "args": [ "run", "-i", "--rm", "-e", "AWS_ACCESS_KEY_ID", "-e", "AWS_SECRET_ACCESS_KEY", "-e", "AWS_REGION", "-e", "BEDROCK_LOG_GROUP_NAME", "-e", "MCP_TRANSPORT", "-e", "CROSS_ACCOUNT_ROLE_NAME", "aws-cost-explorer-mcp:latest" ],
      "env": {
        "AWS_ACCESS_KEY_ID": "YOUR_ACCESS_KEY_ID",
        "AWS_SECRET_ACCESS_KEY": "YOUR_SECRET_ACCESS_KEY",
        "AWS_REGION": "us-east-1",
        "BEDROCK_LOG_GROUP_NAME": "YOUR_CLOUDWATCH_BEDROCK_MODEL_INVOCATION_LOG_GROUP_NAME",
        "CROSS_ACCOUNT_ROLE_NAME": "ROLE_NAME_FOR_THE_ROLE_TO_ASSUME_IN_OTHER_ACCOUNTS",
        "MCP_TRANSPORT": "stdio"
      }
    }
  }
}

> IMPORTANT: Replace YOUR_ACCESS_KEY_ID and YOUR_SECRET_ACCESS_KEY with your actual AWS credentials. Never commit actual credentials to version control.

Option 2: Using UV (without Docker)

If you prefer to run the server directly without Docker, you can use UV:

{
  "mcpServers": {
    "aws_cost_explorer": {
      "command": "uv",
      "args": [
          "--directory",
          "/path/to/aws-cost-explorer-mcp-server",
          "run",
          "server.py"
      ],
      "env": {
        "AWS_ACCESS_KEY_ID": "YOUR_ACCESS_KEY_ID",
        "AWS_SECRET_ACCESS_KEY": "YOUR_SECRET_ACCESS_KEY",
        "AWS_REGION": "us-east-1",
        "BEDROCK_LOG_GROUP_NAME": "YOUR_CLOUDWATCH_BEDROCK_MODEL_INVOCATION_LOG_GROUP_NAME",
        "CROSS_ACCOUNT_ROLE_NAME": "ROLE_NAME_FOR_THE_ROLE_TO_ASSUME_IN_OTHER_ACCOUNTS",
        "MCP_TRANSPORT": "stdio"
      }
    }
  }
}

Make sure to replace the directory path with the actual path to your repository on your system.

Remote setup

Uses sse as a transport for MCP, the MCP servers on EC2 and the client is running on your local machine. Note that Claude Desktop does not support remote MCP servers at this time (see this GitHub issue).

Starting the Server (remote)

You can start a remote MCP server on Amazon EC2 by following the same instructions as above. Make sure to set the MCP_TRANSPORT as sse (server side events) as shown below. Note that the MCP uses JSON-RPC 2.0 as its wire format, therefore the protocol itself does not include authorization and authentication (see this GitHub issue), do not send or receive sensitive data over MCP.

Run the server using:

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 # can be ignored if you do not want AWS spend info from other accounts
python server.py

1. The MCP server will start listening on TCP port 8000.
1. Configure an ingress rule in the security group associated with your EC2 instance to allow access to TCP port 8000 from your local machine (where you are running the MCP client/LangGraph based app) to your EC2 instance.

>Also see section on running a "secure" remote MCP server i.e. a server to which your MCP clients can connect over HTTPS.

Testing with a CLI MCP client

You can test your remote MCP server with the mcp_sse_client.py script. Running this script will print the list of tools available from the MCP server and an output for the get_bedrock_daily_usage_stats tool.

```{.bashrc}

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.