Grafana MCP Server
Provides tools for executing PromQL and Loki queries, retrieving dashboard configurations, fetching panel data, accessing label values, retrieving dashboard variables, listing all dashboards, accessing datasource configurations, and fetching folder metadata from a Grafana instance.
Enables executing PromQL queries against Prometheus datasources configured in Grafana, optimizing time series responses to reduce token size.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Grafana MCP Server show me the CPU usage for the last hour from the production dashboard"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Grafana MCP Server
Available Tools
The following tools are available via the MCP server:
test_connection: Verify connectivity to your Grafana instance and configuration.
grafana_promql_query: Execute PromQL queries against Grafana's Prometheus datasource. Fetches metrics data using PromQL expressions, optimizes time series responses to reduce token size.
grafana_loki_query: Query Grafana Loki for log data. Fetches logs for a specified duration (e.g., '5m', '1h', '2d'), converts relative time to absolute timestamps.
grafana_get_dashboard_config: Retrieves dashboard configuration details from the database. Queries the connectors_connectormetadatamodelstore table for dashboard metadata.
grafana_query_dashboard_panels: Execute queries for specific dashboard panels. Can query up to 4 panels at once, supports template variables, optimizes metrics data.
grafana_fetch_label_values: Fetch label values for dashboard variables from Prometheus datasource. Retrieves available values for specific labels (e.g., 'instance', 'job'). Supports optional metric filtering.
grafana_fetch_dashboard_variables: Fetch all variables and their values from a Grafana dashboard. Retrieves dashboard template variables and their current values.
grafana_fetch_all_dashboards: Fetch all dashboards from Grafana with basic information like title, UID, folder, tags, etc.
grafana_fetch_datasources: Fetch all datasources from Grafana with their configuration details.
grafana_fetch_folders: Fetch all folders from Grafana with their metadata and permissions.
Related MCP server: Metabase MCP Plus
š Usage & Requirements
1. Get Your Grafana API Endpoint & Service Account Token
Ensure you have a running Grafana instance (self-hosted or cloud).
Generate a Service Account Token from your Grafana UI:
Create Service Account: In your Grafana dashboard, navigate to Admin >> Users & Access >> Service Accounts >> Create a Service Account with Viewer permissions
Generate Service Account Key: Within Service Account, create a new Service Account token.
Copy the service account token (starts with
glsa_)
2. Installation & Running Options
2A. Install & Run with uv (Recommended for Local Development)
2A.1. Install dependencies with uv
uv venv .venv
source .venv/bin/activate
uv sync2A.2. Run the server with uv
uv run -m src.grafana_mcp_server.mcp_serverYou can also use
uvto run any other entrypoint scripts as needed.Make sure your
config.yamlis in the same directory asmcp_server.pyor set the required environment variables (see Configuration section).
2B. Run with Docker Compose (Recommended for Production/Containerized Environments)
Edit
grafana-mcp-server/src/grafana_mcp_server/config.yamlwith your Grafana details (host, API key).Start the server:
docker compose up -dThe server will run in HTTP (SSE) mode on port 8000 by default.
You can override configuration with environment variables (see below).
3. Configuration
The server loads configuration in the following order of precedence:
Environment Variables (recommended for Docker/CI):
GRAFANA_HOST: Grafana instance URL (e.g.https://your-grafana-instance.com)GRAFANA_API_KEY: Grafana Service Account Token (required)GRAFANA_SSL_VERIFY:trueorfalse(default:true)MCP_SERVER_PORT: Port to run the server on (default:8000)MCP_SERVER_DEBUG:trueorfalse(default:true)
YAML file fallback (
config.yaml):grafana: host: "https://your-grafana-instance.com" api_key: "your-grafana-api-key-here" ssl_verify: "true" server: port: 8000 debug: true
4. Integration with AI Assistants (e.g., Claude Desktop, Cursor)
You can integrate this MCP server with any tool that supports the MCP protocol. Here are the main options:
4A. Using Docker (with environment variables)
{
"mcpServers": {
"grafana": {
"command": "docker",
"args": [
"run",
"--rm",
"-i",
"-e",
"GRAFANA_HOST",
"-e",
"GRAFANA_API_KEY",
"-e",
"GRAFANA_SSL_VERIFY",
"drdroidlab/grafana-mcp-server",
"-t",
"stdio"
],
"env": {
"GRAFANA_HOST": "https://your-grafana-instance.com",
"GRAFANA_API_KEY": "your-grafana-api-key-here",
"GRAFANA_SSL_VERIFY": "true"
}
}
}
}The
-t stdioargument is supported for compatibility with Docker MCP clients (forces stdio handshake mode).Adjust the volume path or environment variables as needed for your deployment.
4B. Connecting to an Already Running MCP Server (HTTP/SSE)
If you have an MCP server already running (e.g., on a remote host, cloud VM, or Kubernetes), you can connect your AI assistant or tool directly to its HTTP endpoint.
{
"mcpServers": {
"grafana": {
"url": "http://your-server-host:8000/mcp"
}
}
}Replace
your-server-hostwith the actual host where your MCP server is running.For local setup, use
localhostas the server host (i.e.,http://localhost:8000/mcp).Use
httpfor local or unsecured deployments, andhttpsfor production or secured deployments.Make sure the server is accessible from your client machine (check firewall, security group, etc.).
Health Check
curl http://localhost:8000/healthThe server runs on port 8000 by default.
5. Project Structure
grafana-mcp-server/
ā āāā src/
ā āāā grafana_mcp_server/
ā āāā __init__.py
ā āāā config.yaml # Configuration file
ā āāā mcp_server.py # Main MCP server implementation
ā āāā stdio_server.py # STDIO server for MCP
ā āāā processor/
ā āāā __init__.py
ā āāā grafana_processor.py # Grafana API processor
ā āāā processor.py # Base processor interface
āāā tests/
āāā Dockerfile
āāā docker-compose.yml
āāā pyproject.toml
āāā README.md6. Troubleshooting
Common Issues
Connection Failed:
Verify your Grafana instance is running and accessible
Check your API key has proper permissions
Ensure SSL verification settings match your setup
Authentication Errors:
Verify your API key is correct and not expired
Check if your Grafana instance requires additional authentication
Query Failures:
Ensure datasource UIDs are correct
Verify PromQL/Loki query syntax
Check if the datasource is accessible with your API key
Debug Mode
Enable debug mode to get more detailed logs:
export MCP_SERVER_DEBUG=true7. Contributing
Fork the repository
Create a feature branch (
git checkout -b feature/amazing-feature)Commit your changes (
git commit -m 'Add some amazing feature')Push to the branch (
git push origin feature/amazing-feature)Open a Pull Request
8. License
This project is licensed under the MIT License - see the LICENSE file for details.
9. Support
Need help anywhere? Join our discord channel and message on #mcp channel.
Want a 1-click MCP Server? Join the same community and let us know.
For issues and questions, please open an issue on GitHub or contact the maintainers.
Available Tools
10 toolsgrafana_fetch_all_dashboardsC
Fetches all dashboards from Grafana with basic information like title, UID, folder, tags, etc.
Inputs: limit.
grafana_fetch_dashboard_variablesC
Fetches all variables and their values from a Grafana dashboard. Retrieves dashboard template variables and their current values.
Inputs: dashboard_uid (required).
grafana_fetch_datasourcesB
Fetches all datasources from Grafana with their configuration details.
Inputs: no named parameters.
grafana_fetch_foldersB
Fetches all folders from Grafana with their metadata and permissions.
Inputs: no named parameters.
grafana_fetch_label_valuesC
Fetches label values for dashboard variables from Prometheus datasource. Retrieves available values for specific labels (e.g., 'instance', 'job').
Inputs: datasource_uid (required), label_name (required), metric_match_filter.
grafana_get_dashboard_configC
Retrieves dashboard configuration details from the database. Queries the connectors_connectormetadatamodelstore table for dashboard metadata.
Inputs: dashboard_uid (required).
grafana_loki_queryA
Queries Grafana Loki for log data. Fetches logs for a specified duration (e.g., '5m', '1h', '2d'), converts relative time to absolute timestamps. Note: Loki queries require at least one non-empty matcher. Use patterns like '{job=".+"}' instead of '{job=".*"}' or '{}' to avoid syntax errors.
Inputs: datasource_uid (required), query (required), duration, start_time, +2 more.
grafana_promql_queryC
Executes PromQL queries against Grafana's Prometheus datasource. Fetches metrics data using PromQL expressions, optimizes time series responses to reduce token size.
Inputs: datasource_uid (required), query (required), start_time, end_time, +1 more.
grafana_query_dashboard_panelsA
Executes queries for specific dashboard panels. Can query up to 4 panels at once, supports template variables, optimizes metrics data.
Inputs: dashboard_uid (required), panel_ids (required), template_variables.
test_connectionA
Test connection to Grafana API to verify configuration and connectivity. Requires API key or open Grafana instance.
Inputs: no named parameters.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelogā¦
TDQS
Scored across 10 tools
Every tool has a clearly distinct purpose targeting specific Grafana resources or functions. For example, grafana_fetch_all_dashboards retrieves dashboard lists while grafana_fetch_dashboard_variables gets template variables, and grafana_loki_query versus grafana_promql_query handle different query types. There is no overlap that would cause agent misselection.
All tools follow a consistent snake_case pattern with 'grafana_' prefix and descriptive verb_noun combinations. The naming convention is perfectly predictable: grafana_fetch_*, grafana_get_*, grafana_query_*, and grafana_*_query patterns are used appropriately throughout the set.
With 10 tools, this server is well-scoped for Grafana operations. Each tool earns its place by covering distinct aspects: dashboard management, data source access, query execution, and connectivity testing. This count provides comprehensive coverage without being overwhelming.
The toolset provides excellent coverage for querying, fetching, and testing Grafana resources. Minor gaps exist in dashboard lifecycle management (no create/update/delete operations for dashboards or folders), but agents can work effectively with the read-oriented operations provided for the core Grafana use cases.
Maintenance
Related MCP Connectors
The Grafbase MCP server sits in front of a GraphQL API and exposes an MCP protocol-compliant interface that allows AI agents and LLMs to explore and query GraphQL APIs using natural language. It provides tools to search schemas, introspect types and fields, and execute GraphQL queries while minimizing context bloat by returning only relevant schema subsets, with built-in support for authentication, authorization, and configurable access control.
MCP server for building and testing AI agents with multi-model experimentation and insights.
Query application logs, traces, and metrics from your AI coding assistant via Foam's MCP server.
Hosted MCP server connecting AI assistants to 9,000+ apps and 40,000+ actions via Zapier.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceAn MCP server that enables AI assistants to interact with Signoz observability platform, providing tools to query dashboards, metrics, traces, logs, and APM data with time range support.14MIT
- AlicenseAqualityDmaintenanceAn MCP server that enables AI assistants to query databases, execute SQL, and manage Metabase resources like dashboards, cards, and collections through natural language.2218 PyPIMIT
- AlicenseAqualityDmaintenanceA MCP server for Metabase that gives AI assistants direct access to dashboards, cards, and query execution.331MIT
- FlicenseNot gradedqualityDmaintenanceAn MCP server that enables AI assistants to query and analyze logs from Grafana Loki using LogQL, supporting label discovery and keyword search.4-