Loki MCP Server logo

Loki MCP Server

Read-only Grafana Loki access over stdio with LogQL queries, label discovery, counts, and local exports.

Install Loki MCP Server

Pick your client, then add it in one click or paste the config.

No confirmed install command yet

We only publish a config when the install details come from the project itself — its README, its docs, or a verified owner. We haven’t found those for Loki MCP Server, and we’d rather show nothing than a guess you’d paste into your client.

Open setup steps on GitHub

Overview

Loki MCP Server MCP server connects AI agents to Grafana Loki through a local stdio process. It provides tools for discovering labels, running bounded LogQL queries, counting matching log lines, listing configured connections, and exporting results locally. The server supports Loki 2.6.1 and 3.x, uses explicit connection profiles, and keeps Loki itself read-only. Reach for it when an agent needs controlled log investigation without write access to Loki.

Use cases

  • Discover Loki labels before writing a LogQL query
  • Inspect recent application errors with bounded pages
  • Count log volume by service or time bucket
  • Export matching logs to a local file
  • Configure separate Loki environments for an agent

Key features

  • Read-only Grafana Loki access
  • Label and stream discovery
  • Bounded LogQL queries
  • Grouped log counts
  • Local raw or templated exports
  • Per-connection limits and authentication

Security & health

What it can reach and how reliably it runs — from our own checks, not the maintainer’s claims.

ActiveLast checked Today

Recent health check succeeded.

4/4 checks healthy over the last 13d

How Loki MCP Server works

What Loki MCP Server does

Loki MCP Server MCP server gives an MCP-compatible client read-only access to Grafana Loki. It is intended for agent-assisted log investigation: an agent can inspect available labels, construct a LogQL log query, review matching lines, measure event volume, and save results to a local file. Loki is never modified; the only write operation is the local file created by exportLogs.

The server exposes five text tools. listConnections displays configured Loki stands, operator hints, and effective limits. discoverLogs explores label names, values, and stream-label combinations. queryLogs reads bounded pages of the newest or oldest matching lines. countLogs counts matches, optionally grouped by label, time bucket, or both. exportLogs writes matching lines to a local destination using raw output or a configured rendering template.

How it works

The process communicates through MCP JSON-RPC on standard input and output. Diagnostic messages go to standard error and a local log file, leaving stdout available for protocol traffic. Each data operation requires an explicit connection name. Queries must be LogQL log queries, such as {app="backend"} |= "ERROR"; the server does not infer filters or explain the cause of an incident.

A practical workflow starts with listConnections, followed by discoverLogs to identify label names and real stream-label combinations. The agent can then use countLogs to estimate volume before retrieving lines with queryLogs. Responses are readable text rather than structured output schemas. Query pages are bounded, and default compact output shortens messages and stack traces to reduce token use. Raw query output is a preview; complete lines should be written with exportLogs.

The implementation supports Grafana Loki 2.6.1 and 3.x. Default windows, page sizes, request timeouts, and export limits are configurable per connection. Time inputs can use relative expressions, RFC3339 values, local connection time, or epoch nanoseconds.

Setup and configuration

Java 21 or newer is required. Build the JAR with the Gradle wrapper, or download the prebuilt artifact attached to a release, then launch it with java -jar. Docker images are published to GHCR; the container must run interactively so the MCP client can keep stdin open.

Connection profiles are read from ~/.loki-mcp-server/connections.json unless LOKI_MCP_CONNECTIONS_FILE points to another file. A profile includes a Loki URL and can also define a description, operator hint, timezone, service labels, authentication and tenant headers, limits, export roots, and formatting files. Configuration is validated at startup. Unknown fields, duplicate keys, missing environment variables, and invalid format files stop startup, and changes require a restart.

When using Docker, mount the directory containing connections.json at /data. Loki hostnames must be reachable from inside the container; localhost refers to the container itself. Any export directory outside the mounted data directory must also be mounted. Keep stderr separate from stdout in client configuration.

Tools and capabilities

  • Discover label names, values, and matching stream-label sets.
  • Run bounded newest-first or oldest-first LogQL log queries.
  • Count matching lines by total, label, time bucket, or combined groups.
  • Export results without overwriting an existing file.
  • Apply raw output or local templates to exported lines.
  • Use connection-specific limits, hints, timezones, authentication, and tenant headers.

Limitations and notes

Loki MCP Server MCP server is read-only against Loki and does not change streams or records. countLogs builds only the count_over_time expression; it does not derive filters or interpret operational causes. A Loki request times out after the configured limit, and large result sets must be narrowed or paged. Export can produce a partial file if its time limit is reached, and multiple lines sharing one nanosecond may exceed a Loki page boundary.

queryLogs has a default maximum of 1,000 lines per page. Its raw mode is limited to a preview of returned content, with stream labels and up to 4,000 code points per line; use export for complete lines. Boundary lines can repeat between pages. Discovery windows also have limits, and matching stream-label discovery should use a narrow time range when possible. URLs, credentials, tenant headers, and full log lines are excluded from tool responses and diagnostics.

Reviews

No reviews yet — be the first to share how it worked for you.

Frequently Asked Questions about Loki MCP Server

Loki MCP Server is an MCP server that connects AI agents to Grafana Loki through stdio. Its main tools list connections, discover labels and stream sets, run bounded LogQL queries, count matching lines, and export results to local files. Loki remains read-only; only local exports write data.

Install Java 21 or newer, build or download the JAR, and launch it with `java -jar loki-mcp-server.jar`. Configure connections in `~/.loki-mcp-server/connections.json`, or set `LOKI_MCP_CONNECTIONS_FILE` to another path. A Docker image is also available from GHCR.

Add named connection profiles to `connections.json`, including each Loki URL. Profiles may also define timezones, hints, service labels, authentication and tenant headers, limits, export roots, and formatting options. The server validates this file at startup and requires a restart after changes.

Yes, `exportLogs` writes matching lines to a local file and is the supported way to obtain complete output. `queryLogs` raw mode is only a preview and limits each returned line to 4,000 code points. Exports never overwrite an existing file.

Yes, Claude Code can launch it with `claude mcp add` and the Java command. The server uses stdio, so other MCP clients can also launch the JAR as a standard process, provided stderr remains separate from stdout.

Related MCP servers

Add a badge to your READMEShow it’s listed — live SVG, Markdown or HTML.

AllMCPs Directory Badge

Full Badge Customizer

Showcase your server listing on GitHub or your project documentation. Embed this dynamic SVG badge to highlight official listing status and live engagement.

Badge Style:
Live Dynamic SVG PreviewLoki MCP Server AllMCPs Directory Badge
Markdown (GitHub README)
[![AllMCPs](https://allmcps.com/api/badge/loki-mcp-server?style=directory)](https://allmcps.com/mcp/loki-mcp-server)
HTML Embed
<a href="https://allmcps.com/mcp/loki-mcp-server"><img src="https://allmcps.com/api/badge/loki-mcp-server?style=directory" alt="Loki MCP Server on AllMCPs" /></a>