Skip to main content
Glama
grafana-blind-alerts-mcp

grafana-blind-alerts-mcp

by softenq
README.md
# grafana-blind-alerts-mcp

Read-only [Model Context Protocol (MCP)](https://modelcontextprotocol.io) server that helps SRE/DevOps teams and AI coding assistants find **blind Grafana alert rules** — rules marked `health=ok` and `state=Normal` whose queries return zero series and **can never fire when an incident actually happens**.

Based on the two-stage blind-alert methodology documented by [Softenq](https://www.softenq.com/):  
[Grafana alerting audit: 16 of 209 alert rules could never fire](https://www.softenq.com/cases/alerting-blind-rules-audit/)

## Why `health=ok` Still Leaves Blind Spots

Grafana marks an alert rule `health=ok` as long as Prometheus or Loki returns HTTP `200`, even if `data.result` is empty (`[]`). Empty results happen for two completely different reasons:

1. **`zero_by_design`**: an `absent()` 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.
2. **`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 read-only MCP server probes each rule's bound datasource through Grafana's proxy API and classifies zero-series rules automatically, failing closed (`orphaned_or_unverified`) whenever an expression cannot be verified or when any branch of a compound query points to a missing metric or target.

## Tools

| Tool | What it does |
|---|---|
| `list_grafana_alert_rules` | Reads `/api/v1/provisioning/alert-rules` and extracts folder UIDs, datasource UIDs, and primary PromQL/LogQL queries. |
| `audit_blind_alert_rules` | Queries each rule's bound Prometheus/Loki datasource proxy, detects zero-series rules (including composite `unless` / `or vector(0)` masks), and classifies them into `zero_by_design` vs `orphaned_or_unverified`. |
| `classify_zero_series_rule` | Strips state filters (`state`, `status`, `phase`, `severity`) while keeping target identity labels (`job`, `instance`, `host`, `node`, `cluster`, `namespace`) to verify whether the base series or Loki stream exists. |

## Quick Start

Requirements: Python `>=3.10` and a Grafana **Viewer / read-only** Service Account token.

```bash
export GRAFANA_URL="https://grafana.example.com"
export GRAFANA_TOKEN="your_readonly_viewer_token"
uvx grafana-blind-alerts-mcp
```

Or run from a local checkout:

```bash
uv --directory /path/to/grafana-blind-alerts-mcp run grafana-blind-alerts-mcp
```

Optional environment variable:
- `LAZY_METRICS`: comma-separated counter names that only appear on first failure/run (target labels such as `job`/`instance` are still verified when present).

### Claude Desktop / Cursor / Claude Code Config

```json
{
  "mcpServers": {
    "grafana-blind-alerts": {
      "command": "uvx",
      "args": ["grafana-blind-alerts-mcp"],
      "env": {
        "GRAFANA_URL": "https://grafana.example.com",
        "GRAFANA_TOKEN": "your_readonly_viewer_token"
      }
    }
  }
}
```

## Development & Tests

```bash
uv run --with mcp --with httpx --with pytest pytest -v
```

Maintained by [Softenq](https://www.softenq.com/) (`contact@softenq.com`). Licensed under the MIT License.

TDQS

A3.8/5.0

Scored across 3 tools

Disambiguation5/5

The three tools have clearly distinct scopes: listing alert rules, auditing rules in bulk, and classifying a single alert expression. The boundary between bulk auditing and single-rule classification is explicit through their arguments and descriptions.

Naming Consistency5/5

All tools use consistent snake_case with a leading action verb: list_, audit_, and classify_. The noun phrases are readable and follow the same general verb_noun convention.

Tool Count5/5

Three tools is well-scoped for a focused Grafana blind-alert auditing server. Each tool serves a distinct part of the workflow: discovery, bulk analysis, and single-expression classification.

Completeness4/5

The surface covers the core lifecycle of listing rules, auditing them for zero-series issues, and classifying individual expressions. Minor gaps exist, such as no dedicated tool for fetching a specific rule's details or datasource metadata, but these are not blocking for the stated purpose.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues