Grafana Blind Alerts Audit MCP
Read-only MCP server that detects blind Grafana alert rules (health=ok with 0 series) and separates zero-by-design from orphaned metric sources.
Documentation
grafana-blind-alerts-mcp
Read-only Model Context Protocol (MCP) server and deterministic CLI that find blind Grafana alert rules — rules marked health=ok and state=Normal whose queries return zero series (or mask a dead metric behind or vector(0) / unless) and can never fire during an incident.
Why health=ok Still Leaves Blind Spots
Grafana marks an alert rule health=ok whenever Prometheus or Loki returns HTTP 200, even if data.result is empty ([]). Empty results happen for two different reasons:
zero_by_design: anabsent()guard on a healthy target, a threshold comparison (temp > 80,state="failed") currently satisfied across live hosts, or a lazy error counter not yet emitted after a restart.orphaned_or_unverified: a renamed or removed metric, a lost scrape job or host label after a migration, or a dead expression hidden behind... or vector(0)/unless.
This tool probes each rule's bound datasource through Grafana's proxy API and classifies rules in a single pass, failing closed (orphaned_or_unverified) whenever an expression cannot be parsed or any branch of a compound query points to a missing metric, target label, or Loki stream.
Tools
| Tool | What it does |
|---|---|
list_grafana_alert_rules | Reads GET /api/ruler/grafana/api/v1/rules (Grafana OSS Viewer / alert.rules:read), with automatic fallback to GET /api/v1/provisioning/alert-rules on 403/404, and extracts folder UIDs, datasource UIDs, and primary PromQL/LogQL queries. |
audit_blind_alert_rules | Queries each rule's bound Prometheus/Loki datasource proxy (api/v1/query for PromQL; loki/api/v1/series over 24 h for Loki stream existence), catches zero-series rules and masked or vector(0) / unless branches, and classifies them into zero_by_design vs orphaned_or_unverified. |
classify_zero_series_rule | Strips state filters (state, status, phase, level, severity, reason, code, result) while keeping target identity labels (job, instance, host, node, cluster, namespace, service, pod) to verify whether the base series or Loki stream exists. |
Permissions & Quick Start
Requirements: Python >=3.10 and a read-only Grafana Service Account token:
- Grafana OSS
Viewer(alert.rules:read+datasources:query) is sufficient for the primary Ruler API (/api/ruler/grafana/api/v1/rules) and datasource proxy queries. Note thatVieweronly sees alert rules in folders where the token hasfolders:read. - Fallback endpoint (
/api/v1/provisioning/alert-rules) is only called if the Ruler endpoint returns403/404. Depending on Grafana version and RBAC configuration, this endpoint may return403forViewerand requirealert.provisioning:read(orAdmin). - The server never mutates rules and never calls
/api/v1/eval(which requiresEditor/Admin).
Deterministic CLI / CI Mode (No LLM Required)
For CI/CD gates, cron jobs, or closed perimeters, run the underlying auditor directly without starting an MCP server:
export GRAFANA_URL="https://grafana.example.com"
export GRAFANA_TOKEN="your_readonly_viewer_token"
uvx --from git+https://github.com/softenq/grafana-blind-alerts-mcp@v0.1.0 \
grafana-blind-alerts-mcp --audit --fail-on-orphaned
By default --audit inspects all matching rules (--limit 0). Pass --limit N to cap the audit; truncated runs set "truncated": true in JSON output and print a warning to stderr. Passing --fail-on-orphaned exits with status 1 if any orphaned_or_unverified rules or Stage 1 datasource query errors occur (use --fail-on-errors to fail only on datasource errors).
For local development or air-gapped environments, install from a local clone (pip install -e . or uv run grafana-blind-alerts-mcp --audit --fail-on-orphaned).
MCP Server Mode (Claude Desktop / Cursor / Claude Code)
{
"mcpServers": {
"grafana-blind-alerts": {
"command": "uvx",
"args": [
"--from",
"git+https://github.com/softenq/grafana-blind-alerts-mcp@v0.1.0",
"grafana-blind-alerts-mcp"
],
"env": {
"GRAFANA_URL": "https://grafana.example.com",
"GRAFANA_TOKEN": "your_readonly_viewer_token"
}
}
}
}
Optional environment variable:
LAZY_METRICS: comma-separated counter names that only appear on first failure/run (positive target labels such asjob/instanceare still verified when present).
Security & Threat Model
- Datasource proxy read scope: A Grafana token with
datasources:querycan execute arbitrary read queries against proxied Prometheus and Loki datasources via/api/datasources/proxy/uid/*. Treat it as a broad telemetry read credential and be aware that an untrusted agent could issue expensive queries (DoS risk). - Closed perimeters & data egress: In MCP mode, alert titles, PromQL/LogQL queries, and blind-spot findings are returned to whichever LLM client invokes the tools. Do not connect this server to a cloud-hosted LLM if your alert names or label values are sensitive; use a local/on-prem LLM or run the deterministic CLI (
--audit) in CI/cron.
Known Limitations
- Address-label allowlist: Base-series probes preserve only
job,instance,host,node,cluster,namespace,service,pod. Entity labels outside this list (for exampleunit,device,mountpoint,deployment) are dropped during the base probe, so a renamed systemduniton a live host will not be caught if other units emit the same metric. - Instant query lookback: Prometheus instant
count({...})probes use Prometheus's default 5-minute staleness lookback. Metrics scraped on longer intervals (hourly/daily batch jobs) should either be listed inLAZY_METRICSor checked withlast_over_time(...[24h])//api/v1/series. - Partial fleet blindness: Auditing empty queries catches completely blind rules or missing address targets, not partial loss where 1 of 5 nodes stops reporting an ungrouped metric.
Development & Tests
uv run --with mcp --with httpx --with pytest pytest -v
Licensed under the MIT License.