123DevOps··5 min read

Installing Grafana (Docker, Linux, and Kubernetes) and the Grafana MCP server for use with AI assistants

A step-by-step guide to installing Grafana, provisioning data sources as code, creating a service account, and connecting the Grafana MCP server to Claude and other assistants — with least-privilege permissions.

Observability

Grafana is the starting point of almost every open source observability stack. And with MCP (Model Context Protocol), it has also become a source of context for AI assistants: instead of copying and pasting charts into the chat, the assistant queries dashboards, metrics, and logs directly — with whatever permissions you give it.

In this guide, we install Grafana in three ways, configure data sources as code, and connect the Grafana MCP server.

Part 1: installing Grafana

Option A: Docker (to try it out in minutes)

docker run -d --name grafana -p 3000:3000 \
  -e GF_SECURITY_ADMIN_PASSWORD='change-this-password' \
  -v grafana-data:/var/lib/grafana \
  grafana/grafana

Go to http://localhost:3000 and log in as admin. The grafana-data volume preserves dashboards and settings when the container is recreated.

Option B: Linux with the official package (Debian/Ubuntu)

sudo apt-get install -y apt-transport-https software-properties-common wget
sudo mkdir -p /etc/apt/keyrings/
wget -q -O - https://apt.grafana.com/gpg.key | gpg --dearmor | sudo tee /etc/apt/keyrings/grafana.gpg > /dev/null
echo "deb [signed-by=/etc/apt/keyrings/grafana.gpg] https://apt.grafana.com stable main" | sudo tee /etc/apt/sources.list.d/grafana.list
sudo apt-get update
sudo apt-get install -y grafana
sudo systemctl enable --now grafana-server

The configuration lives in /etc/grafana/grafana.ini. For RPM-based distributions, there is an equivalent repository in the official documentation.

Option C: Kubernetes with Helm

helm repo add grafana https://grafana.github.io/helm-charts
helm repo update
helm install grafana grafana/grafana \
  --namespace observability --create-namespace \
  --set persistence.enabled=true

# initial admin password
kubectl get secret -n observability grafana \
  -o jsonpath="{.data.admin-password}" | base64 --decode; echo

If you are also going to install Prometheus, Alertmanager, and exporters, the kube-prometheus-stack chart already includes a preconfigured Grafana — see configuring Prometheus.

Part 2: essential settings

Environment variables prefixed with GF_ override any option in grafana.ini. The most important ones for production:

GF_SERVER_ROOT_URL=https://grafana.example.com
GF_SECURITY_ADMIN_PASSWORD__FILE=/run/secrets/grafana_admin   # password read from a file/secret
GF_USERS_ALLOW_SIGN_UP=false
GF_AUTH_ANONYMOUS_ENABLED=false
GF_DATABASE_TYPE=postgres                                      # the default SQLite won't work with multiple replicas

For teams, configure SSO (generic OAuth, Google, GitHub, Azure AD/Entra, Okta, or SAML) and map groups to Grafana roles (Viewer, Editor, Admin).

Data sources as code (provisioning)

Instead of configuring data sources through the UI, declare them in files — that way the environment is reproducible:

# /etc/grafana/provisioning/datasources/datasources.yaml
apiVersion: 1
datasources:
  - name: Prometheus
    type: prometheus
    access: proxy
    url: http://prometheus:9090
    isDefault: true
  - name: Loki
    type: loki
    access: proxy
    url: http://loki:3100
  - name: Tempo
    type: tempo
    access: proxy
    url: http://tempo:3200

The same mechanism provisions dashboards and alert rules, as we show in building dashboards.

Part 3: what the Grafana MCP server is

The Model Context Protocol is an open standard for connecting AI assistants to external tools and data. The Grafana MCP server (the grafana/mcp-grafana project) exposes tools to the assistant such as:

  • Searching dashboards and reading their panels and queries;
  • Listing data sources;
  • Running PromQL and LogQL queries;
  • Looking up alert rules, incidents, and on-call schedules (when those features are available in your instance).

In practice, you can ask the assistant: “Which services saw an increase in 5xx errors in the last hour? Show me the checkout error logs for that period” — and it queries Grafana to answer.

Part 4: creating a least-privilege service account

The MCP server acts with the permissions of the token you hand it. Follow the principle of least privilege:

  1. In Grafana, go to Administration → Users and access → Service accounts.
  2. Create an account, for example ai-assistant, with the Viewer role.
  3. Generate a token and store it in a secrets manager.
  4. Only grant Editor if you really want the assistant to create or modify dashboards — and preferably in a separate instance or folder.

Part 5: connecting the MCP server to the assistant

The MCP client configuration (such as Claude Desktop) looks like this:

{
  "mcpServers": {
    "grafana": {
      "command": "docker",
      "args": [
        "run", "--rm", "-i",
        "-e", "GRAFANA_URL",
        "-e", "GRAFANA_SERVICE_ACCOUNT_TOKEN",
        "mcp/grafana", "-t", "stdio"
      ],
      "env": {
        "GRAFANA_URL": "http://host.docker.internal:3000",
        "GRAFANA_SERVICE_ACCOUNT_TOKEN": "<your-token>"
      }
    }
  }
}

Use host.docker.internal when Grafana runs on your own machine; for a remote instance, use its URL.

In Claude Code (terminal)

claude mcp add grafana \
  -e GRAFANA_URL=https://grafana.example.com \
  -e GRAFANA_SERVICE_ACCOUNT_TOKEN="$GRAFANA_TOKEN" \
  -- docker run --rm -i -e GRAFANA_URL -e GRAFANA_SERVICE_ACCOUNT_TOKEN mcp/grafana -t stdio

Without Docker

The server can also be installed as a Go binary:

go install github.com/grafana/mcp-grafana/cmd/mcp-grafana@latest

In that case, configure the MCP client to run mcp-grafana with the same environment variables. Variable and option names may change between versions — check the project’s README.

Security: what to consider

  • Least privilege, always: Viewer by default, tokens with expiration and rotation.
  • Sensitive data: everything the assistant queries (including logs) is sent to the AI model. If your logs contain personal data, mask it before ingestion with telemetry pipelines and review the AI provider’s policies.
  • Prompt injection: log content is third-party-controlled text (a malicious request can write instructions into a log). Treat the assistant’s output as a suggestion and review any action with side effects.
  • Auditing: use a dedicated service account so you can identify in Grafana’s audit log what the assistant queried.

Checklist

  • Grafana installed with persistence and the admin password changed
  • External database (PostgreSQL/MySQL) for installations with multiple replicas
  • SSO configured and open sign-up disabled
  • Data sources provisioned as code
  • Dedicated service account for MCP, with the Viewer role
  • MCP server connected and tested with a simple query
  • Logs free of personal data before granting the assistant access

Grafana shows you what’s happening. With MCP, you can also ask — as long as the assistant sees only what it needs to see.

Get updates on new posts and stay in the loop!