### Install mcp-grafana with uvx Source: https://github.com/grafana/mcp-grafana/blob/main/README.md The recommended installation method using uvx. Ensure you have uv installed; uvx will handle downloading and running the server automatically. ```bash uvx mcp-grafana ``` -------------------------------- ### Install Dependencies with uv Source: https://github.com/grafana/mcp-grafana/blob/main/tests/README.md Installs project dependencies using uv. Ensure uv is installed first. ```bash uv sync --all-groups ``` -------------------------------- ### Install mcp-grafana via Go Source: https://github.com/grafana/mcp-grafana/blob/main/docs/troubleshooting.md Install the latest version of the binary and add it to the system PATH. ```bash GOBIN="$HOME/go/bin" go install github.com/grafana/mcp-grafana/cmd/mcp-grafana@latest export PATH="$HOME/go/bin:$PATH" ``` -------------------------------- ### Installation and Configuration Source: https://context7.com/grafana/mcp-grafana/llms.txt Instructions for installing and configuring the Grafana MCP Server using various methods. ```APIDOC ## Installation and Configuration ### Quick Start with uvx The simplest way to run the server using uvx (requires uv installed). ```json { "mcpServers": { "grafana": { "command": "uvx", "args": ["mcp-grafana"], "env": { "GRAFANA_URL": "http://localhost:3000", "GRAFANA_SERVICE_ACCOUNT_TOKEN": "" } } } } ``` ### Docker Configuration Run the MCP server in a Docker container with stdio transport for AI assistant integration. ```bash # Pull the official image docker pull grafana/mcp-grafana # Run in stdio mode (for Claude Desktop, Cursor, etc.) docker run --rm -i \ -e GRAFANA_URL=http://localhost:3000 \ -e GRAFANA_SERVICE_ACCOUNT_TOKEN= \ grafana/mcp-grafana -t stdio # Run in SSE mode (HTTP server) docker run --rm -p 8000:8000 \ -e GRAFANA_URL=http://localhost:3000 \ -e GRAFANA_SERVICE_ACCOUNT_TOKEN= \ grafana/mcp-grafana # Run in streamable HTTP mode with TLS docker run --rm -p 8443:8443 \ -v /path/to/certs:/certs:ro \ -e GRAFANA_URL=http://localhost:3000 \ -e GRAFANA_SERVICE_ACCOUNT_TOKEN= \ grafana/mcp-grafana \ -t streamable-http \ -addr :8443 \ --server.tls-cert-file /certs/server.crt \ --server.tls-key-file /certs/server.key ``` ### Helm Chart Deployment Deploy to Kubernetes using the official Helm chart. ```bash # Add the Grafana Helm repository helm repo add grafana https://grafana.github.io/helm-charts # Install with custom configuration helm install my-release grafana/grafana-mcp \ --set grafana.apiKey= \ --set grafana.url= ``` ``` -------------------------------- ### Enable and Start mcp-grafana Systemd Service Source: https://github.com/grafana/mcp-grafana/blob/main/docs/clients/vscode-copilot.md Enables the mcp-grafana systemd user service to start on boot and starts it immediately. This command should be run after creating the service unit file. ```bash systemctl --user enable --now mcp-grafana ``` -------------------------------- ### Install mcp-grafana via Go Source: https://github.com/grafana/mcp-grafana/blob/main/docs/clients/claude-desktop.md Use this command to install the latest version of the mcp-grafana binary into your Go bin directory. ```bash GOBIN="$HOME/go/bin" go install github.com/grafana/mcp-grafana/cmd/mcp-grafana@latest ``` -------------------------------- ### Start mcp-grafana Server (CLI) Source: https://github.com/grafana/mcp-grafana/blob/main/docs/clients/vscode-copilot.md Starts the mcp-grafana server using environment variables for Grafana URL and token. Ensure Grafana is accessible and a service account token is generated. ```bash export GRAFANA_URL="http://localhost:3000" export GRAFANA_SERVICE_ACCOUNT_TOKEN="" mcp-grafana --transport sse --address localhost:8000 ``` -------------------------------- ### Start Gemini CLI Source: https://github.com/grafana/mcp-grafana/blob/main/docs/clients/gemini-cli.md Launch the Gemini CLI interface. ```bash gemini ``` -------------------------------- ### Start local Grafana instance Source: https://github.com/grafana/mcp-grafana/blob/main/README.md Starts a local Grafana instance on port 3000 using Docker Compose for integration testing. ```bash docker-compose up -d ``` -------------------------------- ### Start MCP Server Source: https://github.com/grafana/mcp-grafana/blob/main/tests/README.md Launches the Grafana MCP server in SSE mode with specified tools enabled. Ensure Docker is running and containers are started. ```bash go run ./cmd/mcp-grafana -t sse --enabled-tools admin,search,dashboard,loki,navigation,rendering,proxied ``` -------------------------------- ### Start Remote mcp-grafana Server Source: https://github.com/grafana/mcp-grafana/blob/main/docs/clients/zed.md Command to start the mcp-grafana server for remote connections using SSE transport. ```bash mcp-grafana --transport sse --address localhost:8000 ``` -------------------------------- ### Compare TOML and JSON syntax Source: https://github.com/grafana/mcp-grafana/blob/main/docs/clients/codex.md Examples illustrating the correct TOML syntax for environment variables compared to invalid JSON-style syntax. ```toml # Wrong - JSON-style env = {"GRAFANA_URL": "http://localhost:3000"} # Correct - TOML-style env = { GRAFANA_URL = "http://localhost:3000" } ``` -------------------------------- ### Start mcp-grafana Transport Servers Source: https://github.com/grafana/mcp-grafana/blob/main/docs/troubleshooting.md Launch the server using SSE or streamable-http transport modes. ```bash mcp-grafana -t sse --address localhost:8000 ``` ```bash mcp-grafana -t streamable-http --address localhost:8000 ``` -------------------------------- ### Install mcp-grafana with Helm Source: https://github.com/grafana/mcp-grafana/blob/main/README.md Deploy mcp-grafana to Kubernetes using the Grafana Helm chart. Add the Grafana Helm repository and install the chart, providing Grafana API key and URL as parameters. ```bash helm repo add grafana https://grafana.github.io/helm-charts helm install --set grafana.apiKey= --set grafana.url= my-release grafana/grafana-mcp ``` -------------------------------- ### Run mcp-grafana Locally Source: https://github.com/grafana/mcp-grafana/blob/main/DEVELOPING.md Start the necessary test services and then run the mcp-grafana server in different transport modes. ```bash make run-test-services ``` ```bash make run # stdio mode ``` ```bash make run-sse # SSE mode (with debug logging + metrics) ``` ```bash make run-streamable-http # Streamable HTTP mode (with debug logging + metrics) ``` -------------------------------- ### Start mcp-grafana Server (Docker) Source: https://github.com/grafana/mcp-grafana/blob/main/docs/clients/vscode-copilot.md Launches the mcp-grafana server using Docker, mapping ports and setting Grafana connection details via environment variables. Use 'host.docker.internal' for Grafana if it's running on the host machine. ```bash docker run --rm -p 8000:8000 \ -e GRAFANA_URL=http://host.docker.internal:3000 \ -e GRAFANA_SERVICE_ACCOUNT_TOKEN= \ mcp/grafana --transport sse --address :8000 ``` -------------------------------- ### Docker Example with Metrics and Tracing Source: https://github.com/grafana/mcp-grafana/blob/main/README.md Run the MCP Grafana server in a Docker container with metrics and tracing enabled. Ensure to replace placeholders for Grafana token and Tempo endpoint. ```bash docker run --rm -p 8000:8000 \ -e GRAFANA_URL=http://localhost:3000 \ -e GRAFANA_SERVICE_ACCOUNT_TOKEN= \ -e OTEL_EXPORTER_OTLP_ENDPOINT=http://tempo:4317 \ -e OTEL_EXPORTER_OTLP_INSECURE=true \ grafana/mcp-grafana \ -t streamable-http --metrics ``` -------------------------------- ### Start mcp-grafana Server in Debug Mode Source: https://github.com/grafana/mcp-grafana/blob/main/docs/clients/vscode-copilot.md Starts the mcp-grafana server with debug logging enabled. This is useful for troubleshooting connection or configuration issues. ```bash mcp-grafana --transport sse --address localhost:8000 -debug ``` -------------------------------- ### Add Grafana MCP Server (One-Command) Source: https://github.com/grafana/mcp-grafana/blob/main/docs/clients/claude-code.md Use this command for a quick setup of the Grafana MCP server with essential environment variables. ```bash claude mcp add-json "grafana" '{"command":"mcp-grafana","args":[],"env":{"GRAFANA_URL":"http://localhost:3000","GRAFANA_SERVICE_ACCOUNT_TOKEN":""}}' ``` -------------------------------- ### Deploy Grafana MCP with Helm Source: https://context7.com/grafana/mcp-grafana/llms.txt Commands to add the Helm repository and install the Grafana MCP chart. ```bash # Add the Grafana Helm repository helm repo add grafana https://grafana.github.io/helm-charts # Install with custom configuration helm install my-release grafana/grafana-mcp \ --set grafana.apiKey= \ --set grafana.url= ``` -------------------------------- ### Prometheus Histogram Query Response Example Source: https://context7.com/grafana/mcp-grafana/llms.txt Example response structure for histogram percentile queries, showing the calculated results. ```json { "result": { "resultType": "matrix", "result": [ {"metric": {}, "values": [[1704067200, "0.245"], [1704067260, "0.251"]] } ], "query": "histogram_quantile(0.95, sum(rate(http_request_duration_seconds_bucket{job=\"api-server\"}[5m])) by (le))", "hints": [] } ``` -------------------------------- ### Prometheus Query Response Example Source: https://context7.com/grafana/mcp-grafana/llms.txt This is an example of a response structure for Prometheus queries, indicating the result type and the data. ```json { "data": { "resultType": "matrix", "result": [ { "metric": {"job": "api-server", "instance": "localhost:8080"}, "values": [[1704067200, "125.5"], [1704067260, "130.2"]] } ] }, "hints": null } ``` -------------------------------- ### Run Pytest Suite Source: https://github.com/grafana/mcp-grafana/blob/main/tests/README.md Executes the end-to-end tests using pytest. Dependencies must be installed via uv. ```bash uv run pytest ``` -------------------------------- ### Loki Log Patterns Response Example Source: https://context7.com/grafana/mcp-grafana/llms.txt Example response structure for Loki log patterns query, showing detected patterns and their total counts. ```json [ {"pattern": "<_> <_> <_> <_> \"GET /api/<_> HTTP/1.1\" 200 <_>", "totalCount": 15420}, {"pattern": "<_> <_> <_> <_> \"POST /api/<_> HTTP/1.1\" 500 <_>", "totalCount": 234}, {"pattern": "ERROR: Connection refused to <_>:<_>", "totalCount": 45} ] ``` -------------------------------- ### Go Struct Tag Escaping Examples Source: https://github.com/grafana/mcp-grafana/blob/main/internal/linter/jsonschema/README.md Demonstrates the difference between problematic unescaped commas and the correct escaped syntax in Go struct tags. ```go // Problematic (description will be truncated at the first comma): type Example struct { Field string `jsonschema:"description=This is a description, but it will be truncated here"` } // Correct (commas properly escaped): type Example struct { Field string `jsonschema:"description=This is a description\, and it will be fully included"` } ``` -------------------------------- ### Programmatic TLS Configuration in Go Source: https://github.com/grafana/mcp-grafana/blob/main/README.md Configure TLS settings programmatically in Go using the mcpgrafana library. This example shows how to create TLSConfig and GrafanaConfig structs to pass to context functions. ```go // Using struct literals tlsConfig := &mcpgrafana.TLSConfig{ CertFile: "/path/to/client.crt", KeyFile: "/path/to/client.key", CAFile: "/path/to/ca.crt", } grafanaConfig := mcpgrafana.GrafanaConfig{ Debug: true, TLSConfig: tlsConfig, } contextFunc := mcpgrafana.ComposedStdioContextFunc(grafanaConfig) // Or inline grafanaConfig := mcpgrafana.GrafanaConfig{ Debug: true, TLSConfig: &mcpgrafana.TLSConfig{ CertFile: "/path/to/client.crt", KeyFile: "/path/to/client.key", CAFile: "/path/to/ca.crt", }, } contextFunc := mcpgrafana.ComposedStdioContextFunc(grafanaConfig) ``` -------------------------------- ### Add Grafana MCP Server (Docker Setup) Source: https://github.com/grafana/mcp-grafana/blob/main/docs/clients/claude-code.md Configure the Grafana MCP server to run within a Docker container, specifying necessary environment variables. ```bash claude mcp add-json "grafana" '{ "command": "docker", "args": ["run", "--rm", "-i", "-e", "GRAFANA_URL", "-e", "GRAFANA_SERVICE_ACCOUNT_TOKEN", "mcp/grafana"], "env": { "GRAFANA_URL": "http://host.docker.internal:3000", "GRAFANA_SERVICE_ACCOUNT_TOKEN": "" } }' ``` -------------------------------- ### Get Datasource Details Source: https://context7.com/grafana/mcp-grafana/llms.txt Request and response format for retrieving specific datasource information. ```json // Request by UID { "tool": "get_datasource", "arguments": { "uid": "prometheus-uid" } } // Request by name { "tool": "get_datasource", "arguments": { "name": "Prometheus" } } // Response { "id": 1, "uid": "prometheus-uid", "name": "Prometheus", "type": "prometheus", "url": "http://prometheus:9090", "access": "proxy", "isDefault": true, "jsonData": { "httpMethod": "POST", "timeInterval": "15s" } } ``` -------------------------------- ### Get Dashboard Summary Source: https://context7.com/grafana/mcp-grafana/llms.txt Retrieve a concise overview of a dashboard, useful for minimizing context window usage. Requires dashboard UID. ```json // Request { "tool": "get_dashboard_summary", "arguments": { "uid": "k8s-overview" } } // Response { "uid": "k8s-overview", "title": "Kubernetes Overview", "description": "Main Kubernetes cluster monitoring dashboard", "tags": ["kubernetes", "infrastructure"], "panelCount": 12, "panels": [ {"id": 1, "title": "CPU Usage", "type": "timeseries", "queryCount": 2}, {"id": 2, "title": "Memory Usage", "type": "timeseries", "queryCount": 2} ], "variables": [ {"name": "cluster", "type": "query", "label": "Cluster"}, {"name": "namespace", "type": "query", "label": "Namespace"} ], "timeRange": {"from": "now-1h", "to": "now"}, "refresh": "30s" } ``` -------------------------------- ### Verify Grafana MCP Configuration Source: https://github.com/grafana/mcp-grafana/blob/main/docs/clients/claude-code.md Steps to verify the Grafana MCP server configuration by starting a Claude Code session and querying Grafana data. ```bash claude ``` -------------------------------- ### Start mcp-grafana Server in Read-only Mode Source: https://github.com/grafana/mcp-grafana/blob/main/docs/clients/vscode-copilot.md Starts the mcp-grafana server with write operations disabled. This mode is useful for environments where only data retrieval is needed. ```bash mcp-grafana --transport sse --address localhost:8000 --disable-write ``` -------------------------------- ### Run all integration tests Source: https://github.com/grafana/mcp-grafana/blob/main/README.md Executes the full suite of integration tests. ```bash make test-all ``` -------------------------------- ### Loki Statistics Response Example Source: https://context7.com/grafana/mcp-grafana/llms.txt Example response structure for Loki statistics query, providing counts for streams, chunks, entries, and total bytes. ```json { "streams": 5, "chunks": 50, "entries": 10000, "bytes": 512000 } ``` -------------------------------- ### Get Specific Grafana Alert Rule Source: https://context7.com/grafana/mcp-grafana/llms.txt Retrieve a single alert rule by its unique identifier (UID) using the `alerting_manage_rules` tool with the `get` action. ```json { "tool": "alerting_manage_rules", "arguments": { "action": "get", "ruleUid": "alert-rule-uid" } } ``` -------------------------------- ### Loki Log Query Response Example Source: https://context7.com/grafana/mcp-grafana/llms.txt Example response structure for a Loki log query, including timestamp, line content, labels, and parsed structured metadata. ```json { "data": [ { "timestamp": "1704067200000000000", "line": "2024-01-01T00:00:00Z ERROR Connection refused", "labels": {"app": "nginx", "pod": "nginx-abc123"}, "structuredMetadata": {"trace_id": "abc123"}, "parsed": {"level": "ERROR", "message": "Connection refused"} } ], "metadata": { "linesReturned": 50, "maxLinesAllowed": 100, "resultsTruncated": false, "totalLinesScanned": 1500 } } ``` -------------------------------- ### Build mcp-grafana Source: https://github.com/grafana/mcp-grafana/blob/main/DEVELOPING.md Use these commands to build the mcp-grafana binary or its Docker image. ```bash make build # builds dist/mcp-grafana ``` ```bash make build-image # builds Docker image ``` -------------------------------- ### Enable Debug Mode Source: https://github.com/grafana/mcp-grafana/blob/main/docs/troubleshooting.md Run the server with verbose logging enabled. ```json { "args": ["-debug"] } ``` ```bash GRAFANA_URL="http://localhost:3000" \ GRAFANA_SERVICE_ACCOUNT_TOKEN="" \ mcp-grafana -debug ``` -------------------------------- ### GET /api/prometheus/labels Source: https://context7.com/grafana/mcp-grafana/llms.txt Retrieves values for a specific Prometheus label with optional filtering. ```APIDOC ## GET /api/prometheus/labels ### Description Get values for a specific label with optional filtering. ### Method GET ### Endpoint /api/prometheus/labels ### Query Parameters - **datasourceUid** (string) - Required - The UID of the Prometheus datasource. - **labelName** (string) - Required - The name of the label to retrieve values for. - **matches** (array[object]) - Optional - Filters to apply to label matching. - **filters** (array[object]) - List of filter conditions. - **name** (string) - The name of the metric or label to filter on. - **value** (string) - The value to match. - **type** (string) - The comparison type (e.g., '='). - **limit** (integer) - Optional - The maximum number of label values to return. ### Response #### Success Response (200) - Returns an array of label values matching the criteria. ### Request Example ```json { "tool": "list_prometheus_label_values", "arguments": { "datasourceUid": "prometheus-uid", "labelName": "job", "matches": [{"filters": [{"name": "__name__", "value": "up", "type": "="}]}], "limit": 100 } } ``` ### Response Example ```json ["prometheus", "node-exporter", "grafana", "alertmanager"] ``` ``` -------------------------------- ### Run project linting Source: https://github.com/grafana/mcp-grafana/blob/main/README.md Executes the project linting suite, including custom checks for JSON schema struct tags. ```bash make lint ``` ```bash make lint-jsonschema ``` -------------------------------- ### GET /api/prometheus/metrics Source: https://context7.com/grafana/mcp-grafana/llms.txt Discovers available Prometheus metric names with filtering and pagination. ```APIDOC ## GET /api/prometheus/metrics ### Description Discover available Prometheus metrics with regex filtering and pagination. ### Method GET ### Endpoint /api/prometheus/metrics ### Query Parameters - **datasourceUid** (string) - Required - The UID of the Prometheus datasource. - **regex** (string) - Optional - A regular expression to filter metric names. - **limit** (integer) - Optional - The maximum number of metrics to return. - **page** (integer) - Optional - The page number for pagination. ### Response #### Success Response (200) - Returns an array of metric names matching the criteria. ### Request Example ```json { "tool": "list_prometheus_metric_names", "arguments": { "datasourceUid": "prometheus-uid", "regex": "node_.*", "limit": 10, "page": 1 } } ``` ### Response Example ```json ["node_cpu_seconds_total", "node_memory_MemTotal_bytes", "node_disk_read_bytes_total", "node_network_receive_bytes_total"] ``` ``` -------------------------------- ### GET /api/dashboards/panel-queries Source: https://context7.com/grafana/mcp-grafana/llms.txt Retrieves query and datasource information for panels within a dashboard. ```APIDOC ## GET /api/dashboards/panel-queries ### Description Extract panel queries with datasource information from a dashboard. ### Method GET ### Endpoint /api/dashboards/panel-queries ### Query Parameters - **uid** (string) - Required - The unique identifier of the dashboard. - **panelId** (integer) - Optional - The ID of a specific panel. - **variables** (object) - Optional - Key-value pairs for variable substitution in queries. ### Response #### Success Response (200) - Returns an array of objects, each representing a panel's query details. - **title** (string) - The title of the panel. - **query** (string) - The original query string. - **processedQuery** (string) - The query after variable substitution. - **datasource** (object) - Information about the datasource. - **uid** (string) - The unique identifier of the datasource. - **type** (string) - The type of the datasource. - **refId** (string) - The reference ID of the query. - **requiredVariables** (array[object]) - List of variables required for the query. ### Request Example ```json // Request - all panels { "tool": "get_dashboard_panel_queries", "arguments": { "uid": "k8s-overview" } } // Request - specific panel with variable substitution { "tool": "get_dashboard_panel_queries", "arguments": { "uid": "k8s-overview", "panelId": 1, "variables": {"cluster": "production", "namespace": "default"} } } ``` ### Response Example ```json [ { "title": "CPU Usage", "query": "rate(container_cpu_usage_seconds_total{cluster=\"$cluster\"}[5m])", "processedQuery": "rate(container_cpu_usage_seconds_total{cluster=\"production\"}[5m])", "datasource": {"uid": "prometheus-uid", "type": "prometheus"}, "refId": "A", "requiredVariables": [{"name": "cluster", "type": "query"}] } ] ``` ``` -------------------------------- ### Configure API Keys Source: https://github.com/grafana/mcp-grafana/blob/main/tests/README.md Create a .env file to store sensitive API keys for services like OpenAI and Anthropic. ```env OPENAI_API_KEY=sk-... ANTHROPIC_API_KEY=sk-ant-... ``` -------------------------------- ### Configure MCP Client Command Source: https://github.com/grafana/mcp-grafana/blob/main/docs/troubleshooting.md Specify the full path to the mcp-grafana binary in the client configuration. ```json { "command": "/full/path/to/mcp-grafana" } ``` -------------------------------- ### GET /api/dashboards/property Source: https://context7.com/grafana/mcp-grafana/llms.txt Extracts specific parts of a dashboard using JSONPath expressions. ```APIDOC ## GET /api/dashboards/property ### Description Extract specific parts of a dashboard using JSONPath expressions. ### Method GET ### Endpoint /api/dashboards/property ### Query Parameters - **uid** (string) - Required - The unique identifier of the dashboard. - **jsonPath** (string) - Required - The JSONPath expression to extract data. ### Response #### Success Response (200) - Returns an array of values matching the JSONPath expression. ### Request Example ```json // Get all panel titles { "tool": "get_dashboard_property", "arguments": { "uid": "k8s-overview", "jsonPath": "$.panels[*].title" } } // Get first panel's queries { "tool": "get_dashboard_property", "arguments": { "uid": "k8s-overview", "jsonPath": "$.panels[0].targets[*].expr" } } // Get all variables { "tool": "get_dashboard_property", "arguments": { "uid": "k8s-overview", "jsonPath": "$.templating.list" } } ``` ### Response Example ```json // Response for getting all panel titles ["CPU Usage", "Memory Usage", "Network I/O", "Disk Usage"] // Response for getting first panel's queries ["rate(container_cpu_usage_seconds_total[5m])", "container_memory_usage_bytes"] // Response for getting all variables [ {"name": "cluster", "type": "query", "label": "Cluster"}, {"name": "namespace", "type": "query", "label": "Namespace"} ] ``` ``` -------------------------------- ### GET /api/dashboards/summary Source: https://context7.com/grafana/mcp-grafana/llms.txt Retrieves a compact overview of a dashboard, minimizing data transfer. ```APIDOC ## GET /api/dashboards/summary ### Description Get a compact dashboard overview without the full JSON to minimize context window usage. ### Method GET ### Endpoint /api/dashboards/summary ### Query Parameters - **uid** (string) - Required - The unique identifier of the dashboard. ### Response #### Success Response (200) - **uid** (string) - The unique identifier of the dashboard. - **title** (string) - The title of the dashboard. - **description** (string) - The description of the dashboard. - **tags** (array[string]) - Tags associated with the dashboard. - **panelCount** (integer) - The number of panels in the dashboard. - **panels** (array[object]) - A list of panels in the dashboard, each with id, title, type, and queryCount. - **variables** (array[object]) - A list of templating variables used in the dashboard. - **timeRange** (object) - The default time range for the dashboard. - **refresh** (string) - The default refresh interval for the dashboard. #### Response Example ```json { "uid": "k8s-overview", "title": "Kubernetes Overview", "description": "Main Kubernetes cluster monitoring dashboard", "tags": ["kubernetes", "infrastructure"], "panelCount": 12, "panels": [ {"id": 1, "title": "CPU Usage", "type": "timeseries", "queryCount": 2}, {"id": 2, "title": "Memory Usage", "type": "timeseries", "queryCount": 2} ], "variables": [ {"name": "cluster", "type": "query", "label": "Cluster"}, {"name": "namespace", "type": "query", "label": "Namespace"} ], "timeRange": {"from": "now-1h", "to": "now"}, "refresh": "30s" } ``` ``` -------------------------------- ### Get Dashboard by UID Source: https://context7.com/grafana/mcp-grafana/llms.txt Request and response format for retrieving full dashboard JSON. ```json // Request { "tool": "get_dashboard_by_uid", "arguments": { "uid": "k8s-overview" } } // Response { "dashboard": { "uid": "k8s-overview", "title": "Kubernetes Overview", "panels": [...], "templating": {"list": [...]}, "time": {"from": "now-1h", "to": "now"} }, "meta": { "folderUid": "infra-folder", "canEdit": true, "canSave": true } } ``` -------------------------------- ### Check Version Information Source: https://github.com/grafana/mcp-grafana/blob/main/docs/troubleshooting.md Verify the versions of both the mcp-grafana binary and the Grafana server. ```bash # mcp-grafana version mcp-grafana --version # Grafana version curl $GRAFANA_URL/api/health | jq .version ``` -------------------------------- ### Verify Codex configuration Source: https://github.com/grafana/mcp-grafana/blob/main/docs/clients/codex.md Commands to list, inspect, and test the configured MCP servers. ```bash # List configured servers codex mcp list # Show specific server config codex mcp get grafana # Start Codex and test codex ``` -------------------------------- ### Run mcp-grafana in STDIO Mode via Docker Source: https://github.com/grafana/mcp-grafana/blob/main/README.md Deploy mcp-grafana using Docker for STDIO mode, which is typical for direct integration with AI assistants. Override the default entrypoint with '-t stdio' and use '-i' to keep stdin open. Configure GRAFANA_URL and GRAFANA_SERVICE_ACCOUNT_TOKEN as environment variables. ```bash docker pull grafana/mcp-grafana # For local Grafana: docker run --rm -i -e GRAFANA_URL=http://localhost:3000 -e GRAFANA_SERVICE_ACCOUNT_TOKEN= grafana/mcp-grafana -t stdio # For Grafana Cloud: docker run --rm -i -e GRAFANA_URL=https://myinstance.grafana.net -e GRAFANA_SERVICE_ACCOUNT_TOKEN= grafana/mcp-grafana -t stdio ``` -------------------------------- ### Get Full Dashboard Image Source: https://context7.com/grafana/mcp-grafana/llms.txt Render an entire Grafana dashboard as a PNG image, specifying dimensions and theme. ```json { "tool": "get_panel_image", "arguments": { "dashboardUid": "k8s-overview", "width": 1920, "height": 1080, "theme": "light" } } ``` -------------------------------- ### Run JSONSchema Linter Source: https://github.com/grafana/mcp-grafana/blob/main/internal/linter/jsonschema/README.md Commands to execute the linter via Makefile or direct Go execution. ```shell make lint-jsonschema ``` ```shell go run ./cmd/linters/jsonschema --path . ``` -------------------------------- ### Configure mcp-grafana in Claude Desktop Source: https://github.com/grafana/mcp-grafana/blob/main/docs/clients/claude-desktop.md Standard configuration for the Claude Desktop JSON file. Use the full path version if you encounter ENOENT errors. ```json { "mcpServers": { "grafana": { "command": "mcp-grafana", "args": [], "env": { "GRAFANA_URL": "http://localhost:3000", "GRAFANA_SERVICE_ACCOUNT_TOKEN": "" } } } } ``` ```json { "mcpServers": { "grafana": { "command": "/Users/yourname/go/bin/mcp-grafana", "args": [], "env": { "GRAFANA_URL": "http://localhost:3000", "GRAFANA_SERVICE_ACCOUNT_TOKEN": "" } } } } ``` -------------------------------- ### Get Current On-Call Users Source: https://context7.com/grafana/mcp-grafana/llms.txt Fetch the users currently on-call for a specific schedule using the `get_current_oncall_users` tool. Requires the `scheduleId`. ```json { "tool": "get_current_oncall_users", "arguments": { "scheduleId": "schedule-abc" } } ``` -------------------------------- ### Get Grafana Notification Policy Tree Source: https://context7.com/grafana/mcp-grafana/llms.txt Retrieve the entire notification policy tree using the `alerting_manage_routing` tool with the `get_policy_tree` action. ```json { "tool": "alerting_manage_routing", "arguments": { "action": "get_policy_tree" } } ``` -------------------------------- ### Add Grafana MCP Server (Full JSON Config) Source: https://github.com/grafana/mcp-grafana/blob/main/docs/clients/claude-code.md Provides a detailed JSON configuration for the Grafana MCP server, including command, arguments, and environment variables. ```bash claude mcp add-json "grafana" '{ "command": "mcp-grafana", "args": [], "env": { "GRAFANA_URL": "http://localhost:3000", "GRAFANA_SERVICE_ACCOUNT_TOKEN": "" } }' ``` -------------------------------- ### Get Dashboard Panel Queries Source: https://context7.com/grafana/mcp-grafana/llms.txt Extract queries from dashboard panels, optionally with variable substitution. Useful for understanding panel configurations. ```json // Request - all panels { "tool": "get_dashboard_panel_queries", "arguments": { "uid": "k8s-overview" } } ``` ```json // Request - specific panel with variable substitution { "tool": "get_dashboard_panel_queries", "arguments": { "uid": "k8s-overview", "panelId": 1, "variables": {"cluster": "production", "namespace": "default"} } } ``` ```json // Response [ { "title": "CPU Usage", "query": "rate(container_cpu_usage_seconds_total{cluster=\"$cluster\"}[5m])", "processedQuery": "rate(container_cpu_usage_seconds_total{cluster=\"production\"}[5m])", "datasource": {"uid": "prometheus-uid", "type": "prometheus"}, "refId": "A", "requiredVariables": [{"name": "cluster", "type": "query"}] } ] ``` -------------------------------- ### Manage MCP servers via CLI Source: https://github.com/grafana/mcp-grafana/blob/main/docs/clients/gemini-cli.md Use Gemini CLI commands to list or remove configured MCP servers. ```bash # List configured servers gemini mcp list # Remove a server gemini mcp remove grafana ``` -------------------------------- ### Configure mcp-grafana in settings.json Source: https://github.com/grafana/mcp-grafana/blob/main/docs/clients/gemini-cli.md Define the MCP server configuration in the Gemini CLI settings file. ```json { "mcpServers": { "grafana": { "command": "mcp-grafana", "args": [], "env": { "GRAFANA_URL": "http://localhost:3000", "GRAFANA_SERVICE_ACCOUNT_TOKEN": "" } } } } ``` -------------------------------- ### Get Dashboard Property with JSONPath Source: https://context7.com/grafana/mcp-grafana/llms.txt Extract specific dashboard properties using JSONPath expressions. Useful for targeted data retrieval. ```json // Get all panel titles { "tool": "get_dashboard_property", "arguments": { "uid": "k8s-overview", "jsonPath": "$.panels[*].title" } } // Response: ["CPU Usage", "Memory Usage", "Network I/O", "Disk Usage"] ``` ```json // Get first panel's queries { "tool": "get_dashboard_property", "arguments": { "uid": "k8s-overview", "jsonPath": "$.panels[0].targets[*].expr" } } // Response: ["rate(container_cpu_usage_seconds_total[5m])", "container_memory_usage_bytes"] ``` ```json // Get all variables { "tool": "get_dashboard_property", "arguments": { "uid": "k8s-overview", "jsonPath": "$.templating.list" } } ``` -------------------------------- ### Execute PromQL Instant Query Source: https://context7.com/grafana/mcp-grafana/llms.txt Use this tool to execute an instant PromQL query against a Prometheus datasource. Ensure the datasourceUid is correctly set. ```json { "tool": "query_prometheus", "arguments": { "datasourceUid": "prometheus-uid", "expr": "up", "endTime": "now", "queryType": "instant" } } ``` -------------------------------- ### Configure SSE transport Source: https://github.com/grafana/mcp-grafana/blob/main/docs/clients/gemini-cli.md Set up an HTTP-based connection using SSE transport. ```bash export GRAFANA_URL="http://localhost:3000" export GRAFANA_SERVICE_ACCOUNT_TOKEN="" mcp-grafana --transport sse --address localhost:8000 ``` ```json { "mcpServers": { "grafana": { "httpUrl": "http://localhost:8000/sse" } } } ``` -------------------------------- ### Configure OpenTelemetry Tracing Source: https://github.com/grafana/mcp-grafana/blob/main/README.md Configure distributed tracing for the MCP server using standard OTEL environment variables. Traces are exported via OTLP/gRPC when the endpoint is set. ```bash OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317 \ OTEL_EXPORTER_OTLP_INSECURE=true \ ./mcp-grafana -t streamable-http ``` ```bash OTEL_EXPORTER_OTLP_ENDPOINT=https://tempo-us-central1.grafana.net:443 \ OTEL_EXPORTER_OTLP_HEADERS="Authorization=Basic ..." \ ./mcp-grafana -t streamable-http ``` -------------------------------- ### Verify mcp-grafana Binary Source: https://github.com/grafana/mcp-grafana/blob/main/docs/clients/windsurf.md Verify the mcp-grafana binary is installed and accessible in your system's PATH. This command helps in troubleshooting connection issues. ```bash which mcp-grafana ``` -------------------------------- ### Get Panel Image Source: https://context7.com/grafana/mcp-grafana/llms.txt Render a specific dashboard panel as a PNG image, with options for dimensions, time range, variables, theme, and scaling. ```json { "tool": "get_panel_image", "arguments": { "dashboardUid": "k8s-overview", "panelId": 1, "width": 1200, "height": 600, "timeRange": {"from": "now-6h", "to": "now"}, "variables": {"var-cluster": "production"}, "theme": "dark", "scale": 2 } } ``` -------------------------------- ### Run MCP Server Locally (STDIO Mode) Source: https://github.com/grafana/mcp-grafana/blob/main/README.md Use this command to run the MCP server locally in STDIO mode, which is the default for local development. ```bash make run ``` -------------------------------- ### Run Custom Docker Image (STDIO Mode) Source: https://github.com/grafana/mcp-grafana/blob/main/README.md Run a custom built Docker image of the MCP Grafana server in STDIO mode by overriding the default transport setting. ```bash docker run -it --rm mcp-grafana:latest -t stdio ``` -------------------------------- ### Configure mcp-grafana with Docker Source: https://github.com/grafana/mcp-grafana/blob/main/docs/clients/gemini-cli.md Run the mcp-grafana server inside a Docker container. ```json { "mcpServers": { "grafana": { "command": "docker", "args": [ "run", "--rm", "-i", "-e", "GRAFANA_URL", "-e", "GRAFANA_SERVICE_ACCOUNT_TOKEN", "mcp/grafana" ], "env": { "GRAFANA_URL": "http://host.docker.internal:3000", "GRAFANA_SERVICE_ACCOUNT_TOKEN": "" } } } } ``` -------------------------------- ### Configure MCP Grafana Binary Source: https://github.com/grafana/mcp-grafana/blob/main/README.md Use this JSON configuration when running the mcp-grafana binary directly. Ensure GRAFANA_URL and GRAFANA_SERVICE_ACCOUNT_TOKEN are set. ```json { "mcpServers": { "grafana": { "command": "mcp-grafana", "args": [], "env": { "GRAFANA_URL": "http://localhost:3000", // Or "https://myinstance.grafana.net" for Grafana Cloud "GRAFANA_SERVICE_ACCOUNT_TOKEN": "", // If using username/password authentication "GRAFANA_USERNAME": "", "GRAFANA_PASSWORD": "", // Optional: specify organization ID for multi-org support "GRAFANA_ORG_ID": "1" } } } } ``` -------------------------------- ### List Grafana Incidents Source: https://context7.com/grafana/mcp-grafana/llms.txt Fetch a list of Grafana incidents using the `list_incidents` tool. You can filter by status and limit the number of results. Set `drill` to `false` to get previews. ```json { "tool": "list_incidents", "arguments": { "limit": 10, "status": "active", "drill": false } } ``` -------------------------------- ### Draft Release Branch and PR Source: https://github.com/grafana/mcp-grafana/blob/main/DEVELOPING.md Use this command to automate the creation of a release branch and PR, including CHANGELOG updates. Alternatively, follow the manual steps. ```bash /draft-release ``` ```bash # Determine the new version from the latest tag git tag --sort=-version:refname | head -1 # e.g. v0.10.0 → next minor is v0.11.0 git checkout main && git pull git checkout -b release/v0.11.0 # Update CHANGELOG.md with the new version's entries # (see existing entries for format) git add CHANGELOG.md git commit -m "docs: add CHANGELOG.md for v0.11.0 release" git push -u origin release/v0.11.0 gh pr create --title "Release v0.11.0" ``` -------------------------------- ### Enable Auto-Allow Tool Actions in Zed Settings Source: https://github.com/grafana/mcp-grafana/blob/main/docs/clients/zed.md This setting bypasses the need for manual confirmation for all MCP tool actions. Use with caution as it grants broad permissions. ```json { "agent": { "always_allow_tool_actions": true } } ``` -------------------------------- ### Run unit tests Source: https://github.com/grafana/mcp-grafana/blob/main/README.md Executes unit tests that do not require external dependencies. ```bash make test-unit ``` ```bash make test ```