Sponsored by Deepsite.site

Grafana MCP Server

Created By
Christian Schlichtherle6 months ago
An MCP server for the comprehensive discovery, editing, and testing of dashboards and folders in one or more Grafana clusters. Its security model is based on labels and folders.
Content

Grafana MCP

This repository provides an MCP (Model Context Protocol) server for the comprehensive discovery, editing, and testing of dashboards and folders in one or more Grafana clusters. Its security model is based on labels and folders.

Quick Start

# Install and run with zero configuration (uses localhost:3000 by default)
uv sync
python main.py

# That's it! The server is ready to use with your local Grafana instance.

Features

  • Dashboard Protection: When creating Grafana dashboards, the MCP server labels them to mark itself as the origin
  • Selective Modification: Only dashboards with required protection labels can be updated or deleted
  • Unrestricted Reading: No restrictions for reading dashboards, allowing enhancement of existing dashboards by copying them
  • Folder Restrictions: Configurable access control to specific folders and subfolders
  • Multi-Cluster Support: Manage dashboards across multiple Grafana instances
  • Comprehensive Search: Full support for Grafana's search API with filtering options

Available MCP Tools

Discovery

Discover and explore Grafana resources across clusters.

Cluster Management

  • list_clusters() - List all configured Grafana cluster names
  • check_cluster_health(cluster: str) - Check health and connectivity of a Grafana cluster

Search Operations

  • search(cluster: str, *, query: str = "", tags: list = [], starred: bool = False, folder_uids: list = [], dashboard_uids: list = [], dashboard_ids: list = [], type: str = "", limit: int = 1000, page: int = 1) - Search dashboards and folders with comprehensive filtering options

Dashboard Discovery

  • read_dashboard(cluster: str, dashboard_uid: str) - Read any dashboard configuration and metadata (no restrictions)
  • inspect_dashboard(cluster: str, dashboard_uid: str) - Detailed structural analysis of dashboard panels, variables, datasources, and layout

Folder Discovery

  • list_folders(cluster: str, *, parent_uid: str = "") - List folders, optionally under a parent folder
  • get_folder(cluster: str, folder_uid: str) - Get detailed folder information including hierarchy and permissions

Datasource Discovery

  • list_datasources(cluster: str) - List all datasources in cluster with name, type, UID, and metadata

Editing

Create, modify, and manage Grafana resources with security controls.

Dashboard Management

  • create_dashboard(cluster: str, dashboard_json: dict, *, folder_uid: str = "") - Create new dashboard with automatic protection labels
  • update_dashboard(cluster: str, dashboard_uid: str, dashboard_json: dict) - Update existing dashboard (requires protection labels)
  • delete_dashboard(cluster: str, dashboard_uid: str) - Delete dashboard (requires protection labels)
  • copy_dashboard(source_cluster: str, source_uid: str, new_title: str, *, target_cluster: str = "", folder_uid: str = "", target_uid: str = "") - Copy dashboard with intelligent UID handling and auto-overwrite capabilities

Folder Management

  • create_folder(cluster: str, title: str, *, parent_uid: str = "") - Create new folder, optionally as subfolder
  • update_folder(cluster: str, folder_uid: str, title: str, *, parent_uid: str = "") - Update/rename/move folder to different parent
  • delete_folder(cluster: str, folder_uid: str, *, force_delete_rules: bool = False) - Delete folder with optional alert rule cleanup

Testing

Validate, test, and analyze dashboard quality and data accuracy.

Validation & Quality Assurance

  • validate_dashboard(cluster: str, dashboard_uid: str) - Comprehensive schema validation and best practices checking
  • compare_dashboards(cluster: str, dashboard_uid_a: str, dashboard_uid_b: str, *, compare_cluster_b: str = "") - Compare two dashboards showing structural and configuration differences

Data Verification & Testing

  • snapshot_dashboard(cluster: str, dashboard_uid: str, *, snapshot_name: str = "", expires_hours: int = 24, time_from: str = "now-6h", time_to: str = "now") - Create snapshot with current data for inspection and testing
  • test_panel_render(cluster: str, dashboard_uid: str, panel_id: int, *, width: int = 1000, height: int = 500, time_from: str = "now-6h", time_to: str = "now", save_to_file: str = "") - Render panel as PNG for visual validation

Configuration

Environment Variables

Configure the MCP server using these environment variables:

# Cluster URLs (space-separated key=value pairs, defaults to "localhost=http://localhost:3000")
export GRAFANA_CLUSTERS="localhost=http://localhost:3000 dev=https://grafana.dev.example.com prod=https://grafana.prod.example.com"

# Cluster API tokens (space-separated key=value pairs, optional)
# Only required for clusters that need authentication
export GRAFANA_TOKENS="dev=glsa_yyy prod=glsa_zzz"  # Note: localhost has no token (unauthenticated)

# Protection labels (space-separated, defaults to "MCP")
export GRAFANA_LABELS="MCP Claude"

# Folder restriction (defaults to "/" for root access)
export GRAFANA_FOLDER=/MCP

Local Development Without Authentication

For local development, you can run Grafana in a Docker container without authentication:

