Home › Guides › Grafana MCP with Claude Code

Grafana MCP Server with Claude Code

Ask Claude Code, in plain English, how a server is doing. It queries Grafana for real and answers with CPU, memory, disk and log data. Then it builds a dashboard for you. This is the written version of my video: the service account, the one command that connects it, the questions I asked, and the settings that keep it safe.

What the Grafana MCP server does

MCP, the Model Context Protocol, is how an AI assistant uses outside tools. The Grafana MCP server is an open source program from Grafana Labs. Claude Code starts it, and through it, Claude can search dashboards, run Prometheus and Loki queries, read alerts and create dashboards. It talks to Grafana's API with a token you give it.

Youa question in plain English→ Claude Codepicks a tool→ Grafana MCP serverDocker container→ Grafana APIPrometheus, Loki, alerts

How does Claude know what to do? Every tool comes with a name and a description, like "query Prometheus" or "search dashboards". Claude reads those, picks the right tool for your question, and fills in the arguments. The MCP server runs the call against Grafana and hands back the result.

What you need

Step 1: create a service account

The MCP server needs its own login: a service account. Don't use your personal account for this.

  1. In Grafana, open Administration → Users and access → Service accounts.
  2. Click Add service account.
  3. Name it claude.
  4. Pick a role (see the table), then click Create.
RoleWhat Claude can doUse it for
ViewerRead only. Search dashboards, query metrics and logs, read alert rules.Questions and troubleshooting.
EditorEverything Viewer can, plus create and change dashboards.Letting Claude build dashboards, like in this guide.

I picked Editor in the video because Claude builds a dashboard later. If you only want answers, pick Viewer.

Step 2: create the token

  1. On the new service account, click Add service account token.
  2. Click Generate token.
  3. Copy the token. It starts with glsa_.

Grafana shows the token only once. Copy it now. If you lose it, delete it and generate a new one. Treat it like a password: anyone with it can do whatever the service account's role allows.

Step 3: add the server to Claude Code

Open a terminal in your project folder. One command adds the server. Replace the URL with your Grafana address and the token with the one you just copied:

claude mcp add grafana --env GRAFANA_URL=https://YOUR-STACK.grafana.net --env GRAFANA_SERVICE_ACCOUNT_TOKEN=glsa_xxx -- docker run --rm -i -e GRAFANA_URL -e GRAFANA_SERVICE_ACCOUNT_TOKEN mcp/grafana -t stdio

What each part does:

PartMeaning
claude mcp add grafanaAdds an MCP server named grafana.
--env GRAFANA_URL=...Your Grafana address. For Grafana Cloud, that's https://YOUR-STACK.grafana.net.
--env GRAFANA_SERVICE_ACCOUNT_TOKEN=...The token from step 2.
--Everything after the double dash is the command Claude Code runs to start the server.
docker run --rm -iStarts a container, keeps its input open so Claude Code can talk to it, and removes it when it stops.
-e GRAFANA_URL -e GRAFANA_SERVICE_ACCOUNT_TOKENPasses the two values into the container.
mcp/grafanaThe official Grafana MCP server image.
-t stdioTalks to Claude Code over standard input and output.

Tip: self-hosted Grafana on the same machine. Inside the container, localhost is the container itself, not your computer. With Docker Desktop, use http://host.docker.internal:3000 as GRAFANA_URL instead of http://localhost:3000.

Where the server is saved

By default the server is saved for this project folder only, in your own Claude Code settings, not in a file in the project. That's good, because the token never ends up in git. The --scope flag changes that:

ScopeAvailable inStored
local (default)This project folder, only for youYour Claude Code config, outside the project
projectEveryone who opens this projectA .mcp.json file in the project, meant to be committed
userEvery project on your computerYour Claude Code config, outside the project

Add --scope user right after claude mcp add if you want Grafana in every project.

Tip: don't put the token in --scope project. That writes it into .mcp.json, a file you commit. Keep the token in your own config, and never paste it into files that go into git.

Step 4: check the connection

claude mcp list

The grafana line should end with Connected:

grafana: docker run --rm -i -e GRAFANA_URL -e GRAFANA_SERVICE_ACCOUNT_TOKEN mcp/grafana -t stdio - ✓ Connected

