loading…
Search for a command to run...
loading…
Model Context Protocol (MCP) server for Grafana - Complete TypeScript implementation with all tools
Model Context Protocol (MCP) server for Grafana - Complete TypeScript implementation with all tools
Complete TypeScript/JavaScript implementation of the Model Context Protocol (MCP) server for Grafana, enabling AI assistants to interact with Grafana dashboards, datasources, alerts, incidents, and more.
npm version npm downloads License MCP GitHub stars
npm install -g @leval/mcp-grafana
npx @leval/mcp-grafana
git clone https://github.com/levalhq/mcp-grafana.git
cd mcp-grafana
npm install
npm run build
Create a .env file in your project root:
# Required
GRAFANA_URL=https://your-grafana-instance.com
# Authentication (use one)
GRAFANA_SERVICE_ACCOUNT_TOKEN=glsa_xxxxxxxxxxxx # Recommended
# OR
GRAFANA_USERNAME=username # Basic auth
GRAFANA_PASSWORD=password
# Optional
DEBUG=true # Enable debug logging
TLS_CERT_FILE=/path/to/cert.pem # mTLS certificate
TLS_KEY_FILE=/path/to/key.pem # mTLS key
TLS_CA_FILE=/path/to/ca.pem # Custom CA certificate
TLS_SKIP_VERIFY=true # Skip TLS verification
Config File Locations:
~/Library/Application Support/Claude/claude_desktop_config.json%APPDATA%\Claude\claude_desktop_config.json~/.config/Claude/claude_desktop_config.jsonConfiguration:
{
"mcpServers": {
"grafana": {
"command": "npx",
"args": ["@leval/mcp-grafana"],
"env": {
"GRAFANA_URL": "https://your-grafana.com",
"GRAFANA_SERVICE_ACCOUNT_TOKEN": "glsa_xxxxxxxxxxxx"
}
}
}
}
Usage:
{
"claude.mcpServers": {
"grafana": {
"command": "npx",
"args": ["@leval/mcp-grafana"],
"env": {
"GRAFANA_URL": "https://your-grafana.com",
"GRAFANA_SERVICE_ACCOUNT_TOKEN": "glsa_xxxxxxxxxxxx"
}
}
}
}
Or configure globally in VS Code settings:
Cmd/Ctrl + Shift + P)claude.mcpServers configurationUsage:
Configuration: Add to .cursor/settings.json in your project root:
{
"ai.mcpServers": {
"grafana": {
"command": "npx",
"args": ["@leval/mcp-grafana"],
"env": {
"GRAFANA_URL": "https://your-grafana.com",
"GRAFANA_SERVICE_ACCOUNT_TOKEN": "glsa_xxxxxxxxxxxx"
}
}
}
}
Or configure globally:
Cmd/Ctrl + ,)Usage:
Cmd/Ctrl + K to open AI chatConfiguration: Add to ~/.config/zed/settings.json:
{
"assistant": {
"version": "2",
"mcp_servers": {
"grafana": {
"command": "npx",
"args": ["@leval/mcp-grafana"],
"env": {
"GRAFANA_URL": "https://your-grafana.com",
"GRAFANA_SERVICE_ACCOUNT_TOKEN": "glsa_xxxxxxxxxxxx"
}
}
}
}
}
Usage:
Cmd/Ctrl + ?)Configuration: Add to .github/codex/mcp-config.json:
{
"servers": {
"grafana": {
"command": "npx",
"args": ["@leval/mcp-grafana"],
"env": {
"GRAFANA_URL": "https://your-grafana.com",
"GRAFANA_SERVICE_ACCOUNT_TOKEN": "glsa_xxxxxxxxxxxx"
}
}
}
}
Usage:
Configuration: Add to ~/.continue/config.json:
{
"models": [...],
"mcpServers": {
"grafana": {
"command": "npx",
"args": ["@leval/mcp-grafana"],
"env": {
"GRAFANA_URL": "https://your-grafana.com",
"GRAFANA_SERVICE_ACCOUNT_TOKEN": "glsa_xxxxxxxxxxxx"
}
}
}
}
Usage:
Configuration: Add to .windsurf/mcp-servers.json:
{
"grafana": {
"command": "npx",
"args": ["@leval/mcp-grafana"],
"env": {
"GRAFANA_URL": "https://your-grafana.com",
"GRAFANA_SERVICE_ACCOUNT_TOKEN": "glsa_xxxxxxxxxxxx"
}
}
}
Usage:
| Tool | Description | Example Usage |
|---|---|---|
search_dashboards |
Search for dashboards | "Find dashboards with 'cpu' in the name" |
get_dashboard_by_uid |
Get complete dashboard JSON | "Show me the dashboard with UID abc123" |
get_dashboard_summary |
Get dashboard metadata | "Summarize the monitoring dashboard" |
get_dashboard_property |
Extract specific properties | "Get all panel titles from dashboard xyz" |
update_dashboard |
Create or update dashboards | "Add a new panel to track memory usage" |
| Tool | Description | Example Usage |
|---|---|---|
list_datasources |
List all datasources | "What datasources are configured?" |
get_datasource_by_uid |
Get datasource by UID | "Show details for datasource uid-123" |
get_datasource_by_name |
Get datasource by name | "Get the Prometheus datasource config" |
| Tool | Description | Example Usage |
|---|---|---|
query_prometheus |
Execute PromQL queries | "Show CPU usage for the last hour" |
list_prometheus_metric_names |
List available metrics | "What metrics are available?" |
list_prometheus_label_names |
List label names | "Show all Prometheus labels" |
list_prometheus_label_values |
Get label values | "What values exist for the 'env' label?" |
list_prometheus_metric_metadata |
Get metric metadata | "Describe the node_cpu_seconds metric" |
| Tool | Description | Example Usage |
|---|---|---|
query_loki_logs |
Execute LogQL queries | "Show error logs from the API service" |
query_loki_stats |
Get log stream statistics | "How many log entries in the last day?" |
list_loki_label_names |
List log label names | "What labels are in our logs?" |
list_loki_label_values |
Get log label values | "Show all namespaces in logs" |
find_error_pattern_logs |
Find error patterns | "Analyze error patterns in production" |
| Tool | Description | Example Usage |
|---|---|---|
list_incidents |
List incidents | "Show all active incidents" |
get_incident |
Get incident details | "Details for incident INC-123" |
create_incident |
Create new incident | "Create a critical incident for API outage" |
add_activity_to_incident |
Add notes to incidents | "Add update to incident INC-123" |
In Grafana UI:
Required Permissions:
dashboards:read - View dashboardsdatasources:read - View datasourcesalert.rules:read - View alert ruleslogs:read - Query Lokimetrics:read - Query Prometheusincidents:write - Manage incidents (if needed)# Test connection
curl -H "Authorization: Bearer YOUR_TOKEN" \
https://your-grafana.com/api/org
# Test with the MCP server
npx @leval/mcp-grafana --debug
# Clone the repository
git clone https://github.com/levalhq/mcp-grafana.git
cd mcp-grafana
# Install dependencies
npm install
# Run tests
npm test
# Test with your Grafana instance
node test/test-connection.js
node test/test-api.js
# Check if running correctly
npx @leval/mcp-grafana --debug
# Should output:
# Starting MCP Grafana server with stdio transport...
# MCP server started with stdio transport
# Test your credentials
curl -H "Authorization: Bearer YOUR_TOKEN" \
https://your-grafana.com/api/org
# Check response - should return org details
| Error | Solution |
|---|---|
| "Authentication failed" | Check your service account token |
| "No datasources found" | Verify datasource permissions |
| "Tool not found" | Ensure all tools are enabled |
| "Connection timeout" | Check network and Grafana URL |
| "Permission denied" | Add required permissions to service account |
npx @leval/mcp-grafana \
--disable-incident \
--disable-oncall \
--disable-sift
export TLS_CERT_FILE=/path/to/cert.pem
export TLS_KEY_FILE=/path/to/key.pem
export TLS_CA_FILE=/path/to/ca.pem
npx @leval/mcp-grafana
npx @leval/mcp-grafana --debug
# Or
export DEBUG=true
npx @leval/mcp-grafana
Contributions are welcome! Please feel free to submit a Pull Request.
# Fork and clone
git clone https://github.com/levalhq/mcp-grafana.git
cd mcp-grafana
# Install dependencies
npm install
# Make changes and test
npm test
# Build
npm run build
# Submit PR
All features from the original Go implementation have been migrated:
Apache-2.0 - See LICENSE file for details
This package is published on npm as @leval/mcp-grafana
# Install globally
npm install -g @leval/mcp-grafana
# Or use directly with npx
npx @leval/mcp-grafana
# View package info
npm info @leval/mcp-grafana
This TypeScript implementation provides full feature parity with the original Go version, with improved npm ecosystem integration and support for all major MCP clients.
Made with ❤️ for the Grafana and AI community
Add this to claude_desktop_config.json and restart Claude Desktop.
{
"mcpServers": {
"grafana": {
"command": "npx",
"args": [
"-y",
"@leval/mcp-grafana"
]
}
}
}pro tip
Just installed Grafana? Say to Claude: "remember why I installed Grafanaand what I want to try" — it'll save into your Vault.
how this works →