Prometheus MCP Server

repository·main·Indexed 19 days ago

https://github.com/pab1it0/prometheus-mcp-server

A Model Context Protocol (MCP) server that enables AI assistants to query and analyze Prometheus metrics using PromQL. It provides a standardized interface for metric discovery and data retrieval, supporting multiple transport modes (http, sse, stdio) and authentication methods including Basic Auth and Bearer tokens. Version 1.6.2.

Tokens
5.6K
Snippets
16
Records
26
Agent score
66%

What's inside prometheus-mcp-server

  1. Set up a development environment for Prometheus MCP Server

    main

    This project uses uv for dependency management. To set up a local development environment:

    1. Install uv:
      curl -LsSf https://astral.sh/uv/install.sh | sh
    2. Create a virtual environment and install dependencies:
      uv venv
      source .venv/bin/activate  # On Unix/macOS
      # .venv\Scripts\activate  # On Windows
      uv pip install -e .
    curl -LsSf https://astral.sh/uv/install.sh | sh
    
    uv venv
    source .venv/bin/activate
    uv pip install -e .
  2. Install Prometheus MCP Server via Claude Code CLI

    main

    You can install the server directly using the Claude Code CLI by providing the Prometheus URL as an environment variable.

    claude mcp add prometheus --env PROMETHEUS_URL=http://your-prometheus:9090 -- docker run -i --rm -e PROMETHEUS_URL ghcr.io/pab1it0/prometheus-mcp-server:latest
  3. Install Prometheus MCP Server in Claude Desktop

    main

    To use the Prometheus MCP server with Claude Desktop, add the following configuration to your claude_desktop_config.json file. This setup uses Docker to run the server and passes the PROMETHEUS_URL via environment variables.

    {
      "mcpServers": {
        "prometheus": {
          "command": "docker",
          "args": [
            "run",
            "-i",
            "--rm",
            "-e",
            "PROMETHEUS_URL",
            "ghcr.io/pab1it0/prometheus-mcp-server:latest"
          ],
          "env": {
            "PROMETHEUS_URL": "<your-prometheus-url>"
          }
        }
      }
    }
  4. Run tests for Prometheus MCP Server

    main

    The project uses pytest for testing. To run the test suite, first install the development dependencies, then execute pytest.

    # Install development dependencies
    uv pip install -e ".[dev]"
    
    # Run the tests
    pytest
    
    # Run with coverage report
    pytest --cov=src --cov-report=term-missing
  5. Deploy Prometheus MCP Server to Kubernetes via Helm

    main

    Deploy the server to a Kubernetes cluster using the official Helm chart from the OCI registry. You can set the Prometheus URL and authentication credentials via --set flags.

    # Basic installation
    helm install prometheus-mcp-server \
      oci://ghcr.io/pab1it0/charts/prometheus-mcp-server \
      --version 1.1.1 \
      --set prometheus.url="http://prometheus:9090"
    
    # Installation with authentication
    helm install prometheus-mcp-server \
      oci://ghcr.io/pab1it0/charts/prometheus-mcp-server \
      --version 1.1.1 \
      --set prometheus.url="http://prometheus:9090" \
      --set auth.username="admin" \
      --set auth.password="secret"
    
    # Installation with a custom values file
    helm install prometheus-mcp-server \
      oci://ghcr.io/pab1it0/charts/prometheus-mcp-server \
      --version 1.1.1 \
      -f values.yaml
  6. Install the Prometheus MCP Server Helm Chart

    main

    You can install the Prometheus MCP Server to your Kubernetes cluster using either the OCI registry or by cloning the source repository.

    Prerequisites

    • Kubernetes >= 1.19
    • Helm >= 3.0
    • A Prometheus instance accessible from the cluster

    Installation via OCI Registry

    Use the following command to install directly from the GitHub Container Registry:

    helm install prometheus-mcp-server \
      oci://ghcr.io/pab1it0/charts/prometheus-mcp-server \
      --set prometheus.url=http://prometheus:9090

    Installation from Source

    Clone the repository and install from the local chart directory:

    git clone https://github.com/pab1it0/prometheus-mcp-server.git
    cd prometheus-mcp-server
    
    helm install prometheus-mcp-server ./charts/prometheus-mcp-server \
      --set prometheus.url=http://prometheus:9090
    helm install prometheus-mcp-server \
      oci://ghcr.io/pab1it0/charts/prometheus-mcp-server \
      --set prometheus.url=http://prometheus:9090
  7. Install Prometheus MCP Server in VS Code, Cursor, or Windsurf

    main

    Add the server configuration to your IDE's MCP settings. This configuration runs the server via Docker.

    {
      "prometheus": {
        "command": "docker",
        "args": [
          "run",
          "-i",
          "--rm",
          "-e",
          "PROMETHEUS_URL",
          "ghcr.io/pab1it0/prometheus-mcp-server:latest"
        ],
        "env": {
          "PROMETHEUS_URL": "<your-prometheus-url>"
        }
      }
    }
  8. Configure Prometheus Connection settings

    main

    Configure how the MCP server connects to your Prometheus instance using the following parameters:

    ParameterDescriptionDefault
    prometheus.urlPrometheus server URL (required)http://prometheus:9090
    prometheus.sslVerifyEnable SSL verification"true"
    prometheus.disableLinksDisable Prometheus UI links in responses (saves context tokens)"false"
    prometheus.requestTimeoutRequest timeout in seconds"30"
    prometheus.customHeadersCustom headers as JSON string""
  9. Configure Authentication for Prometheus

    main

    The MCP server supports several authentication methods to connect to Prometheus. You can provide credentials directly via Helm values or use an existing Kubernetes Secret.

    Direct Authentication Parameters

    ParameterDescriptionDefault
    auth.existingSecretUse an existing Kubernetes Secret for credentials""
    auth.usernameBasic auth username""
    auth.passwordBasic auth password""
    auth.tokenBearer token""
    auth.orgIdOrganization ID for multi-tenant setups (X-Scope-OrgID header)""

    Using an Existing Kubernetes Secret

    If you set auth.existingSecret, the Secret must contain one or more of the following keys:

    • PROMETHEUS_USERNAME
    • PROMETHEUS_PASSWORD
    • PROMETHEUS_TOKEN
    • ORG_ID
    # Create the secret first
    kubectl create secret generic prometheus-auth \
      --from-literal=PROMETHEUS_USERNAME=admin \
      --from-literal=PROMETHEUS_PASSWORD=secret
    
    helm install prometheus-mcp-server \
      --set prometheus.url=https://prometheus.example.com \
      --set auth.existingSecret=prometheus-auth