Prometheus MCP Server
A minimal Model Context Protocol (MCP) server focused on reading from Prometheus. It exposes Prometheus discovery and query tools to MCP-compatible apps and includes a convenient CLI for local queries.
Highlights
- Instant and range queries via Prometheus HTTP API
- Discovery helpers: list metrics, get metadata, series selectors, label values
- Optional internal metrics exporter at /metrics (disabled by default)
- Works as a stdio MCP server or a one-off CLI
Installation
Build from source (Rust):
# binary at ./target/release/prometheus-mcp
Or build a Docker image:
Usage (CLI)
The CLI mirrors the tools exposed over MCP.
- Instant query
# optionally set an evaluation time
- Range query
- List metric names
- Metric metadata
- Series selectors (repeat --selector)
- Label values
MCP server (stdio)
Start the MCP server over stdio:
Optional: enable internal metrics at /metrics (default off):
Running in Docker
Build the image:
Run the MCP server:
# Linux: easiest if Prometheus is on the host at :9090
# macOS/Windows: use host.docker.internal
# Linux without host network: map host gateway
One-off CLI in the container:
# Instant query
# Range query
Basic Auth
Pass credentials via environment variables or CLI flags.
- Environment variables:
- CLI flags:
- Docker with env vars:
Configuration
All settings can be provided via environment variables; some also via flags.
| Name | Type | Default | CLI flag | Description |
|---|---|---|---|---|
| PROMETHEUS_URL | string (URL) | http://localhost:9090 | --prometheus-url | Base URL of your Prometheus server |
| PROMETHEUS_TIMEOUT | integer (seconds) | 10 | — | HTTP request timeout |
| PROMETHEUS_RETRIES | integer | 3 | — | Number of retries for Prometheus API calls |
| PROMETHEUS_RETRY_BACKOFF_MS | integer (ms) | 500 | — | Time to wait between retries |
| PROMETHEUS_MIN_INTERVAL_MS | integer (ms) | — | — | Minimum interval between query requests (basic rate limit) |
| PROMETHEUS_CACHE_TTL_SECS | integer (seconds) | — | — | TTL for simple in-process caches (list metrics and label values) |
| PROMETHEUS_USERNAME | string | — | --prometheus-username | Basic auth username |
| PROMETHEUS_PASSWORD | string | — | --prometheus-password | Basic auth password |
| — | boolean | false | --mcp | Start MCP server over stdio |
| — | boolean | false | --metrics-exporter | Enable internal Prometheus metrics at /metrics |
| — | integer (port) | 9091 | --metrics-port | Port for /metrics when exporter is enabled |
See docs/configuration.md for notes and examples.
Accessing from Claude Desktop
Follow the official guide to locate claude_desktop_config.json:
https://modelcontextprotocol.io/quickstart/user#for-claude-desktop-users
Minimal Docker-based entry:
With host Prometheus and exporter (macOS/Windows):
With Basic Auth via environment variables:
More examples: see docs/claude-desktop.md.
Debugging
Use the MCP Inspector to exercise the server interactively:
Connect with transport "STDIO", command prometheus-mcp, and optional args --mcp --prometheus-url http://localhost:9090.
Logs are appended to /tmp/mcp.jsonl; tail it with:
Security Considerations
- The server does not provide authentication itself; when running outside stdio, keep it on localhost.
- Handle credentials via environment variables or your secret manager. Avoid committing secrets.
License
Apache-2.0