Skip to main content
Glama
Grafana MCP Server

Grafana MCP Server

by alludium

Grafana MCP Server

MCP (Model Context Protocol) server for querying Grafana Loki logs. Enables Claude to search your logs using natural language.

Features

  • 🔍 Search logs using LogQL query language

  • ⏰ Time-based filtering (hours back from now)

  • 📊 Configurable result limits

  • 📝 Markdown or JSON response formats

  • 🔐 Secure API key authentication

Related MCP server: Loki MCP Server

Installation

Option 1: Local Development (Use from cloned repo)

Setup:

# Clone and build
git clone https://github.com/alludium/grafana-mcp-server.git
cd grafana-mcp-server
npm install
npm run build

For Claude Desktop - Add to your claude_desktop_config.json:

{
  "mcpServers": {
    "grafana": {
      "command": "node",
      "args": ["/absolute/path/to/grafana-mcp-server/dist/index.js"],
      "env": {
        "GRAFANA_URL": "https://your-grafana-instance.com",
        "GRAFANA_API_KEY": "${GRAFANA_API_KEY}"
      }
    }
  }
}

For Claude Code - Add to .claude/config.json in your project:

{
  "mcpServers": {
    "grafana": {
      "command": "node",
      "args": ["/absolute/path/to/grafana-mcp-server/dist/index.js"],
      "env": {
        "GRAFANA_URL": "https://your-grafana-instance.com",
        "GRAFANA_API_KEY": "${GRAFANA_API_KEY}"
      }
    }
  }
}

Option 2: npm Package (When published)

For Claude Desktop - Add to your claude_desktop_config.json:

{
  "mcpServers": {
    "grafana": {
      "command": "npx",
      "args": ["-y", "@alludium/grafana-mcp-server"],
      "env": {
        "GRAFANA_URL": "https://your-grafana-instance.com",
        "GRAFANA_API_KEY": "${GRAFANA_API_KEY}"
      }
    }
  }
}

For Claude Code - Add to .claude/config.json in your project:

{
  "mcpServers": {
    "grafana": {
      "command": "npx",
      "args": ["-y", "@alludium/grafana-mcp-server"],
      "env": {
        "GRAFANA_URL": "https://your-grafana-instance.com",
        "GRAFANA_API_KEY": "${GRAFANA_API_KEY}"
      }
    }
  }
}

Set your API key in your environment:

export GRAFANA_API_KEY="your_grafana_api_key"

Usage

Once configured, you can ask Claude to search logs naturally:

"Search our production logs for 5xx errors in the last hour"
"Find all database timeout errors from the last 24 hours"
"Show me errors in the auth service from the last 30 minutes"

Direct LogQL Queries

You can also provide specific LogQL queries:

"Search logs with query: {app=\"web\"} |= \"error\""
"Query: {job=\"api\"} |~ \"timeout|failed\" for the last 6 hours"

Tool: search_logs

Search Grafana Loki logs using LogQL query language.

Parameters:

  • query (string, required): LogQL query string

    • Example: {app="web"} |= "error"

  • hours (number, optional): Hours to search back from now (default: 1)

  • limit (number, optional): Maximum number of log lines (default: 100)

  • response_format (string, optional): "markdown" or "json" (default: "markdown")

Example:

{
  "query": "{namespace=\"production\"} |~ \"5[0-9]{2}\"",
  "hours": 24,
  "limit": 50,
  "response_format": "markdown"
}

Configuration

Environment Variables

  • GRAFANA_URL: Your Grafana instance URL (e.g., https://grafana.example.com)

  • GRAFANA_API_KEY: API key with read access to Loki

Getting a Grafana API Key

  1. Log in to your Grafana instance

  2. Go to Configuration → API Keys

  3. Click "New API Key"

  4. Name: "MCP Server" or similar

  5. Role: Viewer (read-only access is sufficient)

  6. Copy the generated key

Development

# Clone the repository
git clone https://github.com/alludium/grafana-mcp-server.git
cd grafana-mcp-server

# Install dependencies
npm install

# Set environment variables
cp .env.example .env
# Edit .env with your Grafana URL and API key

# Run in development mode
npm run dev

# Build
npm run build

# Run built version
npm start

LogQL Query Examples

# All errors from web app
{app="web"} |= "error"

# 5xx HTTP errors
{job="api"} | json | status >= 500

# Pattern matching for timeouts or failures
{service="backend"} |~ "timeout|failed"

# Specific time range with filters
{namespace="production", app="auth"} |= "login" | json | status != 200

License

MIT

Author

Alludium

Available Tools

1 tool
search_logsC

Search Grafana Loki logs using LogQL query language. Returns log entries matching the query within the specified time range.

Inputs: query (required), hours, limit, response_format.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3/5.0

    Scored across 1 tool

    Disambiguation5/5

    With only a single tool exposed, there is no possibility of tool confusion or misselection. The one tool has a clear, specific purpose (LogQL log search).

    Naming Consistency4/5

    The single name search_logs follows a clear verb_noun snake_case convention, which is a good choice for a Grafana tool. Consistency cannot be fully demonstrated with only one tool, so it falls short of a 5.

    Tool Count2/5

    A single tool is far too thin for a server branded as a general 'Grafana MCP Server', which implies dashboards, alerts, datasources, and metrics. One narrowly scoped log-search tool does not earn the server's stated scope.

    Completeness2/5

    The surface covers only log search; there is no way to list or query dashboards, Prometheus metrics, alerts, or datasources. Even within logs, there is no metadata/discovery tool, leaving agents with dead ends for most Grafana workflows.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables querying and formatting Loki logs from Grafana via the Model Context Protocol. It supports LogQL queries, label retrieval, and provides results in text, JSON, or markdown formats.
      750 PyPI
      29
      MIT
    • F
      license
      Not graded
      quality
      D
      maintenance
      Enables AI models to query and analyze Kubernetes cluster logs through Grafana Loki, supporting semantic operations like error aggregation and pod restart detection. It provides tools for regex-based log searching and namespace discovery to facilitate natural language troubleshooting.
      -
    • A
      license
      A
      quality
      C
      maintenance
      Enables read-only querying of Grafana Loki logs through tools like label discovery, LogQL queries, and recent log retrieval, without requiring knowledge of the Loki API.
      4
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables AI agents to query Grafana dashboards, alerts, and datasources for observability insights and incident investigation.
      MIT