communitystdio

Grafana MCP Server

Query Prometheus and Loki, read Grafana dashboards, and check alert rules from Claude Code or Cursor.

Updated: April 15, 2026

Install

npx mcp-grafana
~/.claude/settings.json
{
  "mcpServers": {
    "grafana-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-grafana"
      ],
      "env": {
        "GRAFANA_URL": "http://localhost:3000",
        "GRAFANA_API_KEY": "glsa_xxx"
      }
    }
  }
}

Capabilities

  • + Query Prometheus and Loki data sources through the Grafana proxy
  • + List and read dashboards with panel metadata and targets
  • + Search panels by title, tag, or data source
  • + Get alert rules and their current firing state
  • + Check datasource health and test connectivity

Limitations

  • - Requires a Grafana service account token with the right scope
  • - No dashboard creation or editing; the server is read-only
  • - Alert rules are read-only; you cannot acknowledge or silence alerts via MCP
  • - No snapshot creation; the share-by-snapshot path is not exposed

Grafana MCP server setup for Claude Code and Cursor

Quick answer: The Grafana MCP server wraps the Grafana API as MCP tools for Claude Code and Cursor. Drop in the env vars, run one npx command, and the editor can reach the service directly. Setup takes about 3 minutes, tested on mcp-grafana@0.3.5 on April 15, 2026.

Grafana is the dashboard and alerting layer on top of Prometheus, Loki, Tempo, and a dozen other data sources. It is the observability pane most SRE teams open first. Without an MCP connection, working with Grafana means flipping between the editor and the web UI - copying IDs, pasting results, losing context. The MCP server removes that loop. Claude can fetch the data itself, reason about it, and write changes back without you switching tabs.

This guide covers install, config for both editors, prompt patterns that actually work, and the places where the API will bite back.

What this server does

The server speaks MCP over stdio and wraps the standard Grafana SDK. The tool surface is grouped into these sets:

  • Datasources: list_datasources, test_datasource, query_datasource
  • Dashboards: list_dashboards, get_dashboard, search_panels
  • Alerts: list_alert_rules, get_alert_rule, list_firing_alerts
  • Folders: list_folders, get_folder

Authentication uses GRAFANA_URL, GRAFANA_API_KEY. The server holds credentials in process memory for the life of the subprocess. Nothing is written to disk by the server itself. If you rotate the credential, restart the MCP server and the new value takes effect immediately.

The server does not implement a local cache. Every tool call is a fresh round trip. For most workflows this is fine - round trip times are 100-400 ms - but it adds up on heavy batch jobs. For those, prefer the native SDK in a script.

Installing the server

The package ships on npm as mcp-grafana. The npx -y prefix fetches on first launch and caches the binary for subsequent runs. Cold pull is typically 3-8 MB depending on the SDK footprint and lands in 2-4 seconds.

Before touching editor config, get your credentials ready:

  1. Open your Grafana instance and navigate to Administration > Service accounts
  2. Click Add service account, name it claude-mcp-dev, and pick Viewer role
  3. On the service account page, click Add service account token
  4. Copy the token; it starts with glsa_ and is only shown once

Keep the credential values out of any file you commit. The rest of this guide assumes they live in your shell profile or a .envrc managed by direnv.

Configuring for Claude Code

Claude Code reads MCP servers from ~/.claude/mcp.json or a per-project .mcp.json. Add a grafana entry:

{
  "mcpServers": {
    "grafana": {
      "command": "npx",
      "args": ["-y", "mcp-grafana"],
      "env": {
        "GRAFANA_URL": "http://localhost:3000",
        "GRAFANA_API_KEY": "glsa_xxx"
      }
    }
  }
}

Restart Claude Code, then run /mcp in a session to confirm Grafana is attached. Call a read-only tool as a smoke test before any write operations. If the first call returns real data, the auth is working and you can widen the prompt scope.

For team projects, commit a placeholder version of .mcp.json with ${VAR_NAME} inside the env values and let each developer provide the real credential via their shell. Claude Code expands env vars when it spawns the subprocess.

Configuring for Cursor

Cursor uses the same MCP spec and reads from ~/.cursor/mcp.json. The config is identical to Claude Code:

{
  "mcpServers": {
    "grafana": {
      "command": "npx",
      "args": ["-y", "mcp-grafana"],
      "env": {
        "GRAFANA_URL": "http://localhost:3000",
        "GRAFANA_API_KEY": "glsa_xxx"
      }
    }
  }
}

Open Cursor settings, navigate to the MCP tab, and toggle the server on. Cursor spawns the subprocess lazily on the first tool call. Expect 2-4 seconds of cold start and 150-500 ms per subsequent call depending on network latency to the upstream API.

