prometheus-mcp-server

drewstreib/prometheus-mcp-server

3.2

If you are the rightful owner of prometheus-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

A Model Context Protocol (MCP) server for Prometheus, providing standardized access to Prometheus metrics and queries.

Tools
5
Resources
0
Prompts
0

Prometheus MCP Server

A Model Context Protocol (MCP) server for Prometheus.

This provides access to your Prometheus metrics and queries through standardized MCP interfaces, allowing AI assistants to execute PromQL queries and analyze your metrics data.

Features

  • Execute PromQL queries against Prometheus
  • Discover and explore metrics
    • List available metrics
    • Get metadata for specific metrics
    • Get documentation - Primary discovery endpoint with query patterns
    • View instant query results
    • View range query results with different step intervals
  • Authentication support
    • Basic auth from environment variables
    • Bearer token auth from environment variables
  • Docker containerization support
  • Provide interactive tools for AI assistants

Recommended for AI/LLM Usage

When using this MCP server with AI assistants like Claude, start with the get_documentation tool. This is the primary discovery endpoint that provides:

  • Complete PromQL reference and usage patterns
  • System monitoring queries and examples
  • Specialized monitoring guides for specific contexts

For specialized monitoring contexts:

  • Power/Energy/Lab/UPS/Battery questions: Use get_documentation("victron") for Victron MultiPlus power system monitoring
  • Temperature/HVAC/Climate/Weather questions: Use get_documentation("weather") for Ecobee thermostat and environmental sensor monitoring

Example prompts for Claude:

Use get_documentation to show me what kinds of queries I can make with Prometheus
Use get_documentation("victron") to learn about power monitoring
Use get_documentation("weather") to learn about temperature and HVAC monitoring

The list of tools is configurable, so you can choose which tools you want to make available to the MCP client. This is useful if you don't use certain functionality or if you don't want to take up too much of the context window.

Usage

  1. Ensure your Prometheus server is accessible from the environment where you'll run this MCP server.

  2. Configure the environment variables for your Prometheus server, either through a .env file or system environment variables:

# Required: Prometheus configuration
PROMETHEUS_URL=http://your-prometheus-server:9090

# Optional: MCP Server configuration (defaults shown)
FASTMCP_HOST=0.0.0.0
FASTMCP_PORT=8080

# Optional: Authentication credentials (if needed)
# Choose one of the following authentication methods if required:

# For basic auth
PROMETHEUS_USERNAME=your_username
PROMETHEUS_PASSWORD=your_password

# For bearer token auth
PROMETHEUS_TOKEN=your_token

# Optional: For multi-tenant setups like Cortex, Mimir or Thanos
ORG_ID=your_organization_id
  1. Add the server configuration to your client configuration file. For example, for Claude Desktop:
{
  "mcpServers": {
    "prometheus": {
      "url": "http://localhost:8080"
    }
  }
}

Or if running the server manually, you can also use the command-based approach:

{
  "mcpServers": {
    "prometheus": {
      "command": "uv",
      "args": [
        "--directory",
        "<full path to prometheus-mcp-server directory>",
        "run",
        "src/prometheus_mcp_server/main.py"
      ],
      "env": {
        "PROMETHEUS_URL": "http://your-prometheus-server:9090",
        "PROMETHEUS_USERNAME": "your_username",
        "PROMETHEUS_PASSWORD": "your_password",
        "FASTMCP_PORT": "8080"
      }
    }
  }
}

Using with Claude Desktop

Important: Claude Desktop only supports stdio transport natively, but this server runs with HTTP transport. To bridge this gap, you can use the mcp-remote package which acts as a proxy between Claude Desktop and HTTP MCP servers.

Option 1: Using mcp-remote Bridge (Recommended)

  1. First, start your Prometheus MCP server (either locally or via Docker):
# Using local installation
FASTMCP_HOST=0.0.0.0 FASTMCP_PORT=8080 PROMETHEUS_URL=http://your-prometheus-server:9090 uv run src/prometheus_mcp_server/main.py

# Or using Docker
docker run -d --name prometheus-mcp \
  -p 8080:8080 \
  -e PROMETHEUS_URL=http://your-prometheus-server:9090 \
  -e PROMETHEUS_USERNAME=your_username \
  -e PROMETHEUS_PASSWORD=your_password \
  prometheus-mcp-server
  1. Configure Claude Desktop to use the mcp-remote bridge by editing your Claude Desktop configuration file at ~/Library/Application Support/Claude/claude_desktop_config.json:
{
  "mcpServers": {
    "prometheus": {
      "command": "npx",
      "args": [
        "mcp-remote",
        "http://localhost:8080"
      ]
    }
  }
}

Option 2: Direct Remote MCP (Claude Pro/Team/Enterprise only)

