Grafana MCP Server
MCP server exposing 50+ Grafana API tools. Supports Grafana 9.0+ (local and Grafana Cloud).
Prerequisites
The MCP server must already be installed. Do not attempt to install it automatically. If it is not available, stop and tell the user to install it first.
Installation instructions, pre-built binaries, Docker images, and Helm charts: github.com/grafana/mcp-grafana
Configuration
Environment variables
| Variable |
Description |
GRAFANA_URL |
Grafana instance URL (default: http://localhost:3000) |
GRAFANA_SERVICE_ACCOUNT_TOKEN |
Service account token (recommended) |
GRAFANA_API_KEY |
API key (deprecated, use service account token) |
GRAFANA_USERNAME + GRAFANA_PASSWORD |
Basic auth |
GRAFANA_ORG_ID |
Organization ID for multi-org setups |
GRAFANA_EXTRA_HEADERS |
JSON object with custom HTTP headers |
Setup steps
Create a service account in Grafana with at least Viewer role (or Editor for write operations). Generate a token.
Set environment variables:
export GRAFANA_URL="https://mystack.grafana.net"
export GRAFANA_SERVICE_ACCOUNT_TOKEN="glsa_..."
The MCP server starts automatically when Cursor loads the plugin.
Docker config for local Grafana
When connecting to localhost from Docker, use host.docker.internal:
{
"env": {
"GRAFANA_URL": "http://host.docker.internal:3000"
}
}
Binary config (alternative to Docker)
If you prefer the binary over Docker, update mcp.json:
{
"mcpServers": {
"grafana": {
"command": "mcp-grafana",
"args": [],
"env": {
"GRAFANA_URL": "${GRAFANA_URL}",
"GRAFANA_SERVICE_ACCOUNT_TOKEN": "${GRAFANA_SERVICE_ACCOUNT_TOKEN}"
}
}
}
}
CLI flags
| Flag |
Description |
-t, --transport |
Transport type: stdio (default), sse, streamable-http |
--address |
Host:port for SSE/HTTP (default: localhost:8000) |
--debug |
Enable debug logging |
--log-level |
debug, info, warn, error |
--disable-write |
Read-only mode (no create/update/delete tools) |
--enabled-tools |
Comma-separated list of enabled tool categories |
--metrics |
Enable Prometheus metrics at /metrics |
Tool categories
Dashboards
search_dashboards — search by title/metadata
get_dashboard_summary — compact overview (preferred over full JSON)
get_dashboard_property — extract specific parts via JSONPath
get_dashboard_panel_queries — get panel queries and datasource info
get_dashboard_by_uid — full dashboard JSON (large, avoid unless needed)
update_dashboard — create or update a dashboard
patch_dashboard — targeted modifications without full JSON
Datasources
list_datasources — list all datasources
get_datasource_by_uid / get_datasource_by_name — get datasource details
Prometheus
query_prometheus — execute PromQL queries
list_prometheus_metric_metadata — get metric metadata
list_prometheus_metric_names — list available metrics
list_prometheus_label_names / list_prometheus_label_values — label discovery
query_prometheus_histogram — calculate histogram percentiles
Loki
query_loki_logs — query logs/metrics using LogQL
list_loki_label_names / list_loki_label_values — label discovery
query_loki_stats — stream statistics
query_loki_patterns — detected log patterns
Alerting
list_alert_rules / get_alert_rule_by_uid — read alert rules
create_alert_rule / update_alert_rule / delete_alert_rule — manage rules
list_contact_points — notification endpoints
Incidents
list_incidents / get_incident — read incidents
create_incident / add_activity_to_incident — manage incidents
OnCall
list_oncall_schedules / get_oncall_shift / get_current_oncall_users — schedules
list_oncall_teams / list_oncall_users — team/user discovery
list_alert_groups / get_alert_group — alert groups
Sift (investigation)
list_sift_investigations / get_sift_investigation / get_sift_analysis
find_error_pattern_logs / find_slow_requests
Pyroscope (profiling)
list_pyroscope_label_names / list_pyroscope_label_values
list_pyroscope_profile_types / fetch_pyroscope_profile
Annotations
get_annotations / create_annotation / update_annotation / patch_annotation
create_graphite_annotation / get_annotation_tags
Navigation
generate_deeplink — generate URLs for dashboards, panels, Explore
Rendering
get_panel_image — render panel/dashboard as PNG (requires Image Renderer)
Disabled by default
These categories must be explicitly enabled with --enabled-tools:
- ClickHouse:
list_clickhouse_tables, describe_clickhouse_table, query_clickhouse
- CloudWatch:
list_cloudwatch_namespaces, list_cloudwatch_metrics, list_cloudwatch_dimensions, query_cloudwatch
- Elasticsearch:
query_elasticsearch
- Admin:
list_teams, list_users_by_org, list_all_roles, get_role_details, get_role_assignments
- Search Logs:
search_logs (high-level across ClickHouse and Loki)
- Query Examples:
get_query_examples
Best practices
Context window management
- Use
get_dashboard_summary instead of get_dashboard_by_uid to avoid consuming context with full dashboard JSON.
- Use
get_dashboard_property with JSONPath to extract only the specific parts you need.
- Prefer
patch_dashboard for targeted modifications over update_dashboard with full payload.
- Use
search_dashboards to discover dashboards before retrieving by UID.
- When presenting Grafana data, use
generate_deeplink to provide clickable URLs rather than describing navigation steps.
Querying
- When querying Prometheus, always specify a reasonable time range to avoid overwhelming results.
- When querying Loki, prefer targeted LogQL selectors with label matchers over broad queries.
- Use datasource discovery tools (
list_datasources, list_prometheus_metric_names) before writing queries.
Safety
- Avoid write operations (
update_dashboard, create_incident, create_alert_rule) unless explicitly asked by the user.
- Use
--disable-write flag for read-only mode when write access isn't needed.
- Disable unused tool categories with
--enabled-tools to reduce attack surface and context usage.
RBAC
- Viewer role: sufficient for all read operations (dashboards, datasources, queries, annotations)
- Editor role: required for write operations (create/update dashboards, alerts, incidents)
- For fine-grained control, use custom roles with specific permissions per tool (see mcp-grafana README for the full RBAC matrix)
1---2name: grafana-mcp-tools3description: Install, configure, and use the Grafana MCP server effectively. Covers setup via Docker or binary, environment variables, tool categories, RBAC, and best practices for context window management. Use when the user wants to set up mcp-grafana, configure Grafana MCP tools, or needs guidance on which MCP tool to use.4---56# Grafana MCP Server78MCP server exposing 50+ Grafana API tools. Supports Grafana 9.0+ (local and Grafana Cloud).910## Prerequisites1112The MCP server must already be installed. **Do not attempt to install it automatically.** If it is not available, stop and tell the user to install it first.1314Installation instructions, pre-built binaries, Docker images, and Helm charts: [github.com/grafana/mcp-grafana](https://github.com/grafana/mcp-grafana)1516## Configuration1718### Environment variables1920| Variable | Description |21|---|---|22| `GRAFANA_URL` | Grafana instance URL (default: `http://localhost:3000`) |23| `GRAFANA_SERVICE_ACCOUNT_TOKEN` | Service account token (recommended) |24| `GRAFANA_API_KEY` | API key (deprecated, use service account token) |25| `GRAFANA_USERNAME` + `GRAFANA_PASSWORD` | Basic auth |26| `GRAFANA_ORG_ID` | Organization ID for multi-org setups |27| `GRAFANA_EXTRA_HEADERS` | JSON object with custom HTTP headers |2829### Setup steps30311. Create a [service account](https://grafana.com/docs/grafana/latest/administration/service-accounts/) in Grafana with at least **Viewer** role (or **Editor** for write operations). Generate a token.32332. Set environment variables:34 ```bash35 export GRAFANA_URL="https://mystack.grafana.net"36 export GRAFANA_SERVICE_ACCOUNT_TOKEN="glsa_..."37 ```38393. The MCP server starts automatically when Cursor loads the plugin.4041### Docker config for local Grafana4243When connecting to `localhost` from Docker, use `host.docker.internal`:4445```json46{47 "env": {48 "GRAFANA_URL": "http://host.docker.internal:3000"49 }50}51```5253### Binary config (alternative to Docker)5455If you prefer the binary over Docker, update `mcp.json`:5657```json58{59 "mcpServers": {60 "grafana": {61 "command": "mcp-grafana",62 "args": [],63 "env": {64 "GRAFANA_URL": "${GRAFANA_URL}",65 "GRAFANA_SERVICE_ACCOUNT_TOKEN": "${GRAFANA_SERVICE_ACCOUNT_TOKEN}"66 }67 }68 }69}70```7172## CLI flags7374| Flag | Description |75|---|---|76| `-t, --transport` | Transport type: `stdio` (default), `sse`, `streamable-http` |77| `--address` | Host:port for SSE/HTTP (default: `localhost:8000`) |78| `--debug` | Enable debug logging |79| `--log-level` | `debug`, `info`, `warn`, `error` |80| `--disable-write` | Read-only mode (no create/update/delete tools) |81| `--enabled-tools` | Comma-separated list of enabled tool categories |82| `--metrics` | Enable Prometheus metrics at `/metrics` |8384## Tool categories8586### Dashboards8788- `search_dashboards` — search by title/metadata89- `get_dashboard_summary` — compact overview (preferred over full JSON)90- `get_dashboard_property` — extract specific parts via JSONPath91- `get_dashboard_panel_queries` — get panel queries and datasource info92- `get_dashboard_by_uid` — full dashboard JSON (large, avoid unless needed)93- `update_dashboard` — create or update a dashboard94- `patch_dashboard` — targeted modifications without full JSON9596### Datasources9798- `list_datasources` — list all datasources99- `get_datasource_by_uid` / `get_datasource_by_name` — get datasource details100101### Prometheus102103- `query_prometheus` — execute PromQL queries104- `list_prometheus_metric_metadata` — get metric metadata105- `list_prometheus_metric_names` — list available metrics106- `list_prometheus_label_names` / `list_prometheus_label_values` — label discovery107- `query_prometheus_histogram` — calculate histogram percentiles108109### Loki110111- `query_loki_logs` — query logs/metrics using LogQL112- `list_loki_label_names` / `list_loki_label_values` — label discovery113- `query_loki_stats` — stream statistics114- `query_loki_patterns` — detected log patterns115116### Alerting117118- `list_alert_rules` / `get_alert_rule_by_uid` — read alert rules119- `create_alert_rule` / `update_alert_rule` / `delete_alert_rule` — manage rules120- `list_contact_points` — notification endpoints121122### Incidents123124- `list_incidents` / `get_incident` — read incidents125- `create_incident` / `add_activity_to_incident` — manage incidents126127### OnCall128129- `list_oncall_schedules` / `get_oncall_shift` / `get_current_oncall_users` — schedules130- `list_oncall_teams` / `list_oncall_users` — team/user discovery131- `list_alert_groups` / `get_alert_group` — alert groups132133### Sift (investigation)134135- `list_sift_investigations` / `get_sift_investigation` / `get_sift_analysis`136- `find_error_pattern_logs` / `find_slow_requests`137138### Pyroscope (profiling)139140- `list_pyroscope_label_names` / `list_pyroscope_label_values`141- `list_pyroscope_profile_types` / `fetch_pyroscope_profile`142143### Annotations144145- `get_annotations` / `create_annotation` / `update_annotation` / `patch_annotation`146- `create_graphite_annotation` / `get_annotation_tags`147148### Navigation149150- `generate_deeplink` — generate URLs for dashboards, panels, Explore151152### Rendering153154- `get_panel_image` — render panel/dashboard as PNG (requires Image Renderer)155156### Disabled by default157158These categories must be explicitly enabled with `--enabled-tools`:159160- **ClickHouse**: `list_clickhouse_tables`, `describe_clickhouse_table`, `query_clickhouse`161- **CloudWatch**: `list_cloudwatch_namespaces`, `list_cloudwatch_metrics`, `list_cloudwatch_dimensions`, `query_cloudwatch`162- **Elasticsearch**: `query_elasticsearch`163- **Admin**: `list_teams`, `list_users_by_org`, `list_all_roles`, `get_role_details`, `get_role_assignments`164- **Search Logs**: `search_logs` (high-level across ClickHouse and Loki)165- **Query Examples**: `get_query_examples`166167## Best practices168169### Context window management170171- Use `get_dashboard_summary` instead of `get_dashboard_by_uid` to avoid consuming context with full dashboard JSON.172- Use `get_dashboard_property` with JSONPath to extract only the specific parts you need.173- Prefer `patch_dashboard` for targeted modifications over `update_dashboard` with full payload.174- Use `search_dashboards` to discover dashboards before retrieving by UID.175- When presenting Grafana data, use `generate_deeplink` to provide clickable URLs rather than describing navigation steps.176177### Querying178179- When querying Prometheus, always specify a reasonable time range to avoid overwhelming results.180- When querying Loki, prefer targeted LogQL selectors with label matchers over broad queries.181- Use datasource discovery tools (`list_datasources`, `list_prometheus_metric_names`) before writing queries.182183### Safety184185- Avoid write operations (`update_dashboard`, `create_incident`, `create_alert_rule`) unless explicitly asked by the user.186- Use `--disable-write` flag for read-only mode when write access isn't needed.187- Disable unused tool categories with `--enabled-tools` to reduce attack surface and context usage.188189### RBAC190191- **Viewer** role: sufficient for all read operations (dashboards, datasources, queries, annotations)192- **Editor** role: required for write operations (create/update dashboards, alerts, incidents)193- For fine-grained control, use custom roles with specific permissions per tool (see [mcp-grafana README](https://github.com/grafana/mcp-grafana) for the full RBAC matrix)