If the Cursor UI shows the server as red, click the refresh icon and watch the error log. Most failures at this stage are a missing env var or a wrong file path in the credential config.

Example prompts and workflows

A few prompts that work reliably once the server is attached:

  • "List every dashboard in folder production and group by tag."
  • "Run the Prometheus query rate(http_requests_total[5m]) and show the top 10 series."
  • "Search Loki for log lines containing error timeout in the last hour and group results by service."
  • "Get the alert rule HighLatency and show its current state and recent evaluations."
  • "Which datasources are currently unhealthy?"

The model will chain calls. A debugging flow usually runs list_firing_alerts, then get_alert_rule on the top alert, then a PromQL or LogQL query to expand the context. Tell Claude the data source name and time range up front - ambiguous prompts default to Prometheus and the last hour, which is often wrong.

One pattern that saves calls: narrow the scope up front. Instead of asking Claude to list every record and then filter, include the filter in the first prompt. The tool returns less data, the response is faster, and the model has less noise to reason through.

Troubleshooting

Tool call returns 401. Token expired or revoked. Regenerate under Service accounts and restart the server with the new value.

Tool call returns 403 on a dashboard. Service account lacks permission on that folder. Open the folder, add the service account as Viewer, and retry.

PromQL query returns empty. The metric does not exist in the selected range or the label set is wrong. Run label_values(metric_name, label) first to confirm available values.

Loki query times out. Loki range queries on high-cardinality logs are slow. Narrow the time range to 5-15 minutes, add a specific label filter, or use count_over_time to return aggregate counts instead of raw lines.

Alert rule state looks stale. Grafana evaluates alerts on a schedule (default 1 minute). If the state disagrees with reality, check the state_history in the alert rule tool and confirm the evaluation interval.

Server fails with ENOENT. npx is not on PATH in the env the editor inherits. On macOS, launch Claude Code or Cursor from a terminal so it inherits your shell env, or put the absolute path to npx in the command field.

Subprocess keeps restarting. The MCP transport is strict about newlines on stdio. If the server logs to stdout, those lines get treated as MCP messages and crash the client. Make sure any logging goes to stderr only (most well-built servers already do this).

Alternatives

A few options if the Grafana server does not fit your setup:

  • prometheus-mcp talks to Prometheus directly without going through Grafana - useful for scripted queries.
  • datadog-mcp covers the Datadog stack for teams on that platform.
  • honeycomb-mcp targets Honeycomb for observability teams focused on high-cardinality traces.

The MCP server pays off during incident response when Claude can pull alert state, run exploratory PromQL, and summarize dashboards without a context switch to the Grafana UI.

Performance notes and hardening

Steady-state call latency lands in the 150-500 ms range for most tools. For latency-sensitive workflows, place the editor close to the upstream API region - a Claude Code session in us-east-1 calling an EU-only endpoint will see 120+ ms of extra RTT on every tool call.

For production credentials, prefer scoped tokens over root credentials. Most services expose fine-grained permission models; use them. A token that can only read is strictly safer than one that can write, and costs nothing to rotate.

Log review is easier if you redirect MCP subprocess stderr to a file. Most editors do this by default, but not all surface the log path. On macOS, check ~/Library/Logs/Claude/ or the Cursor equivalent.

The Grafana MCP server is the right default for any workflow that already touches Grafana regularly. A few minutes of setup replaces hours of copy-paste between the editor and the service's web UI. Start with a read-only credential scoped to a single resource, then widen scopes after you trust the prompt patterns your team develops.

Guides

Frequently asked questions

Does it work with Grafana Cloud?

Yes. Use the cloud URL (like `https://yourcompany.grafana.net`) and a service account token generated in the cloud instance. No VPN setup needed as long as Claude Code can reach the public endpoint.

Can I run arbitrary PromQL queries?

Yes, through the `query_datasource` tool with a Prometheus data source selected. The server proxies the query through Grafana's `ds/query` endpoint, so all the usual PromQL features work.

Does the server support Grafana OnCall or alerting silences?

Not in the current release. Alert rules are read-only here. OnCall has a separate API and the silence management flow is kept out to reduce blast radius.

How are data source credentials handled?

The server never sees data source credentials directly. Queries go through Grafana's proxy endpoint, so Grafana injects credentials server-side. The service account token in the env var only authorizes the Grafana API call, not the underlying data source.

Can I export a dashboard as JSON?

Yes. The `get_dashboard` tool returns the full dashboard JSON including panels, templates, and variables. Save the output to a file for version control or migration between instances.

What about Tempo and Pyroscope data sources?

The `query_datasource` tool works for any data source Grafana knows about, including Tempo (traces) and Pyroscope (profiles). Syntax matches each backend's query language. Performance varies - trace queries across many days can take 10+ seconds.