Grafana MCP Server

repository·main·Indexed 25 days ago

https://github.com/grafana/mcp-grafana

A Model Context Protocol (MCP) implementation that provides AI models with access to Grafana instances. It enables AI agents to manage dashboards, query datasources (including Prometheus, Loki, and Snowflake), handle alerting and OnCall schedules, perform Sift investigations, and generate resource deeplinks. Requires Grafana version 9.0 or later.

Tokens
51.5K
Snippets
119
Records
309
Agent score
83%

What's inside mcp-grafana

  1. Understand the Grafana MCP server capabilities

    main

    The Grafana MCP server implements the Model Context Protocol (MCP), allowing AI assistants (like Claude Desktop, Cursor, or VS Code with Copilot) to interact with Grafana without custom integrations. The server exposes tools that map to Grafana actions, enabling an AI assistant to perform tasks on your behalf.

    Key Tool Categories:

    • Dashboards: Search, get summary, get panel queries, update, and patch.
    • Folders: Search and create.
    • Datasources: List and query (Prometheus, Loki, InfluxDB, ClickHouse, Snowflake, CloudWatch, Elasticsearch, Pyroscope).
    • Alerting: Rules and routing.
    • Incidents & OnCall: Grafana Incident (incidents) and OnCall (schedules, alert groups).
    • Sift: Investigations, error patterns, and slow requests.
    • Navigation: Generating deeplinks.
    • Other: Annotations, snapshots (list, get, create, delete), and rendering (panel or dashboard images).
    • Proxied Tools: Tools from external MCP servers reachable through Grafana (e.g., Grafana Tempo).

    Note: Some tool categories are disabled by default to save context window space. Use the configuration guide to enable them. For dashboard interactions, use get_dashboard_summary and get_dashboard_property instead of get_dashboard_by_uid to minimize context window usage.

  2. Choose between Open Source and Grafana Cloud MCP server options

    main

    Decide which MCP server implementation to use based on your hosting and authentication needs:

    OptionBest forAuthentication
    Open source Grafana MCP serverRunning and managing the MCP server yourself for Grafana Cloud or self-managed GrafanaService account token
    Grafana Cloud MCP serverConnecting external AI agents to Grafana Cloud without installing a local serverOAuth 2.1 browser authorization, scoped to the signed-in Grafana user

    Use the open source server documentation for self-managed or manual deployments. For the hosted version, refer to the Grafana Cloud MCP server documentation.

  3. Use the Article template for non-index pages

    main

    When creating new documentation articles, use a named Markdown file where the filename is the page title slug (using dashes). Use the following frontmatter and structure:

    ---
    title: Topic title
    menuTitle: Short title
    description: Description
    keywords:
      - keyword
    weight: 1
    aliases:
      - /old-url/
    ---
    
    # Topic title
    
    Introduction providing overview of goals and content.
    
    ## What you'll achieve
    
    Overview of outcomes (if relevant).
    
    ## Before you begin
    
    List requirements.
    
    ## <ACTION_VERB_HEADING>
    
    Start headings with verbs. Don't use "Step X:" in headings.
    
    ## Next steps
    
    Links to related articles (if relevant). Don't use "refer to" syntax.
  4. Publish a new release manually

    main

    Releases follow a branch-based workflow. If you are not using the automated /draft-release command, follow these manual steps:

    1. Determine the next version: Identify the next version based on the latest git tag.
    2. Create a release branch: Checkout a new branch named release/vX.Y.Z from main.
    3. Update CHANGELOG.md: Add entries for the new version following the Keep a Changelog format.
    4. Commit and Push: Commit the changes and push the branch to origin.
    5. Create a PR: Open a Pull Request for review.
    6. Merge and Tag: After merging the PR, if the auto-tag.yml workflow is not configured, you must manually tag and push the version:
    git checkout main && git pull
    git tag vX.Y.Z HEAD
    git push origin vX.Y.Z
  5. Use docs.agent with an AI agent

    main

    To use docs.agent, run your preferred CLI AI agent within the repository and provide the following instruction to trigger its behavior:

    Follow docs/agent/rules.md

    Once active, the agent can be used to automatically scope work, update context and plans, and author documentation content.

    Follow docs/agent/rules.md
  6. Set up mcp-grafana for Windsurf IDE

    main

    To use the Grafana MCP server within the Windsurf IDE, ensure you have the following prerequisites:

    • Windsurf IDE installed
    • Grafana 9.0+ with a service account token
    • mcp-grafana binary available in your system PATH

    You can configure the server either through the Windsurf UI (Cmd+Shift+P -> Open Windsurf Settings -> Cascade section -> Add Server) or by manually editing the configuration file located at:

    • macOS/Linux: ~/.codeium/windsurf/mcp_config.json
    • Windows: %USERPROFILE%\.codeium\windsurf\mcp_config.json
  7. Configure RBAC permissions for the MCP server

    main

    The MCP server requires specific Grafana RBAC permissions and scopes to function. When creating a service account:

    1. Grant Minimum Permissions: Assign only the actions required for the tools you enable.
    2. Matching Scopes: Ensure permissions are paired with appropriate scopes (e.g., datasources:*, dashboards:*).
    3. Quick Setup: For faster configuration, assign the built-in Editor role to the service account. This provides broad read/write access suitable for most MCP operations, though it is less granular than a least-privilege approach.

    Special Note for Grafana Incident and Sift tools: These use basic roles rather than fine-grained RBAC:

    • Viewer: Read-only (e.g., list incidents, get investigations).
    • Editor: Write operations (e.g., create incidents, run analyses that modify state).
  8. Enable OpenTelemetry logs

    main

    The server exports structured logs via OTLP/gRPC when OTEL_EXPORTER_OTLP_ENDPOINT (or OTEL_EXPORTER_OTLP_LOGS_ENDPOINT) is set. Logs include trace_id and span_id for correlation with traces. Traces and logs can be enabled independently by using their specific environment variables. Logs are also exported under the stdio transport. If the collector is unreachable, logs are buffered in memory (default queue: 2048) before being dropped.

    # Send logs and traces to a local OTel collector
    OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317 \
    OTEL_EXPORTER_OTLP_INSECURE=true \
    ./mcp-grafana -t streamable-http