Now start Claude Code with claude and type /mcp. The Grafana server is listed as connected. Select it to see its tools: dashboards, Prometheus, Loki, alerting and more.

Step 5: ask Grafana questions

These are the prompts from the video. Swap web-01 for one of your own hosts.

PromptWhat Claude does
"Which dashboards do I have in Grafana?"Calls the dashboard search tool and lists them with their folders.
"How is the server web-01 doing right now? CPU, memory and disk."Finds the Prometheus data source, writes the PromQL queries itself, and answers with real numbers.
"Anything unusual in web-01's logs in the last hour?"Queries Loki, reads the log lines, and gives a short summary with the lines that matter.
"Which alert rules do I have, and is anything firing right now?"Uses the alerting tools to list every rule with its current state, and explains why nothing fired.

I didn't write a single line of PromQL. All of the answers come from Grafana's own APIs. Claude only reads them through the MCP tools.

Tip: stop the permission prompts. By default Claude Code asks before every tool call. In the video I allowed the Grafana tools for that folder, in .claude/settings.json:

{
  "permissions": {
    "allow": ["mcp__grafana"]
  }
}

Only do this with a service account whose role you are happy with. With an Editor token, it also means Claude changes dashboards without asking.

See the PromQL it wrote

Want to see what it actually ran? Press Ctrl+O to expand the tool calls. Scroll up to the Prometheus call and there is the exact PromQL query it wrote. Press Ctrl+O again to go back.

It's a nice way to learn PromQL, too: ask in plain English, then read the query it chose. It's also how you check that the answer is based on the metric you think it is.

Step 6: let Claude build a dashboard

This needs the Editor role. The prompt from the video:

Create a Grafana dashboard for web-01 with CPU, memory and disk usage, and its latest logs. Call it "web-01 by Claude".

Claude writes the dashboard, saves it through the API, and tells you its name. Open it in Grafana: it's a real dashboard with real queries on live data, in the same place as your other dashboards.

Every panel is normal Grafana. Open a panel's menu and click Edit, and there's the PromQL query Claude wrote. You can change it like any other panel.

Ask for changes

You can keep talking to it. Back in Claude Code:

In the "web-01 by Claude" dashboard, make the CPU panel a gauge and add a panel for network traffic.

It updates the same dashboard. Reload it in Grafana and both changes are there. That's a much faster way to get a first version, which you then polish by hand.

Tip: continue where you left off. If you closed Claude Code, claude --continue reopens the last conversation in that folder, so it still knows which dashboard you mean.

Keep it safe

Here is the setting that matters most: Claude can only do what the service account is allowed to do. No prompt can get past the role behind the token.

claude mcp add grafana --env GRAFANA_URL=https://YOUR-STACK.grafana.net --env GRAFANA_SERVICE_ACCOUNT_TOKEN=glsa_xxx -- docker run --rm -i -e GRAFANA_URL -e GRAFANA_SERVICE_ACCOUNT_TOKEN mcp/grafana -t stdio --disable-write

If the server is already added, remove it first with claude mcp remove grafana, then add it again.

There are also flags to switch off whole tool groups you don't use, like --disable-oncall. Fewer tools means Claude has less to choose from, so it picks the right one more often.

Tip: review what it does. Keep the token out of git and out of screenshots. Read the tool calls with Ctrl+O before you trust a number, and look at a dashboard Claude built before you share it. If a token leaks, delete it on the service account page and generate a new one.

If the server won't connect

What you seeWhat to do
claude mcp list says Failed Start Docker first, then run claude mcp list again.
The server connects, but the tools return errors Check the token, and the service account's role.
Claude can read, but can't create a dashboard The service account is Viewer, or --disable-write is set. That's the safe setup working.
Self-hosted Grafana on the same machine can't be reached Tip: use host.docker.internal instead of localhost in GRAFANA_URL.

Watch the video

The whole setup in six minutes: the service account, the command, the questions about metrics, logs and alerts, the dashboard Claude builds and edits, and the safety flags.

Related

Want AI tools on top of monitoring you can trust?

An assistant like this is only as good as the data behind it. If you'd like monitoring and observability set up properly, including AI tools like this one on top of your Grafana, that's what I do. I'm a Grafana Champion, and I help teams through KorFlux. Tell me what you run and what you want to ask it.