grafana
A Model Context Protocol (MCP) server for Grafana
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:
- 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).
- Clone or download the Grafana MCP Server repository to your host.
- Create and activate a Python virtual environment (recommended):
- uv venv .venv
- source .venv/bin/activate
- Install required Python dependencies (as specified by the repository’s pyproject.toml or requirements.txt):
- uv sync
- 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
- 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
mcp-vegalite
MCP server from isaacwasserman/mcp-vegalite-server
github-chat
A Model Context Protocol (MCP) for analyzing and querying GitHub repositories using the GitHub Chat API.
nautex
MCP server for guiding Coding Agents via end-to-end requirements to implementation plan pipeline
pagerduty
PagerDuty's official local MCP (Model Context Protocol) server which provides tools to interact with your PagerDuty account directly from your MCP-enabled client.
futu-stock
mcp server for futuniuniu stock
mcp -boilerplate
Boilerplate using one of the 'better' ways to build MCP Servers. Written using FastMCP