If you have Claude Pro, Team, or Enterprise, you can use the built-in remote MCP support:

  1. Deploy your Prometheus MCP server to a publicly accessible endpoint
  2. In Claude Desktop, go to Settings > Integrations
  3. Add your remote MCP server URL (e.g., https://your-server.com:8080)

Troubleshooting Claude Desktop Integration

  • mcp-remote not found: Install it globally with npm install -g mcp-remote
  • Connection issues: Ensure your Prometheus MCP server is running and accessible on the specified port
  • Authentication errors: Verify your Prometheus credentials are correct and the Prometheus server is reachable

Docker Usage

This project includes Docker support for easy deployment and isolation.

Using Docker Images

You can use pre-built Docker images or build your own locally.

Building the Docker Image Locally

If you prefer to build the image yourself:

docker build -t prometheus-mcp-server .

Running with Docker

You can run the server using Docker in several ways:

Using docker run:
docker run -d --name prometheus-mcp \
  -p 8080:8080 \
  -e PROMETHEUS_URL=http://your-prometheus-server:9090 \
  -e PROMETHEUS_USERNAME=your_username \
  -e PROMETHEUS_PASSWORD=your_password \
  prometheus-mcp-server
Using docker-compose:

Create a docker-compose.yml file:

version: '3.8'
services:
  prometheus-mcp:
    image: prometheus-mcp-server
    ports:
      - "8080:8080"
    environment:
      - PROMETHEUS_URL=http://your-prometheus-server:9090
      - PROMETHEUS_USERNAME=your_username
      - PROMETHEUS_PASSWORD=your_password
    restart: unless-stopped

Then run:

docker-compose up -d

Running with Docker in Claude Desktop

To use the containerized server with Claude Desktop, first start the container:

docker run -d --name prometheus-mcp \
  -p 8080:8080 \
  -e PROMETHEUS_URL=http://your-prometheus-server:9090 \
  -e PROMETHEUS_USERNAME=your_username \
  -e PROMETHEUS_PASSWORD=your_password \
  prometheus-mcp-server

Then configure Claude Desktop to use the HTTP endpoint:

{
  "mcpServers": {
    "prometheus": {
      "url": "http://localhost:8080"
    }
  }
}

Attribution

This project is based on the original work by Pavel Shklovsky (pab1it0). See for full attribution details.

Development

Contributions are welcome! Please open an issue or submit a pull request if you have any suggestions or improvements.

This project uses uv to manage dependencies. Install uv following the instructions for your platform:

curl -LsSf https://astral.sh/uv/install.sh | sh

You can then create a virtual environment and install the dependencies with:

uv venv
source .venv/bin/activate  # On Unix/macOS
.venv\Scripts\activate     # On Windows
uv pip install -e .

Project Structure

The project has been organized with a src directory structure:

prometheus-mcp-server/
ā”œā”€ā”€ src/
│   └── prometheus_mcp_server/
│       ā”œā”€ā”€ __init__.py      # Package initialization
│       ā”œā”€ā”€ server.py        # MCP server implementation
│       ā”œā”€ā”€ main.py          # Main application logic
│       └── metrics.json     # Metrics documentation database
ā”œā”€ā”€ docs-mcp/                # Machine-readable documentation
│   ā”œā”€ā”€ usage.md            # Complete usage guide and PromQL reference
│   ā”œā”€ā”€ victron.md          # Victron power system monitoring guide
│   └── weather.md          # Environmental sensors and HVAC monitoring
ā”œā”€ā”€ docs-for-humans/         # Human-readable documentation
ā”œā”€ā”€ tests/                   # Test suite
ā”œā”€ā”€ Dockerfile               # Docker configuration
ā”œā”€ā”€ pyproject.toml           # Project configuration
└── README.md                # This file

Testing

The project includes a comprehensive test suite that ensures functionality and helps prevent regressions.

Run the tests with pytest:

# Install development dependencies
uv pip install -e ".[dev]"

# Run the tests
pytest

# Run with coverage report
pytest --cov=src --cov-report=term-missing

Tests are organized into:

  • Configuration validation tests
  • Server functionality tests
  • Error handling tests
  • Main application tests

When adding new features, please also add corresponding tests.

Tools

ToolCategoryDescription
get_documentationDiscoveryPrimary discovery endpoint - start here for query examples and patterns
execute_queryQueryExecute a PromQL instant query against Prometheus
execute_range_queryQueryExecute a PromQL range query with start time, end time, and step interval
list_metricsDiscoveryList all available metrics in Prometheus
get_metric_metadataDiscoveryGet metadata for a specific metric
get_seriesDiscoveryFind time series matching label selectors within a time range
get_targetsDiscoveryGet information about all scrape targets

License

MIT