You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$(error Neither GRAFANA_SERVICE_ACCOUNT_TOKEN nor GRAFANA_API_KEY is set. Please 'export GRAFANA_SERVICE_ACCOUNT_TOKEN=...' or use a tool like direnv to load it from .envrc. See https://grafana.com/docs/grafana/latest/administration/service-accounts/#add-a-token-to-a-service-account-in-grafana for details on creating service account tokens.)
43
+
else
44
+
$(warning GRAFANA_API_KEY is deprecated, please use GRAFANA_SERVICE_ACCOUNT_TOKEN instead)
45
+
endif
42
46
endif
43
47
GRAFANA_URL=https://mcptests.grafana-dev.net go test -v -count=1 -tags cloud ./tools
Copy file name to clipboardExpand all lines: README.md
+20-18Lines changed: 20 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -240,9 +240,11 @@ The `mcp-grafana` binary supports various command-line flags for configuration:
240
240
241
241
This MCP server works with both local Grafana instances and Grafana Cloud. For Grafana Cloud, use your instance URL (e.g., `https://myinstance.grafana.net`) instead of `http://localhost:3000` in the configuration examples below.
242
242
243
-
1. If using API key authentication, create a service account in Grafana with enough permissions to use the tools you want to use,
243
+
1. If using service account token authentication, create a service account in Grafana with enough permissions to use the tools you want to use,
244
244
generate a service account token, and copy it to the clipboard for use in the configuration file.
245
-
Follow the [Grafana documentation][service-account] for details.
245
+
Follow the [Grafana service account documentation][service-account] for details on creating service account tokens.
246
+
247
+
> **Note:** The environment variable `GRAFANA_API_KEY` is deprecated and will be removed in a future version. Please migrate to using `GRAFANA_SERVICE_ACCOUNT_TOKEN` instead. The old variable name will continue to work for backward compatibility but will show deprecation warnings.
246
248
247
249
2. You have several options to install `mcp-grafana`:
248
250
@@ -255,23 +257,23 @@ This MCP server works with both local Grafana instances and Grafana Cloud. For G
255
257
```bash
256
258
docker pull mcp/grafana
257
259
# For local Grafana:
258
-
docker run --rm -i -e GRAFANA_URL=http://localhost:3000 -e GRAFANA_API_KEY=<your service account token> mcp/grafana -t stdio
260
+
docker run --rm -i -e GRAFANA_URL=http://localhost:3000 -e GRAFANA_SERVICE_ACCOUNT_TOKEN=<your service account token> mcp/grafana -t stdio
259
261
# For Grafana Cloud:
260
-
docker run --rm -i -e GRAFANA_URL=https://myinstance.grafana.net -e GRAFANA_API_KEY=<your service account token> mcp/grafana -t stdio
262
+
docker run --rm -i -e GRAFANA_URL=https://myinstance.grafana.net -e GRAFANA_SERVICE_ACCOUNT_TOKEN=<your service account token> mcp/grafana -t stdio
261
263
```
262
264
263
265
2. **SSE Mode**: In this mode, the server runs as an HTTP server that clients connect to. You must expose port 8000 using the `-p` flag:
264
266
265
267
```bash
266
268
docker pull mcp/grafana
267
-
docker run --rm -p 8000:8000 -e GRAFANA_URL=http://localhost:3000 -e GRAFANA_API_KEY=<your service account token> mcp/grafana
269
+
docker run --rm -p 8000:8000 -e GRAFANA_URL=http://localhost:3000 -e GRAFANA_SERVICE_ACCOUNT_TOKEN=<your service account token> mcp/grafana
268
270
```
269
271
270
272
3. **Streamable HTTP Mode**: In this mode, the server operates as an independent process that can handle multiple client connections. You must expose port 8000 using the `-p` flag: For this mode you must explicitly override the default with `-t streamable-http`
271
273
272
274
```bash
273
275
docker pull mcp/grafana
274
-
docker run --rm -p 8000:8000 -e GRAFANA_URL=http://localhost:3000 -e GRAFANA_API_KEY=<your service account token> mcp/grafana -t streamable-http
276
+
docker run --rm -p 8000:8000 -e GRAFANA_URL=http://localhost:3000 -e GRAFANA_SERVICE_ACCOUNT_TOKEN=<your service account token> mcp/grafana -t streamable-http
275
277
```
276
278
277
279
For HTTPS streamable HTTP mode with server TLS certificates:
@@ -281,7 +283,7 @@ This MCP server works with both local Grafana instances and Grafana Cloud. For G
281
283
docker run --rm -p 8443:8443 \
282
284
-v /path/to/certs:/certs:ro \
283
285
-e GRAFANA_URL=http://localhost:3000 \
284
-
-e GRAFANA_API_KEY=<your service account token> \
286
+
-e GRAFANA_SERVICE_ACCOUNT_TOKEN=<your service account token> \
285
287
mcp/grafana \
286
288
-t streamable-http \
287
289
-addr :8443 \
@@ -318,7 +320,7 @@ This MCP server works with both local Grafana instances and Grafana Cloud. For G
318
320
"args": [],
319
321
"env": {
320
322
"GRAFANA_URL": "http://localhost:3000", // Or "https://myinstance.grafana.net"for Grafana Cloud
321
-
"GRAFANA_API_KEY": "<your service account token>",
323
+
"GRAFANA_SERVICE_ACCOUNT_TOKEN": "<your service account token>",
322
324
// If using username/password authentication
323
325
"GRAFANA_USERNAME": "<your username>",
324
326
"GRAFANA_PASSWORD": "<your password>"
@@ -344,14 +346,14 @@ This MCP server works with both local Grafana instances and Grafana Cloud. For G
344
346
"-e",
345
347
"GRAFANA_URL",
346
348
"-e",
347
-
"GRAFANA_API_KEY",
349
+
"GRAFANA_SERVICE_ACCOUNT_TOKEN",
348
350
"mcp/grafana",
349
351
"-t",
350
352
"stdio"
351
353
],
352
354
"env": {
353
355
"GRAFANA_URL": "http://localhost:3000", // Or "https://myinstance.grafana.net"for Grafana Cloud
354
-
"GRAFANA_API_KEY": "<your service account token>",
356
+
"GRAFANA_SERVICE_ACCOUNT_TOKEN": "<your service account token>",
355
357
// If using username/password authentication
356
358
"GRAFANA_USERNAME": "<your username>",
357
359
"GRAFANA_PASSWORD": "<your password>"
@@ -407,7 +409,7 @@ To use debug mode with the Claude Desktop configuration, update your config as f
407
409
"args": ["-debug"],
408
410
"env": {
409
411
"GRAFANA_URL": "http://localhost:3000", // Or "https://myinstance.grafana.net" for Grafana Cloud
410
-
"GRAFANA_API_KEY": "<your service account token>"
412
+
"GRAFANA_SERVICE_ACCOUNT_TOKEN": "<your service account token>"
411
413
}
412
414
}
413
415
}
@@ -428,15 +430,15 @@ To use debug mode with the Claude Desktop configuration, update your config as f
428
430
"-e",
429
431
"GRAFANA_URL",
430
432
"-e",
431
-
"GRAFANA_API_KEY",
433
+
"GRAFANA_SERVICE_ACCOUNT_TOKEN",
432
434
"mcp/grafana",
433
435
"-t",
434
436
"stdio",
435
437
"-debug"
436
438
],
437
439
"env": {
438
440
"GRAFANA_URL": "http://localhost:3000", // Or "https://myinstance.grafana.net" for Grafana Cloud
439
-
"GRAFANA_API_KEY": "<your service account token>"
441
+
"GRAFANA_SERVICE_ACCOUNT_TOKEN": "<your service account token>"
440
442
}
441
443
}
442
444
}
@@ -471,7 +473,7 @@ If your Grafana instance is behind mTLS or requires custom TLS certificates, you
// Fall back to the deprecated API key environment variable
49
+
apiKey=os.Getenv(grafanaAPIEnvVar)
50
+
ifapiKey!="" {
51
+
slog.Warn("GRAFANA_API_KEY is deprecated, please use GRAFANA_SERVICE_ACCOUNT_TOKEN instead. See https://grafana.com/docs/grafana/latest/administration/service-accounts/#add-a-token-to-a-service-account-in-grafana for details on creating service account tokens.")
// ExtractGrafanaInfoFromEnv is a StdioContextFunc that extracts Grafana configuration from environment variables.
274
-
// It reads GRAFANA_URL and GRAFANA_API_KEY environment variables and adds the configuration to the context for use by Grafana clients.
287
+
// It reads GRAFANA_URL and GRAFANA_SERVICE_ACCOUNT_TOKEN (or deprecated GRAFANA_API_KEY) environment variables and adds the configuration to the context for use by Grafana clients.
// ExtractGrafanaClientFromEnv is a StdioContextFunc that creates and injects a Grafana client into the context.
415
-
// It uses configuration from GRAFANA_URL, GRAFANA_API_KEY, GRAFANA_USERNAME/PASSWORD environment variables to initialize
428
+
// It uses configuration from GRAFANA_URL, GRAFANA_SERVICE_ACCOUNT_TOKEN (or deprecated GRAFANA_API_KEY), GRAFANA_USERNAME/PASSWORD environment variables to initialize
"GRAFANA_API_KEY is deprecated, please use GRAFANA_SERVICE_ACCOUNT_TOKEN instead. See https://grafana.com/docs/grafana/latest/administration/service-accounts/#add-a-token-to-a-service-account-in-grafana for details on creating service account tokens.",
43
+
DeprecationWarning,
44
+
)
36
45
37
46
ifnotauth_header:
38
47
pytest.skip("No authentication credentials available to create team")
elif (username:=os.environ.get("GRAFANA_USERNAME")) and (password:=os.environ.get("GRAFANA_USERNAME")):
54
+
importwarnings
55
+
56
+
warnings.warn(
57
+
"GRAFANA_API_KEY is deprecated, please use GRAFANA_SERVICE_ACCOUNT_TOKEN instead. See https://grafana.com/docs/grafana/latest/administration/service-accounts/#add-a-token-to-a-service-account-in-grafana for details on creating service account tokens.",
58
+
DeprecationWarning,
59
+
)
60
+
elif (username:=os.environ.get("GRAFANA_USERNAME")) and (
elif (username:=os.environ.get("GRAFANA_USERNAME")) and (password:=os.environ.get("GRAFANA_PASSWORD")):
78
+
importwarnings
79
+
80
+
warnings.warn(
81
+
"GRAFANA_API_KEY is deprecated, please use GRAFANA_SERVICE_ACCOUNT_TOKEN instead. See https://grafana.com/docs/grafana/latest/administration/service-accounts/#add-a-token-to-a-service-account-in-grafana for details on creating service account tokens.",
82
+
DeprecationWarning,
83
+
)
84
+
elif (username:=os.environ.get("GRAFANA_USERNAME")) and (
0 commit comments