# Run Grafana without authentication
docker run -d \
  -p 3000:3000 \
  -e "GF_AUTH_ANONYMOUS_ENABLED=true" \
  -e "GF_AUTH_ANONYMOUS_ORG_ROLE=Admin" \
  -e "GF_AUTH_BASIC_ENABLED=false" \
  --name grafana \
  grafana/grafana:latest

# Configure MCP server for unauthenticated local access
export GRAFANA_CLUSTERS="localhost=http://localhost:3000"
# No GRAFANA_TOKENS needed!

# Or use the default configuration (no environment variables needed!)
# This defaults to localhost=http://localhost:3000 without authentication

# Run the MCP server
python main.py

Mixed Authentication Environments

You can mix authenticated and unauthenticated clusters:

# Local without auth, production with auth
export GRAFANA_CLUSTERS="localhost=http://localhost:3000 prod=https://grafana.prod.com"
export GRAFANA_TOKENS="prod=glsa_abc123"  # Only prod needs a token

Authentication Setup (For Production Clusters)

For production or authenticated Grafana clusters, you need to create service account tokens. Service accounts are the recommended way to authenticate with Grafana's HTTP API (API keys are deprecated).

Note: Skip this section if you're only using local unauthenticated Grafana instances.

Creating Service Account Tokens via Grafana UI

  1. Create Service Account:

    • Navigate to AdministrationUsers and accessService Accounts
    • Click "Add service account"
    • Enter a Display name (e.g., "MCP Server")
    • Select appropriate Role: Viewer, Editor, or Admin
    • Click "Create"
  2. Generate Token:

    • Select your newly created service account
    • Click "Add service account token"
    • Enter a Display name for the token
    • Set Expiration date (or select "No expiration")
    • Click "Generate token"
    • Important: Copy and save the token immediately - it's only shown once!

Creating Service Account Tokens via API

# Create service account
curl -X POST -H "Content-Type: application/json" \
  -d '{"name": "mcp-server", "role": "Editor"}' \
  http://admin:admin@localhost:3000/api/serviceaccounts

# Create token for the service account (use ID from previous response)
curl -X POST -H "Content-Type: application/json" \
  -d '{"name": "mcp-token"}' \
  http://admin:admin@localhost:3000/api/serviceaccounts/{id}/tokens

Using Tokens

Tokens should be prefixed with glsa_ and used in the GRAFANA_TOKENS environment variable:

export GRAFANA_TOKENS="prod=glsa_abc123def456 dev=glsa_xyz789uvw012"

Authentication in Requests

The MCP server automatically adds the Bearer token to all requests:

Authorization: Bearer glsa_abc123def456

For more information, see the official Grafana documentation on service accounts.

Installation & Usage

  1. Install dependencies:

    uv sync
    # or
    pip install -e .
    
  2. Set environment variables (see Configuration section above)

  3. Run the MCP server:

    python main.py
    

The server will validate your configuration and start the MCP server, making all tools available to MCP clients.

Example Usage

# List all configured clusters
clusters = list_clusters()
# Returns: ["localhost", "prod"]

# Explore folder hierarchy
root_folders = list_folders("prod")  # List root-level folders
subfolders = list_folders("prod", parent_uid="folder123")  # List subfolders

# Search for dashboards and folders
dashboards = search("prod", query="monitoring", tags=["production"])
folders_only = search("prod", type="dash-folder", query="team")
dashboards_only = search("prod", type="dash-db", starred=True)

# Create and manage folders
folder = create_folder("prod", "Team Alpha", parent_uid="parent123")
updated = update_folder("prod", "folder123", "New Name", parent_uid="new_parent")

# Copy a dashboard into a specific folder
new_dash = copy_dashboard("prod", "abc123def", "My New Dashboard", folder_uid="folder123")

# Create a dashboard with protection labels automatically added
result = create_dashboard("prod", {
    "title": "Test Dashboard",
    "panels": [...],
    "tags": ["custom"]  # MCP labels will be automatically added
}, folder_uid="folder123")

Security Model

  • Label-Based Protection: Dashboards created by this MCP server are automatically tagged with protection labels
  • Selective Operations: Only dashboards with required labels can be updated or deleted
  • Folder Restrictions: Operations can be restricted to specific folder hierarchies
  • Token-Based Auth: Uses secure service account tokens instead of deprecated API keys
  • No Overwrites: Dashboard creation prevents accidental overwrites of existing dashboards

Server Config

{
  "mcpServers": {
    "grafana": {
      "command": "uv",
      "args": [
        "--directory",
        "/ABSOLUTE/PATH/TO/grafana-mcp",
        "run",
        "main.py"
      ],
      "env": {
        "GRAFANA_CLUSTERS": "local=http://localhost:3000 dev=https://dev.example.com/grafana",
        "GRAFANA_TOKENS": "dev=glsa_abc123xyz"
      }
    }
  }
}
Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
DeepChatYour AI Partner on Desktop
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
Playwright McpPlaywright MCP server
Amap Maps高德地图官方 MCP Server
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
CursorThe AI Code Editor
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
ChatWiseThe second fastest AI chatbot™
WindsurfThe new purpose-built IDE to harness magic
Serper MCP ServerA Serper MCP Server
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Tavily Mcp