SuperAPIAI Directory

loki-mcp-server

github.com · AI developer platforms

Query Grafana Loki directly with a discovery-first workflow: labels, values, series and LogQL queries, without requiring Grafana.

Open website Alternatives
PricingOpen source开源项目(可免费自部署)
PlatformsmacOS · Linux

About this tool

Purpose

loki-mcp-server is an MCP (Model Context Protocol) server written in Go, with the goal of letting AI agents query Grafana Loki logs directly, without going through Grafana. It targets AI-driven log analysis scenarios, uses LogQL as the query language, and can be integrated into AI agent frameworks, automation tools, and DevOps workflows.

Main capabilities

The server provides 5 fine-grained tools:

  • query_range: executes a LogQL range query to retrieve logs within a certain time window.
  • query: executes a LogQL instant query, used for point-in-time evaluation.
  • labels: lists all available label names in Loki.
  • label_values: lists all values of a specific label.
  • series: finds active log stream series matching a selector.

Unlike the official grafana/loki-mcp, which exposes only a single loki_query tool, this project adopts a "discover first, then query" workflow: labels, label_values, and series let the LLM first discover what is available in Loki, then construct precise query_range or query calls, thereby obtaining more accurate log retrieval results and reducing invalid round trips.

In addition, the server enforces strict input validation, including limit caps, direction validation, label name format checks, and mutually exclusive authentication methods, so as to surface errors early rather than forwarding erroneous requests to Loki.

Usage

The server is configured entirely through environment variables, injected by the MCP client. Note: basic authentication (LOKI_USERNAME / LOKI_PASSWORD) and bearer token (LOKI_BEARER_TOKEN) are mutually exclusive.

By default, the server communicates via the MCP protocol over stdio, which is what Claude Code, Claude Desktop, and most local clients expect. Setting MCP_HTTP_ADDR switches to serving the streamable HTTP transport instead, for running the server as a remote endpoint behind a proxy or gateway. HTTP mode is stateless, so it can run behind a load balancer and be deployed with multiplereplicas. It does not carry authentication itself; before exposure it should be placed behind TLS and an authentication proxy; anyone who can access the endpoint can read every line of logs visible to the configured LOKI_URL credentials.

When used with Claude Code, add it to Claude Code's MCP configuration (~/.claude.json). When used with Claude Desktop, add it to the Claude Desktop configuration (on macOS, ~/Library/Application Support/Claude/claude_desktop_config.json).

Applicable scenarios

  • AI agents performing log analysis and troubleshooting.
  • Integrating Loki log queries into automation tools and DevOps workflows.
  • Scenarios that require letting the LLM first discover labels and log streams, then construct precise LogQL queries.

Limitations

  • HTTP mode is stateless and does not provide authentication itself; it must be placed behind TLS and an authentication proxy.
  • Basic authentication and bearer token are mutually exclusive and cannot be used at the same time.
  • Specific installation commands, build steps, and configuration examples are not fully given in the provided materials and are not provided for now.

Local development environment

Under deploy/ there is a Docker Compose configuration that can start a complete Loki test environment: Loki log storage is located at http://localhost:3100;Grafana UI is located at http://localhost:3000(匿名管理员,已预配置 Loki as the data source); Promtail collects container logs and sends them to Loki; the log generator emits structured JSON logs, including random applications (nginx, api, gateway, auth, payments), levels, and messages.

Up/Down to navigate · Enter to open · ESC to closeBrowse all tools