Skip to main content

MCP server for Prometheus integration

Project description

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.

Prometheus Server MCP server

Features

  • Execute PromQL queries against Prometheus

  • Discover and explore metrics

    • List available metrics
    • Get metadata for specific metrics
    • 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

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.

Installation

Option 1: Install from PyPI (Recommended)

# Using uvx (recommended for Claude Desktop)
uvx prometheus-mcp-server

# Using pip
pip install prometheus-mcp-server

# Using uv
uv add prometheus-mcp-server

Option 2: Install from Source

# Clone the repository
git clone https://github.com/raihan0824/prometheus-mcp-server.git
cd prometheus-mcp-server

# Install with uv
uv pip install -e .

# Or install with pip
pip install -e .

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: 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: Custom MCP configuration
PROMETHEUS_MCP_SERVER_TRANSPORT=stdio # Choose between http, stdio, sse. If undefined, stdio is set as the default transport.

# Optional: Only relevant for non-stdio transports
PROMETHEUS_MCP_BIND_HOST=localhost # if undefined, 127.0.0.1 is set by default.
PROMETHEUS_MCP_BIND_PORT=8080 # if undefined, 8080 is set by default.

# 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:

Option A: Using uvx with PyPI package (Recommended)

{
  "mcpServers": {
    "prometheus": {
      "command": "uvx",
      "args": [
        "prometheus-mcp-server"
      ],
      "env": {
        "PROMETHEUS_URL": "<your-prometheus-url>",
        "PROMETHEUS_USERNAME": "<your-username>",
        "PROMETHEUS_PASSWORD": "<your-password>"
      }
    }
  }
}

Option B: Using uvx with local repository

{
  "mcpServers": {
    "prometheus": {
      "command": "uvx",
      "args": [
        "--directory",
        "/path/to/prometheus-mcp-server",
        "run",
        "prometheus-mcp-server"
      ],
      "env": {
        "PROMETHEUS_URL": "<your-prometheus-url>",
        "PROMETHEUS_USERNAME": "<your-username>",
        "PROMETHEUS_PASSWORD": "<your-password>"
      }
    }
  }
}

Option C: Using uvx with Git repository

{
  "mcpServers": {
    "prometheus": {
      "command": "uvx",
      "args": [
        "run",
        "--from",
        "git+https://github.com/raihan0824/prometheus-mcp-server.git",
        "prometheus-mcp-server"
      ],
      "env": {
        "PROMETHEUS_URL": "<your-prometheus-url>",
        "PROMETHEUS_USERNAME": "<your-username>",
        "PROMETHEUS_PASSWORD": "<your-password>"
      }
    }
  }
}

Option D: Using Docker (Legacy)

{
  "mcpServers": {
    "prometheus": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "PROMETHEUS_URL",
        "ghcr.io/pab1it0/prometheus-mcp-server:latest"
      ],
      "env": {
        "PROMETHEUS_URL": "<url>",
        "PROMETHEUS_MCP_SERVER_TRANSPORT": "http",
        "PROMETHEUS_MCP_BIND_HOST": "localhost",
        "PROMETHEUS_MCP_BIND_PORT": "8080"
      }
    }
  }
}

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
├── Dockerfile               # Docker configuration
├── docker-compose.yml       # Docker Compose configuration
├── .dockerignore            # Docker ignore file
├── 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

Tool Category Description
execute_query Query Execute a PromQL instant query against Prometheus
execute_range_query Query Execute a PromQL range query with start time, end time, and step interval
list_metrics Discovery List all available metrics in Prometheus
get_metric_metadata Discovery Get metadata for a specific metric
get_targets Discovery Get information about all scrape targets

License

MIT


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

raihan0824_prometheus_mcp_server-1.2.4.tar.gz (20.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file raihan0824_prometheus_mcp_server-1.2.4.tar.gz.

File metadata

File hashes

Hashes for raihan0824_prometheus_mcp_server-1.2.4.tar.gz
Algorithm Hash digest
SHA256 301264e5ac0da1bca255b7584b46f262c3fe2392eb451430a1134afe03e01dcb
MD5 38be0957d587afd1cf8597b88dd458c9
BLAKE2b-256 4a9852e8b6d4adb0fe0b883bedcf7b3312abab6fa897b48b61b4c27eac86aa2a

See more details on using hashes here.

File details

Details for the file raihan0824_prometheus_mcp_server-1.2.4-py3-none-any.whl.

File metadata

File hashes

Hashes for raihan0824_prometheus_mcp_server-1.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 3d4a22961dc5a4687949a3b9c38a4222a67b4a6381659b41e4a24949830860f5
MD5 78857304d1f883b71e3d22baebe15d88
BLAKE2b-256 4899ada1b57090ec39d307da0a4b18207a4a160a2f264d22822fe56cad2c516c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page