SuperAPI AI Directory

grafana-loki-mcp

Query Loki logs through the Grafana API.

Open website

About this tool

grafana-loki-mcp is a FastMCP server designed to query Loki logs through the Grafana API. It provides a set of tools that enable users to conveniently retrieve and analyze Loki log data.

Purpose

The server is mainly used to query Loki logs from Grafana, and is suitable for development or operations scenarios that need to integrate log query functionality.

Main Capabilities

  • Query Loki logs through the Grafana API
  • Retrieve Loki labels and label values
  • Format query results in different formats (text, JSON, Markdown)
  • Support stdio and SSE transport protocols

Usage

Environment Variables

The following environment variables need to be set:

  • GRAFANA_URL: The URL of the Grafana instance
  • GRAFANA_API_KEY: A Grafana API key with appropriate permissions

These values can also be provided through command-line arguments.

Command-Line Arguments

  • --transport: The transport protocol to use (stdio or sse, default:stdio)

Running the Server

Development setup instructions are provided, including using uv to install dependencies, run the test suite and coverage, and perform code linting and formatting.

Available Tools

  • query_loki: Query Loki logs through Grafana. Parameters include:
    • query: Loki query string
    • start: Start time (ISO format, Unix timestamp, or Grafana-style relative time such as 'now-1h', default: 1 hour ago)
    • end: End time (ISO format, Unix timestamp, or Grafana-style relative time such as 'now', default: now)
    • limit: Maximum number of log lines to return (default: 100)
    • direction: Query direction ('forward' or 'backward', default: 'backward')
    • max_per_line: Maximum number of characters per log line (0 means unlimited, default: 100)
  • get_loki_labels: Get all label names in Loki.
  • get_loki_label_values: Get the values of a specific label in Loki. Parameters:
    • label: Label name
  • format_loki_results: Format Loki query results in a more readable format. Parameters:
    • results: Loki query result from query_loki - format_type: Output format ('text', 'json', or 'markdown', default: 'text')
    • max_per_line: Maximum number of characters per log line (0 means unlimited, default: 0)

Applicable Scenarios

Suitable for developers, operations personnel, or data analysts who need to query Loki logs from Grafana, especially in scenarios where log queries need to be integrated into automated processes or AI tools.

Limitations

  • Requires a valid Grafana instance and API key.
  • Functionality is limited by the API capabilities of Grafana and Loki.
  • Specific information such as performance, pricing, and platform support is not yet provided.