Skip to content

Commit 4efbbb1

Browse files
authored
Add MCP usage guide for Grafana (#282)
Signed-off-by: Dan Barr <[email protected]> Co-authored-by: Dan Barr <[email protected]>
1 parent 8f30914 commit 4efbbb1

File tree

1 file changed

+229
-0
lines changed

1 file changed

+229
-0
lines changed
Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
---
2+
title: Grafana MCP server guide
3+
sidebar_label: Grafana
4+
description:
5+
Using the Grafana MCP server with ToolHive for dashboard management,
6+
datasource queries, alerting, and incident response.
7+
last_update:
8+
author: danbarr
9+
date: 2025-11-06
10+
---
11+
12+
## Overview
13+
14+
The official [Grafana MCP server](https://github.com/grafana/mcp-grafana)
15+
provides comprehensive access to your Grafana instance and its surrounding
16+
ecosystem. With support for dashboards, datasource queries (Prometheus, Loki,
17+
Pyroscope), alerting, incident management, Grafana OnCall, and Sift
18+
investigations, this server enables AI agents to interact with your entire
19+
observability stack.
20+
21+
The server works with both local Grafana instances and Grafana Cloud, making it
22+
ideal for tasks like troubleshooting production issues, analyzing metrics and
23+
logs, managing dashboards, and coordinating incident response.
24+
25+
## Metadata
26+
27+
<MCPMetadata name='grafana' />
28+
29+
## Usage
30+
31+
You'll need a Grafana service account token to authenticate with the Grafana
32+
API. The token must have permissions for the Grafana features you want to access
33+
(such as dashboards, datasources, or alerting). Refer to the
34+
[Grafana service account documentation](https://grafana.com/docs/grafana/latest/administration/service-accounts/)
35+
for details on creating tokens and configuring permissions.
36+
37+
<Tabs groupId='mode' queryString='mode'>
38+
<TabItem value='ui' label='UI' default>
39+
40+
Select the `grafana` MCP server in the ToolHive registry.
41+
42+
In the **Secrets** section, add your Grafana service account token or select an
43+
existing secret that contains the token.
44+
45+
In the **Environment Variables** section, configure the connection to your
46+
Grafana instance:
47+
48+
- `GRAFANA_URL`: Your Grafana instance URL (for example, `http://localhost:3000`
49+
for local instances or `https://myinstance.grafana.net` for Grafana Cloud)
50+
- `GRAFANA_ORG_ID` (optional): The numeric organization ID if your Grafana
51+
instance has multiple organizations
52+
53+
:::tip[Security tip]
54+
55+
Enable outbound network filtering on the **Network Isolation** tab to restrict
56+
the server's network access. Update the allowed hosts to match your Grafana
57+
instance domain.
58+
59+
:::
60+
61+
</TabItem>
62+
<TabItem value='cli' label='CLI'>
63+
64+
Create a secret containing your Grafana service account token:
65+
66+
```bash
67+
thv secret set grafana-token
68+
```
69+
70+
Run the server with your Grafana instance URL and the secret:
71+
72+
```bash
73+
thv run \
74+
-e GRAFANA_URL=http://localhost:3000 \
75+
--secret grafana-token,target=GRAFANA_SERVICE_ACCOUNT_TOKEN \
76+
grafana
77+
```
78+
79+
For Grafana Cloud, use your cloud instance URL:
80+
81+
```bash
82+
thv run \
83+
-e GRAFANA_URL=https://myinstance.grafana.net \
84+
--secret grafana-token,target=GRAFANA_SERVICE_ACCOUNT_TOKEN \
85+
grafana
86+
```
87+
88+
Enable [network isolation](../guides-cli/network-isolation.mdx) to restrict the
89+
server's network access. Create a permission profile with your Grafana instance
90+
domain:
91+
92+
```json title="grafana-profile.json"
93+
{
94+
"network": {
95+
"outbound": {
96+
"insecure_allow_all": false,
97+
"allow_host": ["myinstance.grafana.net"],
98+
"allow_port": [443]
99+
}
100+
}
101+
}
102+
```
103+
104+
Then run with the custom profile:
105+
106+
```bash
107+
thv run \
108+
-e GRAFANA_URL=https://myinstance.grafana.net \
109+
--secret grafana-token,target=GRAFANA_SERVICE_ACCOUNT_TOKEN \
110+
--isolate-network --permission-profile grafana-profile.json \
111+
grafana
112+
```
113+
114+
If your Grafana instance has multiple organizations, add the `GRAFANA_ORG_ID`
115+
environment variable with the numeric organization ID (for example,
116+
`-e GRAFANA_ORG_ID=2`).
117+
118+
:::tip[Debug mode]
119+
120+
Add the `--` separator followed by `-debug` to enable detailed logging of HTTP
121+
requests and responses:
122+
123+
```bash
124+
thv run \
125+
-e GRAFANA_URL=http://localhost:3000 \
126+
--secret grafana-token,target=GRAFANA_SERVICE_ACCOUNT_TOKEN \
127+
-- -debug
128+
```
129+
130+
:::
131+
132+
</TabItem>
133+
<TabItem value='k8s' label='Kubernetes'>
134+
135+
Create a Kubernetes secret containing your Grafana service account token:
136+
137+
```bash
138+
kubectl -n toolhive-system create secret generic grafana-token \
139+
--from-literal=token=<YOUR_TOKEN>
140+
```
141+
142+
Create a Kubernetes manifest to deploy the Grafana MCP server:
143+
144+
```yaml {14-17} title="grafana.yaml"
145+
apiVersion: toolhive.stacklok.dev/v1alpha1
146+
kind: MCPServer
147+
metadata:
148+
name: grafana
149+
namespace: toolhive-system
150+
spec:
151+
image: docker.io/mcp/grafana:latest
152+
transport: sse
153+
mcpPort: 8000
154+
proxyPort: 8080
155+
env:
156+
- name: GRAFANA_URL
157+
value: 'http://localhost:3000'
158+
secrets:
159+
- name: grafana-token
160+
key: token
161+
targetEnvName: GRAFANA_SERVICE_ACCOUNT_TOKEN
162+
```
163+
164+
Apply the manifest to your Kubernetes cluster:
165+
166+
```bash
167+
kubectl apply -f grafana.yaml
168+
```
169+
170+
For Grafana Cloud, update the `GRAFANA_URL` in the manifest:
171+
172+
```yaml
173+
spec:
174+
env:
175+
- name: GRAFANA_URL
176+
value: 'https://myinstance.grafana.net'
177+
```
178+
179+
If your Grafana instance has multiple organizations, add the `GRAFANA_ORG_ID`
180+
environment variable with the numeric organization ID:
181+
182+
```yaml
183+
spec:
184+
env:
185+
- name: GRAFANA_URL
186+
value: 'http://localhost:3000'
187+
- name: GRAFANA_ORG_ID
188+
value: '2'
189+
```
190+
191+
</TabItem>
192+
</Tabs>
193+
194+
## Sample prompts
195+
196+
Here are some sample prompts you can use to interact with the Grafana MCP
197+
server:
198+
199+
- "Show me all dashboards related to Kubernetes monitoring"
200+
- "Query the Prometheus datasource for CPU usage over the last hour for the
201+
`api-service` pod"
202+
- "Get the recent alerts that are currently firing"
203+
- "List all open incidents and show me details for the most recent one"
204+
- "Find error patterns in the logs from the `production` namespace using Loki"
205+
- "Who is currently on call for the backend team schedule?"
206+
- "Create a new incident titled 'High memory usage on production cluster' with
207+
severity critical"
208+
- "Show me the panel queries from the 'API Performance' dashboard"
209+
- "Get label values for the `namespace` label from the Loki datasource"
210+
- "List all Sift investigations from the past week"
211+
212+
## Recommended practices
213+
214+
- Create service accounts with least-privilege permissions. Use fine-grained
215+
RBAC scopes to limit access to only the datasources, dashboards, and features
216+
required for your specific use case.
217+
- Regularly rotate service account tokens and update the secrets in ToolHive.
218+
- Enable network isolation to restrict the server's outbound network access to
219+
your Grafana instance domain only.
220+
- For dashboards with large JSON configurations, use the `get_dashboard_summary`
221+
or `get_dashboard_property` tools to minimize context window usage instead of
222+
retrieving the full dashboard with `get_dashboard_by_uid`.
223+
- When working with multi-organization setups, always specify the
224+
`GRAFANA_ORG_ID` to ensure operations target the correct organization.
225+
- Enable [telemetry](../guides-cli/telemetry-and-metrics.mdx) to monitor API
226+
calls and track which Grafana resources are being accessed.
227+
- For production deployments, consider using the debug mode temporarily to
228+
troubleshoot connection or permission issues, but disable it once everything
229+
is working correctly.

0 commit comments

Comments
 (0)