prometheus-mcp 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- prometheus_mcp-0.1.0/.env.example +15 -0
- prometheus_mcp-0.1.0/.github/workflows/publish.yml +67 -0
- prometheus_mcp-0.1.0/.github/workflows/test.yml +36 -0
- prometheus_mcp-0.1.0/.gitignore +66 -0
- prometheus_mcp-0.1.0/CHANGELOG.md +22 -0
- prometheus_mcp-0.1.0/Dockerfile +8 -0
- prometheus_mcp-0.1.0/EVALUATION.md +53 -0
- prometheus_mcp-0.1.0/LICENSE +21 -0
- prometheus_mcp-0.1.0/PKG-INFO +199 -0
- prometheus_mcp-0.1.0/README.md +166 -0
- prometheus_mcp-0.1.0/evaluation.xml +59 -0
- prometheus_mcp-0.1.0/pyproject.toml +62 -0
- prometheus_mcp-0.1.0/server.json +55 -0
- prometheus_mcp-0.1.0/src/prometheus_mcp/__init__.py +3 -0
- prometheus_mcp-0.1.0/src/prometheus_mcp/_mcp.py +55 -0
- prometheus_mcp-0.1.0/src/prometheus_mcp/client.py +155 -0
- prometheus_mcp-0.1.0/src/prometheus_mcp/errors.py +103 -0
- prometheus_mcp-0.1.0/src/prometheus_mcp/models.py +125 -0
- prometheus_mcp-0.1.0/src/prometheus_mcp/output.py +28 -0
- prometheus_mcp-0.1.0/src/prometheus_mcp/py.typed +0 -0
- prometheus_mcp-0.1.0/src/prometheus_mcp/server.py +20 -0
- prometheus_mcp-0.1.0/src/prometheus_mcp/tools.py +693 -0
- prometheus_mcp-0.1.0/tests/test_client.py +176 -0
- prometheus_mcp-0.1.0/tests/test_errors.py +140 -0
- prometheus_mcp-0.1.0/tests/test_mcp_client_cache.py +60 -0
- prometheus_mcp-0.1.0/tests/test_protocol.py +197 -0
- prometheus_mcp-0.1.0/tests/test_tools_helpers.py +126 -0
- prometheus_mcp-0.1.0/tests/test_tools_integration.py +650 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Copy this file to .env and fill in your values.
|
|
2
|
+
# Never commit .env to version control.
|
|
3
|
+
|
|
4
|
+
# Required: Prometheus server URL (no trailing slash)
|
|
5
|
+
PROMETHEUS_URL=https://prometheus.example.com
|
|
6
|
+
|
|
7
|
+
# Optional: Bearer token for authentication (takes precedence over Basic auth)
|
|
8
|
+
# PROMETHEUS_TOKEN=your-token-here
|
|
9
|
+
|
|
10
|
+
# Optional: HTTP Basic auth credentials (used only when PROMETHEUS_TOKEN is not set)
|
|
11
|
+
# PROMETHEUS_USERNAME=admin
|
|
12
|
+
# PROMETHEUS_PASSWORD=secret
|
|
13
|
+
|
|
14
|
+
# Optional: Set to 'false' to skip TLS certificate verification (e.g. for self-signed certs)
|
|
15
|
+
# PROMETHEUS_SSL_VERIFY=true
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
# Fires when a tag like v0.1.0, v1.0.0rc1 is pushed.
|
|
4
|
+
# Builds the sdist+wheel once, then publishes to PyPI using a
|
|
5
|
+
# Trusted Publisher (OIDC — no API token stored anywhere).
|
|
6
|
+
on:
|
|
7
|
+
push:
|
|
8
|
+
tags:
|
|
9
|
+
- "v*"
|
|
10
|
+
|
|
11
|
+
permissions:
|
|
12
|
+
contents: read
|
|
13
|
+
|
|
14
|
+
jobs:
|
|
15
|
+
build:
|
|
16
|
+
name: Build sdist + wheel
|
|
17
|
+
runs-on: ubuntu-latest
|
|
18
|
+
steps:
|
|
19
|
+
- name: Check out code
|
|
20
|
+
uses: actions/checkout@v4
|
|
21
|
+
|
|
22
|
+
- name: Set up Python
|
|
23
|
+
uses: actions/setup-python@v5
|
|
24
|
+
with:
|
|
25
|
+
python-version: "3.12"
|
|
26
|
+
|
|
27
|
+
- name: Install build tooling
|
|
28
|
+
run: python -m pip install --upgrade build
|
|
29
|
+
|
|
30
|
+
- name: Verify tag matches package version
|
|
31
|
+
run: |
|
|
32
|
+
TAG="${GITHUB_REF_NAME#v}"
|
|
33
|
+
PKG=$(python -c "import tomllib, pathlib; print(tomllib.loads(pathlib.Path('pyproject.toml').read_text())['project']['version'])")
|
|
34
|
+
echo "tag=$TAG pyproject.version=$PKG"
|
|
35
|
+
if [ "$TAG" != "$PKG" ]; then
|
|
36
|
+
echo "::error::Tag v$TAG does not match pyproject version $PKG"
|
|
37
|
+
exit 1
|
|
38
|
+
fi
|
|
39
|
+
|
|
40
|
+
- name: Build
|
|
41
|
+
run: python -m build
|
|
42
|
+
|
|
43
|
+
- name: Upload dist artifact
|
|
44
|
+
uses: actions/upload-artifact@v4
|
|
45
|
+
with:
|
|
46
|
+
name: dist
|
|
47
|
+
path: dist/
|
|
48
|
+
if-no-files-found: error
|
|
49
|
+
|
|
50
|
+
publish:
|
|
51
|
+
name: Publish to PyPI
|
|
52
|
+
needs: build
|
|
53
|
+
runs-on: ubuntu-latest
|
|
54
|
+
environment:
|
|
55
|
+
name: pypi
|
|
56
|
+
url: https://pypi.org/project/prometheus-mcp/
|
|
57
|
+
permissions:
|
|
58
|
+
id-token: write
|
|
59
|
+
steps:
|
|
60
|
+
- name: Download dist artifact
|
|
61
|
+
uses: actions/download-artifact@v4
|
|
62
|
+
with:
|
|
63
|
+
name: dist
|
|
64
|
+
path: dist
|
|
65
|
+
|
|
66
|
+
- name: Publish to PyPI
|
|
67
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
name: Tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
matrix:
|
|
14
|
+
python-version: ["3.10", "3.11", "3.12"]
|
|
15
|
+
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
|
|
19
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
20
|
+
uses: actions/setup-python@v5
|
|
21
|
+
with:
|
|
22
|
+
python-version: ${{ matrix.python-version }}
|
|
23
|
+
|
|
24
|
+
- name: Install dependencies
|
|
25
|
+
run: |
|
|
26
|
+
python -m pip install --upgrade pip
|
|
27
|
+
pip install -e '.[dev]'
|
|
28
|
+
|
|
29
|
+
- name: Lint with ruff
|
|
30
|
+
run: |
|
|
31
|
+
ruff check src tests
|
|
32
|
+
ruff format --check src tests
|
|
33
|
+
|
|
34
|
+
- name: Run tests with coverage
|
|
35
|
+
run: |
|
|
36
|
+
pytest tests/ -v --cov=src/prometheus_mcp --cov-report=term-missing
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
*.so
|
|
6
|
+
.Python
|
|
7
|
+
build/
|
|
8
|
+
develop-eggs/
|
|
9
|
+
dist/
|
|
10
|
+
downloads/
|
|
11
|
+
eggs/
|
|
12
|
+
.eggs/
|
|
13
|
+
lib/
|
|
14
|
+
lib64/
|
|
15
|
+
parts/
|
|
16
|
+
sdist/
|
|
17
|
+
var/
|
|
18
|
+
wheels/
|
|
19
|
+
share/python-wheels/
|
|
20
|
+
*.egg-info/
|
|
21
|
+
.installed.cfg
|
|
22
|
+
*.egg
|
|
23
|
+
MANIFEST
|
|
24
|
+
|
|
25
|
+
# Virtual environments
|
|
26
|
+
.venv/
|
|
27
|
+
venv/
|
|
28
|
+
ENV/
|
|
29
|
+
env/
|
|
30
|
+
.env
|
|
31
|
+
|
|
32
|
+
# Testing
|
|
33
|
+
.tox/
|
|
34
|
+
.nox/
|
|
35
|
+
.coverage
|
|
36
|
+
.coverage.*
|
|
37
|
+
.cache
|
|
38
|
+
nosetests.xml
|
|
39
|
+
coverage.xml
|
|
40
|
+
*.cover
|
|
41
|
+
*.py,cover
|
|
42
|
+
.hypothesis/
|
|
43
|
+
.pytest_cache/
|
|
44
|
+
cover/
|
|
45
|
+
htmlcov/
|
|
46
|
+
|
|
47
|
+
# Type checking
|
|
48
|
+
.mypy_cache/
|
|
49
|
+
.dmypy.json
|
|
50
|
+
dmypy.json
|
|
51
|
+
.pyright/
|
|
52
|
+
|
|
53
|
+
# IDEs
|
|
54
|
+
.idea/
|
|
55
|
+
.vscode/
|
|
56
|
+
*.swp
|
|
57
|
+
*.swo
|
|
58
|
+
*~
|
|
59
|
+
|
|
60
|
+
# OS
|
|
61
|
+
.DS_Store
|
|
62
|
+
Thumbs.db
|
|
63
|
+
|
|
64
|
+
# Dist
|
|
65
|
+
*.tar.gz
|
|
66
|
+
*.whl
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `prometheus-mcp` will be documented in this file.
|
|
4
|
+
|
|
5
|
+
Format: [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
versioning: [SemVer](https://semver.org/).
|
|
7
|
+
|
|
8
|
+
## [0.1.0] — 2026-04-18
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- `prometheus_list_metrics` — list all metric names with optional substring filter (cap 500)
|
|
13
|
+
- `prometheus_query` — instant PromQL query with optional time parameter
|
|
14
|
+
- `prometheus_query_range` — range PromQL query with time-series output (cap 5000 points)
|
|
15
|
+
- `prometheus_list_alerts` — list active alerts grouped by state + severity
|
|
16
|
+
- `prometheus_list_targets` — list scrape targets summarised by job + health
|
|
17
|
+
- HTTP Basic auth and Bearer token auth support (Bearer takes precedence)
|
|
18
|
+
- SSL verification toggle via `PROMETHEUS_SSL_VERIFY`
|
|
19
|
+
- Thread-safe lazy client cache (double-checked locking)
|
|
20
|
+
- Structured output (`outputSchema`) for all 5 tools via FastMCP `structured_output=True`
|
|
21
|
+
- Markdown rendering with truncation hints for large result sets
|
|
22
|
+
- Actionable error messages for 401/403/404/400/422/429/5xx/ConnectionError/Timeout
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Evaluation suite
|
|
2
|
+
|
|
3
|
+
This repository ships a 10-question evaluation (`evaluation.xml`) built per the
|
|
4
|
+
mcp-builder Phase 4 specification. The suite measures whether an LLM can
|
|
5
|
+
productively use prometheus-mcp to answer realistic, read-only questions about
|
|
6
|
+
metrics, alerts, and scrape targets.
|
|
7
|
+
|
|
8
|
+
## Design principles
|
|
9
|
+
|
|
10
|
+
Every question is **read-only, independent, stable, verifiable, complex, and
|
|
11
|
+
instance-agnostic** — same principles as sonarqube-mcp's template. Since
|
|
12
|
+
prometheus-mcp wraps a customer-owned Prometheus instance, no pre-solved answer
|
|
13
|
+
shared fixture exists. The suite ships with `__VERIFY_ON_INSTANCE__` placeholders.
|
|
14
|
+
|
|
15
|
+
## Filling in answers
|
|
16
|
+
|
|
17
|
+
1. Pick a target Prometheus (self-hosted, or the public demo at https://demo.promlabs.com).
|
|
18
|
+
2. Export env vars:
|
|
19
|
+
```bash
|
|
20
|
+
export PROMETHEUS_URL=https://prometheus.example.com
|
|
21
|
+
# optional: export PROMETHEUS_TOKEN=... / PROMETHEUS_USERNAME / PROMETHEUS_PASSWORD
|
|
22
|
+
```
|
|
23
|
+
3. Solve each question manually — fastest path is to run Claude Code with this
|
|
24
|
+
MCP configured and ask the question verbatim.
|
|
25
|
+
4. Replace the placeholder with the verified value.
|
|
26
|
+
5. Narrow each question to target one specific entity for stability (e.g.
|
|
27
|
+
replace "first metric" with a specific metric name on your instance).
|
|
28
|
+
|
|
29
|
+
## Running the harness
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
python scripts/evaluation.py \
|
|
33
|
+
-t stdio \
|
|
34
|
+
-c uvx \
|
|
35
|
+
-a prometheus-mcp \
|
|
36
|
+
-e PROMETHEUS_URL=$PROMETHEUS_URL \
|
|
37
|
+
-e PROMETHEUS_TOKEN=$PROMETHEUS_TOKEN \
|
|
38
|
+
-o evaluation_report.md \
|
|
39
|
+
evaluation.xml
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Low-accuracy questions usually signal one of:
|
|
43
|
+
|
|
44
|
+
- Tool description is ambiguous → tighten in `tools.py`.
|
|
45
|
+
- Output schema is under/over-specified → adjust TypedDict in `models.py`.
|
|
46
|
+
- Question itself is ambiguous on your instance → rephrase.
|
|
47
|
+
|
|
48
|
+
## Design deviations
|
|
49
|
+
|
|
50
|
+
Same honest compromise as sonarqube-mcp and jaeger-mcp: question *structure*
|
|
51
|
+
is fixed (validates the MCP design), *values* come from whichever Prometheus
|
|
52
|
+
you verify against. A shared fixture would require standing up a demo Prometheus
|
|
53
|
+
with pinned metrics — out of scope for v0.1.0.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mikhail Shchegolev
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: prometheus-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: MCP server for Prometheus — query metrics, inspect alerts, and explore scrape targets (read-only).
|
|
5
|
+
Project-URL: Homepage, https://github.com/mshegolev/prometheus-mcp
|
|
6
|
+
Project-URL: Issues, https://github.com/mshegolev/prometheus-mcp/issues
|
|
7
|
+
Author: Mikhail Shchegolev
|
|
8
|
+
License: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: anthropic,claude,mcp,metrics,monitoring,observability,prometheus,promql
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
|
+
Classifier: Topic :: System :: Monitoring
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Requires-Dist: mcp>=1.2
|
|
23
|
+
Requires-Dist: pydantic>=2.0
|
|
24
|
+
Requires-Dist: requests>=2.31
|
|
25
|
+
Requires-Dist: typing-extensions>=4.5; python_version < '3.12'
|
|
26
|
+
Requires-Dist: urllib3>=2.0
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: pytest-cov>=4; extra == 'dev'
|
|
29
|
+
Requires-Dist: pytest>=7; extra == 'dev'
|
|
30
|
+
Requires-Dist: responses>=0.25; extra == 'dev'
|
|
31
|
+
Requires-Dist: ruff>=0.5; extra == 'dev'
|
|
32
|
+
Description-Content-Type: text/markdown
|
|
33
|
+
|
|
34
|
+
# prometheus-mcp
|
|
35
|
+
|
|
36
|
+
<!-- mcp-name: io.github.mshegolev/prometheus-mcp -->
|
|
37
|
+
|
|
38
|
+
[](https://pypi.org/project/prometheus-mcp/)
|
|
39
|
+
[](https://pypi.org/project/prometheus-mcp/)
|
|
40
|
+
[](LICENSE)
|
|
41
|
+
[](https://github.com/mshegolev/prometheus-mcp/actions/workflows/test.yml)
|
|
42
|
+
|
|
43
|
+
**MCP server for [Prometheus](https://prometheus.io/) metrics and observability.**
|
|
44
|
+
Give Claude (or any MCP-capable agent) read access to your Prometheus instance — query metrics with PromQL, inspect active alerts, and explore scrape targets — without leaving the conversation.
|
|
45
|
+
|
|
46
|
+
## Why another Prometheus MCP?
|
|
47
|
+
|
|
48
|
+
The existing Prometheus integrations require custom scripts or direct API knowledge. This server:
|
|
49
|
+
|
|
50
|
+
- Speaks the standard [Model Context Protocol](https://modelcontextprotocol.io/) over **stdio** — works with Claude Desktop, Claude Code, Cursor, and any MCP client.
|
|
51
|
+
- Is **read-only**: all 5 tools carry `readOnlyHint: true` — zero risk of modifying Prometheus data.
|
|
52
|
+
- Returns **dual-channel output**: structured JSON (`structuredContent`) for programmatic use + Markdown (`content`) for human-readable display.
|
|
53
|
+
- Has **actionable error messages** that name the exact env var to fix and suggest a next step.
|
|
54
|
+
- Supports **Bearer token**, **HTTP Basic auth**, or **no auth** (common for internal deployments).
|
|
55
|
+
|
|
56
|
+
## Tools
|
|
57
|
+
|
|
58
|
+
| Tool | Endpoint | Description |
|
|
59
|
+
|------|----------|-------------|
|
|
60
|
+
| `prometheus_list_metrics` | `GET /api/v1/label/__name__/values` | List all metric names with optional substring filter (cap 500) |
|
|
61
|
+
| `prometheus_query` | `GET /api/v1/query` | Execute an instant PromQL query |
|
|
62
|
+
| `prometheus_query_range` | `GET /api/v1/query_range` | Execute a PromQL range query returning time-series |
|
|
63
|
+
| `prometheus_list_alerts` | `GET /api/v1/alerts` | List active and pending alerts |
|
|
64
|
+
| `prometheus_list_targets` | `GET /api/v1/targets` | List scrape targets by health and job |
|
|
65
|
+
|
|
66
|
+
## Installation
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
pip install prometheus-mcp
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Or run directly without installing:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
uvx prometheus-mcp
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Configuration
|
|
79
|
+
|
|
80
|
+
All configuration is via environment variables:
|
|
81
|
+
|
|
82
|
+
| Variable | Required | Default | Description |
|
|
83
|
+
|----------|----------|---------|-------------|
|
|
84
|
+
| `PROMETHEUS_URL` | **Yes** | — | Prometheus server URL, e.g. `https://prometheus.example.com` (no trailing slash) |
|
|
85
|
+
| `PROMETHEUS_TOKEN` | No | — | Bearer token (takes precedence over Basic auth) |
|
|
86
|
+
| `PROMETHEUS_USERNAME` | No | — | HTTP Basic auth username |
|
|
87
|
+
| `PROMETHEUS_PASSWORD` | No | — | HTTP Basic auth password |
|
|
88
|
+
| `PROMETHEUS_SSL_VERIFY` | No | `true` | Set `false` for self-signed certificates |
|
|
89
|
+
|
|
90
|
+
Copy `.env.example` to `.env` and fill in your values.
|
|
91
|
+
|
|
92
|
+
## Claude Desktop / Claude Code setup
|
|
93
|
+
|
|
94
|
+
Add to your MCP config (`claude_desktop_config.json` or `.claude/mcp.json`):
|
|
95
|
+
|
|
96
|
+
```json
|
|
97
|
+
{
|
|
98
|
+
"mcpServers": {
|
|
99
|
+
"prometheus": {
|
|
100
|
+
"command": "prometheus-mcp",
|
|
101
|
+
"env": {
|
|
102
|
+
"PROMETHEUS_URL": "https://prometheus.example.com",
|
|
103
|
+
"PROMETHEUS_TOKEN": "your-token-here"
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Or with `uvx` (no install required):
|
|
111
|
+
|
|
112
|
+
```json
|
|
113
|
+
{
|
|
114
|
+
"mcpServers": {
|
|
115
|
+
"prometheus": {
|
|
116
|
+
"command": "uvx",
|
|
117
|
+
"args": ["prometheus-mcp"],
|
|
118
|
+
"env": {
|
|
119
|
+
"PROMETHEUS_URL": "https://prometheus.example.com"
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Docker
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
docker run --rm -e PROMETHEUS_URL=https://prometheus.example.com prometheus-mcp
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Example queries
|
|
133
|
+
|
|
134
|
+
Once configured, ask Claude:
|
|
135
|
+
|
|
136
|
+
- "What metrics does Prometheus have about HTTP requests?"
|
|
137
|
+
- "What is the current request rate for the payment service?"
|
|
138
|
+
- "Show me CPU usage over the last hour with 5-minute resolution"
|
|
139
|
+
- "Are there any firing alerts? What's their severity?"
|
|
140
|
+
- "Which scrape targets are currently down and why?"
|
|
141
|
+
- "How many node-exporter instances are up?"
|
|
142
|
+
|
|
143
|
+
## Tool usage guide
|
|
144
|
+
|
|
145
|
+
### `prometheus_list_metrics`
|
|
146
|
+
|
|
147
|
+
Returns all metric names Prometheus knows about. Use `pattern` to filter by substring (case-insensitive). **Start here** when you don't know which metrics are available. Output is capped at 500 metrics with a truncation hint.
|
|
148
|
+
|
|
149
|
+
### `prometheus_query`
|
|
150
|
+
|
|
151
|
+
Execute an instant PromQL expression and get current values. Returns result type (vector/scalar/matrix/string), sample count, and per-sample labels and values.
|
|
152
|
+
|
|
153
|
+
Parameters:
|
|
154
|
+
- `query` (required) — PromQL expression, e.g. `up`, `rate(http_requests_total[5m])`
|
|
155
|
+
- `time` (optional) — RFC3339 or Unix timestamp; defaults to now
|
|
156
|
+
|
|
157
|
+
### `prometheus_query_range`
|
|
158
|
+
|
|
159
|
+
Execute a PromQL expression over a time window. Returns one series per matching time series with timestamped values. Total data points across all series are capped at 5000.
|
|
160
|
+
|
|
161
|
+
Parameters:
|
|
162
|
+
- `query` (required) — PromQL expression
|
|
163
|
+
- `start` / `end` (required) — RFC3339 or Unix timestamps
|
|
164
|
+
- `step` (required) — resolution like `15s`, `1m`, `5m`
|
|
165
|
+
|
|
166
|
+
Prometheus rejects steps that would produce > 11,000 points per series (HTTP 422). Increase step or narrow the range if this happens.
|
|
167
|
+
|
|
168
|
+
**Note:** The Prometheus range API does not support filtering by branch or commit — filters are expressed purely in PromQL label matchers.
|
|
169
|
+
|
|
170
|
+
### `prometheus_list_alerts`
|
|
171
|
+
|
|
172
|
+
Returns all active/pending alerts with labels (including `alertname`, `severity`), state, activation time, and current value. Includes a state summary (firing vs pending counts).
|
|
173
|
+
|
|
174
|
+
### `prometheus_list_targets`
|
|
175
|
+
|
|
176
|
+
Returns scrape targets with job name, instance address, health (`up`/`down`/`unknown`), last scrape duration in milliseconds, and any error message. Includes a per-job summary. Filter by `state`: `active` (default), `dropped`, or `any`.
|
|
177
|
+
|
|
178
|
+
## Performance characteristics
|
|
179
|
+
|
|
180
|
+
- All tools use a single persistent `requests.Session` with connection pooling.
|
|
181
|
+
- The session has `trust_env = False` to bypass environment proxies (Prometheus is typically an internal service).
|
|
182
|
+
- Requests time out after 30 seconds.
|
|
183
|
+
- `prometheus_query_range` caps output at 5000 total points across all series — use a larger step for long windows.
|
|
184
|
+
- `prometheus_list_metrics` returns up to 500 metrics after filtering.
|
|
185
|
+
|
|
186
|
+
## Development
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
git clone https://github.com/mshegolev/prometheus-mcp
|
|
190
|
+
cd prometheus-mcp
|
|
191
|
+
pip install -e '.[dev]'
|
|
192
|
+
pytest tests/ -v
|
|
193
|
+
ruff check src tests
|
|
194
|
+
ruff format src tests
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
## License
|
|
198
|
+
|
|
199
|
+
MIT — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# prometheus-mcp
|
|
2
|
+
|
|
3
|
+
<!-- mcp-name: io.github.mshegolev/prometheus-mcp -->
|
|
4
|
+
|
|
5
|
+
[](https://pypi.org/project/prometheus-mcp/)
|
|
6
|
+
[](https://pypi.org/project/prometheus-mcp/)
|
|
7
|
+
[](LICENSE)
|
|
8
|
+
[](https://github.com/mshegolev/prometheus-mcp/actions/workflows/test.yml)
|
|
9
|
+
|
|
10
|
+
**MCP server for [Prometheus](https://prometheus.io/) metrics and observability.**
|
|
11
|
+
Give Claude (or any MCP-capable agent) read access to your Prometheus instance — query metrics with PromQL, inspect active alerts, and explore scrape targets — without leaving the conversation.
|
|
12
|
+
|
|
13
|
+
## Why another Prometheus MCP?
|
|
14
|
+
|
|
15
|
+
The existing Prometheus integrations require custom scripts or direct API knowledge. This server:
|
|
16
|
+
|
|
17
|
+
- Speaks the standard [Model Context Protocol](https://modelcontextprotocol.io/) over **stdio** — works with Claude Desktop, Claude Code, Cursor, and any MCP client.
|
|
18
|
+
- Is **read-only**: all 5 tools carry `readOnlyHint: true` — zero risk of modifying Prometheus data.
|
|
19
|
+
- Returns **dual-channel output**: structured JSON (`structuredContent`) for programmatic use + Markdown (`content`) for human-readable display.
|
|
20
|
+
- Has **actionable error messages** that name the exact env var to fix and suggest a next step.
|
|
21
|
+
- Supports **Bearer token**, **HTTP Basic auth**, or **no auth** (common for internal deployments).
|
|
22
|
+
|
|
23
|
+
## Tools
|
|
24
|
+
|
|
25
|
+
| Tool | Endpoint | Description |
|
|
26
|
+
|------|----------|-------------|
|
|
27
|
+
| `prometheus_list_metrics` | `GET /api/v1/label/__name__/values` | List all metric names with optional substring filter (cap 500) |
|
|
28
|
+
| `prometheus_query` | `GET /api/v1/query` | Execute an instant PromQL query |
|
|
29
|
+
| `prometheus_query_range` | `GET /api/v1/query_range` | Execute a PromQL range query returning time-series |
|
|
30
|
+
| `prometheus_list_alerts` | `GET /api/v1/alerts` | List active and pending alerts |
|
|
31
|
+
| `prometheus_list_targets` | `GET /api/v1/targets` | List scrape targets by health and job |
|
|
32
|
+
|
|
33
|
+
## Installation
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pip install prometheus-mcp
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Or run directly without installing:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
uvx prometheus-mcp
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Configuration
|
|
46
|
+
|
|
47
|
+
All configuration is via environment variables:
|
|
48
|
+
|
|
49
|
+
| Variable | Required | Default | Description |
|
|
50
|
+
|----------|----------|---------|-------------|
|
|
51
|
+
| `PROMETHEUS_URL` | **Yes** | — | Prometheus server URL, e.g. `https://prometheus.example.com` (no trailing slash) |
|
|
52
|
+
| `PROMETHEUS_TOKEN` | No | — | Bearer token (takes precedence over Basic auth) |
|
|
53
|
+
| `PROMETHEUS_USERNAME` | No | — | HTTP Basic auth username |
|
|
54
|
+
| `PROMETHEUS_PASSWORD` | No | — | HTTP Basic auth password |
|
|
55
|
+
| `PROMETHEUS_SSL_VERIFY` | No | `true` | Set `false` for self-signed certificates |
|
|
56
|
+
|
|
57
|
+
Copy `.env.example` to `.env` and fill in your values.
|
|
58
|
+
|
|
59
|
+
## Claude Desktop / Claude Code setup
|
|
60
|
+
|
|
61
|
+
Add to your MCP config (`claude_desktop_config.json` or `.claude/mcp.json`):
|
|
62
|
+
|
|
63
|
+
```json
|
|
64
|
+
{
|
|
65
|
+
"mcpServers": {
|
|
66
|
+
"prometheus": {
|
|
67
|
+
"command": "prometheus-mcp",
|
|
68
|
+
"env": {
|
|
69
|
+
"PROMETHEUS_URL": "https://prometheus.example.com",
|
|
70
|
+
"PROMETHEUS_TOKEN": "your-token-here"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Or with `uvx` (no install required):
|
|
78
|
+
|
|
79
|
+
```json
|
|
80
|
+
{
|
|
81
|
+
"mcpServers": {
|
|
82
|
+
"prometheus": {
|
|
83
|
+
"command": "uvx",
|
|
84
|
+
"args": ["prometheus-mcp"],
|
|
85
|
+
"env": {
|
|
86
|
+
"PROMETHEUS_URL": "https://prometheus.example.com"
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Docker
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
docker run --rm -e PROMETHEUS_URL=https://prometheus.example.com prometheus-mcp
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Example queries
|
|
100
|
+
|
|
101
|
+
Once configured, ask Claude:
|
|
102
|
+
|
|
103
|
+
- "What metrics does Prometheus have about HTTP requests?"
|
|
104
|
+
- "What is the current request rate for the payment service?"
|
|
105
|
+
- "Show me CPU usage over the last hour with 5-minute resolution"
|
|
106
|
+
- "Are there any firing alerts? What's their severity?"
|
|
107
|
+
- "Which scrape targets are currently down and why?"
|
|
108
|
+
- "How many node-exporter instances are up?"
|
|
109
|
+
|
|
110
|
+
## Tool usage guide
|
|
111
|
+
|
|
112
|
+
### `prometheus_list_metrics`
|
|
113
|
+
|
|
114
|
+
Returns all metric names Prometheus knows about. Use `pattern` to filter by substring (case-insensitive). **Start here** when you don't know which metrics are available. Output is capped at 500 metrics with a truncation hint.
|
|
115
|
+
|
|
116
|
+
### `prometheus_query`
|
|
117
|
+
|
|
118
|
+
Execute an instant PromQL expression and get current values. Returns result type (vector/scalar/matrix/string), sample count, and per-sample labels and values.
|
|
119
|
+
|
|
120
|
+
Parameters:
|
|
121
|
+
- `query` (required) — PromQL expression, e.g. `up`, `rate(http_requests_total[5m])`
|
|
122
|
+
- `time` (optional) — RFC3339 or Unix timestamp; defaults to now
|
|
123
|
+
|
|
124
|
+
### `prometheus_query_range`
|
|
125
|
+
|
|
126
|
+
Execute a PromQL expression over a time window. Returns one series per matching time series with timestamped values. Total data points across all series are capped at 5000.
|
|
127
|
+
|
|
128
|
+
Parameters:
|
|
129
|
+
- `query` (required) — PromQL expression
|
|
130
|
+
- `start` / `end` (required) — RFC3339 or Unix timestamps
|
|
131
|
+
- `step` (required) — resolution like `15s`, `1m`, `5m`
|
|
132
|
+
|
|
133
|
+
Prometheus rejects steps that would produce > 11,000 points per series (HTTP 422). Increase step or narrow the range if this happens.
|
|
134
|
+
|
|
135
|
+
**Note:** The Prometheus range API does not support filtering by branch or commit — filters are expressed purely in PromQL label matchers.
|
|
136
|
+
|
|
137
|
+
### `prometheus_list_alerts`
|
|
138
|
+
|
|
139
|
+
Returns all active/pending alerts with labels (including `alertname`, `severity`), state, activation time, and current value. Includes a state summary (firing vs pending counts).
|
|
140
|
+
|
|
141
|
+
### `prometheus_list_targets`
|
|
142
|
+
|
|
143
|
+
Returns scrape targets with job name, instance address, health (`up`/`down`/`unknown`), last scrape duration in milliseconds, and any error message. Includes a per-job summary. Filter by `state`: `active` (default), `dropped`, or `any`.
|
|
144
|
+
|
|
145
|
+
## Performance characteristics
|
|
146
|
+
|
|
147
|
+
- All tools use a single persistent `requests.Session` with connection pooling.
|
|
148
|
+
- The session has `trust_env = False` to bypass environment proxies (Prometheus is typically an internal service).
|
|
149
|
+
- Requests time out after 30 seconds.
|
|
150
|
+
- `prometheus_query_range` caps output at 5000 total points across all series — use a larger step for long windows.
|
|
151
|
+
- `prometheus_list_metrics` returns up to 500 metrics after filtering.
|
|
152
|
+
|
|
153
|
+
## Development
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
git clone https://github.com/mshegolev/prometheus-mcp
|
|
157
|
+
cd prometheus-mcp
|
|
158
|
+
pip install -e '.[dev]'
|
|
159
|
+
pytest tests/ -v
|
|
160
|
+
ruff check src tests
|
|
161
|
+
ruff format src tests
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## License
|
|
165
|
+
|
|
166
|
+
MIT — see [LICENSE](LICENSE).
|