Get the FREE Ultimate OpenClaw Setup Guide →

grafana

A Model Context Protocol (MCP) server for Grafana

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio drdroidlab-grafana-mcp-server uvx run -m src.grafana_mcp_server.mcp_server \
  --env GRAFANA_HOST="https://your-grafana-instance.com" \
  --env GRAFANA_API_KEY="your-grafana-api-key-here" \
  --env MCP_SERVER_PORT="8000" \
  --env MCP_SERVER_DEBUG="true" \
  --env GRAFANA_SSL_VERIFY="true"

How to use

This Grafana MCP Server exposes a suite of tools to interact with Grafana data sources, dashboards, and logs through the MCP protocol. It includes capabilities to test connectivity, run PromQL queries against the Grafana Prometheus datasource, fetch Loki logs, retrieve dashboard configurations and panels, and enumerate dashboards, datasources, and folders. Clients can connect to the MCP endpoint and issue commands such as grafana_promql_query, grafana_loki_query, grafana_fetch_all_dashboards, grafana_fetch_datasources, and grafana_fetch_folders to programmatically interact with Grafana resources. The server supports template variable handling and optimization for metric data to minimize payloads, which is helpful for AI assistants and automation tools that rely on concise data streams. You can also fetch available label values and dashboard variables to drive dynamic queries and dashboards.

How to install

Prerequisites:

  • Python 3.11+ or compatible environment
  • Access to a Grafana instance with an API token (Service Account) for authentication

Installation steps:

  1. Install uv (Python virtual environment tool) and dependencies
    • If you haven’t already installed uv, install via your preferred method (e.g., pipx or pip).
  2. Clone or download the Grafana MCP Server repository to your host.
  3. Create and activate a Python virtual environment (recommended):
    • uv venv .venv
    • source .venv/bin/activate
  4. Install required Python dependencies (as specified by the repository’s pyproject.toml or requirements.txt):
    • uv sync
  5. Configure Grafana access:
    • Set GRAFANA_HOST to your Grafana URL
    • Set GRAFANA_API_KEY to your Grafana API key/token with appropriate permissions
    • Optionally set GRAFANA_SSL_VERIFY to true/false depending on SSL setup
  6. Run the MCP server using the recommended uv command:
    • uv run -m src.grafana_mcp_server.mcp_server
    • The server will listen on port 8000 by default (configurable via MCP_SERVER_PORT)

Notes:

  • If you prefer containerized deployment, you can run the provided image with docker compose or a direct docker run, passing the proper Grafana environment variables.
  • Ensure your Grafana token has the necessary permissions for the requested operations (read/observe as needed).

Additional notes

Tips and common considerations:

  • Ensure Grafana SSL verification settings match your Grafana deployment (GRAFANA_SSL_VERIFY).
  • If you encounter authentication errors, re-check the API key scope and validity.
  • The MCP tools support template variables; use grafana_fetch_dashboard_variables and grafana_fetch_label_values to drive dynamic prompts.
  • For production deployments, consider running behind HTTPS and enforcing proper firewall rules.
  • Debug mode can be enabled by setting MCP_SERVER_DEBUG=true to gain more verbose logs for troubleshooting.
  • When using Docker, the -t stdio option is recommended for MCP client compatibility.
  • If you need to adjust which dashboards or datasources are fetched, use grafana_fetch_all_dashboards, grafana_fetch_datasources, grafana_fetch_folders to enumerate resources first, then query specifics.

Related MCP Servers

Sponsor this space

Reach thousands of developers