Loki MCP Server
The Loki MCP Server enables AI agents to query and analyze Grafana Loki logs through the Model Context Protocol (MCP) using LogQL.
query_range— Execute LogQL range queries to fetch logs over a time window, with configurable start/end times, result limit (up to 5000), and sort direction (forward/backward)query— Execute LogQL instant queries for point-in-time log evaluation, with configurable timestamp, result limit, and directionlabels— List all available label names in Loki within a given time range, useful for discovering what labels exist before building querieslabel_values— Retrieve all unique values for a specific label name within a time range, enabling dynamic query constructionseries— Find active log stream series matching a stream selector (e.g.{app="nginx"}), helping identify which log streams are currently active
Additional capabilities include support for basic auth, bearer tokens, and multi-tenant deployments; strict input validation (limit caps, direction checks, label format); and seamless integration with Claude Desktop, Claude Code, AI agent frameworks, and DevOps workflows. A local Docker Compose stack with Loki, Grafana, Promtail, and a log generator is included for development and testing.
Enables querying Grafana Loki logs using LogQL, allowing for the discovery of labels, label values, and active series, and the execution of range and instant queries for log retrieval.
Loki MCP Server
Query Grafana Loki logs directly from AI agents using the Model Context Protocol (MCP).
Built in Go. Enables AI-powered log analysis using LogQL.
Supports integration with:
Claude Desktop
AI agent frameworks
automation tools
DevOps workflows
Motivation
The official grafana/loki-mcp exposes a single loki_query tool, which means the LLM must already know valid label names and values before it can build a query. This project takes a different approach by providing 5 granular tools — labels, label_values, and series let the LLM discover what's available in Loki first, then construct precise query_range or query calls. The result is more accurate log retrieval with fewer wasted round-trips.
Additionally, this server enforces strict input validation (limit caps, direction validation, label name format checks, mutually exclusive auth) to surface errors early instead of forwarding bad requests to Loki.
Related MCP server: Overwatch MCP
Features
query_range — Execute LogQL range queries to fetch logs over a time window
query — Execute LogQL instant queries for point-in-time evaluation
labels — List all available label names
label_values — List values for a specific label
series — Find active log stream series matching a selector
Installation
Homebrew
brew install incu6us/tap/loki-mcp-serverGo install
go install github.com/incu6us/loki-mcp-server/cmd/loki-mcp-server@latestOr build from source:
git clone https://github.com/incu6us/loki-mcp-server.git
cd loki-mcp
go build -o loki-mcp-server ./cmd/loki-mcp-serverConfiguration
The server is configured entirely via environment variables, injected by the MCP client.
Variable | Required | Default | Description |
| yes | — | Base URL of the Loki instance |
| no | — | Basic auth username |
| no | — | Basic auth password |
| no | — | Bearer token authentication |
| no |
| Skip TLS certificate verification |
| no | — |
|
| no |
| HTTP request timeout (Go duration, e.g. |
| no | — | Listen address for the streamable HTTP transport, e.g. |
Note: Basic auth (
LOKI_USERNAME/LOKI_PASSWORD) and bearer token (LOKI_BEARER_TOKEN) are mutually exclusive.
Transports
By default the server speaks MCP over stdio, which is what Claude Code, Claude Desktop and most local clients expect.
Set MCP_HTTP_ADDR to serve the streamable HTTP transport instead, for running the
server as a remote endpoint behind a proxy or gateway:
LOKI_URL=http://loki:3100 MCP_HTTP_ADDR=:8080 loki-mcp-server
# MCP endpoint: http://localhost:8080/mcpThe HTTP mode is stateless, so it can run behind a load balancer with several replicas.
It carries no authentication of its own — put it behind TLS and an authenticating proxy
before exposing it, and remember that whoever reaches the endpoint can read every log
line the configured LOKI_URL credentials can see.
Usage with Claude Code
Add to your Claude Code MCP configuration (~/.claude.json):
{
"mcpServers": {
"loki-mcp-server": {
"type": "stdio",
"command": "/path/to/loki-mcp-server",
"args": [],
"env": {
"LOKI_URL": "http://loki:3100",
"LOKI_USERNAME": "admin",
"LOKI_PASSWORD": "secret"
}
}
}
}Usage with Claude Desktop
Add to your Claude Desktop config (~/Library/Application Support/Claude/claude_desktop_config.json on macOS):
{
"mcpServers": {
"loki-mcp-server": {
"type": "stdio",
"command": "/path/to/loki-mcp-server",
"args": [],
"env": {
"LOKI_URL": "http://loki:3100",
"LOKI_USERNAME": "admin",
"LOKI_PASSWORD": "secret"
}
}
}
}Tools
query_range
Execute a LogQL range query against Loki to fetch logs over a time window.
Parameter | Type | Required | Default | Description |
| string | yes | — | LogQL query expression |
| string | no | 1 hour ago | Start of time range (RFC3339 or Unix nano) |
| string | no | now | End of time range |
| number | no | 100 | Max entries (max 5000) |
| string | no | backward |
|
query
Execute a LogQL instant query for point-in-time evaluation.
Parameter | Type | Required | Default | Description |
| string | yes | — | LogQL query expression |
| number | no | 100 | Max entries (max 5000) |
| string | no | now | Evaluation timestamp |
| string | no | backward |
|
labels
List all available label names in Loki.
Parameter | Type | Required | Default | Description |
| string | no | 6 hours ago | Start of time range |
| string | no | now | End of time range |
label_values
List values for a specific label.
Parameter | Type | Required | Default | Description |
| string | yes | — | Label name |
| string | no | 6 hours ago | Start of time range |
| string | no | now | End of time range |
series
Find active log stream series matching a selector.
Parameter | Type | Required | Default | Description |
| string | yes | — | Stream selector (e.g. |
| string | no | 6 hours ago | Start of time range |
| string | no | now | End of time range |
Local Development Stack
A Docker Compose setup is included under deploy/ to spin up a full Loki environment for testing:
Loki — log storage at
http://localhost:3100Grafana — UI at
http://localhost:3000(anonymous admin, Loki pre-configured as datasource)Promtail — collects container logs and ships them to Loki
Log generator — emits structured JSON logs with randomized apps (
nginx,api,gateway,auth,payments), levels, and messages
# Start the stack
docker compose -f deploy/docker-compose.yml up -d
# Use loki-mcp-server against local Loki
LOKI_URL=http://localhost:3100 loki-mcp-server
# Stop the stack
docker compose -f deploy/docker-compose.yml downDevelopment
# Run tests
go test ./...
# Build
go build -o loki-mcp-server ./cmd/loki-mcp-server
# Vet
go vet ./...⭐ If this project is useful for you, please star the repository.
Available Tools
5 toolslabelsARead-onlyIdempotent
List the label names Loki knows about in a time window.
Start here when the log schema is unknown: labels gives the names (app, namespace, level), then label_values gives the values for one of them, and together they let you write a valid selector for query_range. Only labels present on streams that received data inside the window are returned, so widening start/end surfaces more.
Returns the raw Loki JSON response: {"status","data":["label","names"]}. Read-only: it never writes to or mutates Loki.
Inputs: end, start.
label_valuesARead-onlyIdempotent
List the values a single label takes in Loki over a time window.
Use it after labels to fill in a selector: labels says "app" exists, label_values with label="app" says which apps are actually logging, and one of those goes into {app="..."} for query_range. Only values seen inside the window are returned, so widening start/end surfaces more.
Returns the raw Loki JSON response: {"status","data":["value","list"]}. An unknown label name is not an error; it comes back as an empty list. Read-only: it never writes to or mutates Loki.
Inputs: label (required), end, start.
queryARead-onlyIdempotent
Run a LogQL instant query against Loki, evaluating the expression at a single point in time.
Use this for metric expressions (rate, count_over_time, sum by) when one value per series is enough, or for a quick "what is happening right now" check. To read log lines across a time window, use query_range instead. To discover which labels exist before writing a selector, use labels and label_values.
Returns the raw Loki JSON response: {"status","data":{"resultType","result"}}, where resultType is "vector" for metric expressions and "streams" for log selectors. Read-only: it never writes to or mutates Loki.
Inputs: query (required), time, limit, direction.
query_rangeARead-onlyIdempotent
Run a LogQL range query against Loki, returning results across a time window.
This is the tool to reach for when reading logs: searching for errors, tailing a service over the last hour, or graphing a metric expression over time. Use query instead when a single point-in-time value is enough. If the selector is unknown, call labels and label_values first.
Returns the raw Loki JSON response: {"status","data":{"resultType","result"}}, where resultType is "streams" for log selectors and "matrix" for metric expressions. Loki truncates at limit entries, so a full result set may mean logs were cut off; narrow start/end or tighten the selector rather than raising limit. Read-only: it never writes to or mutates Loki.
Inputs: query (required), end, limit, start, +1 more.
seriesARead-onlyIdempotent
List the log streams matching a selector, as complete label sets.
Use it to see which concrete streams a selector actually covers and what other labels they carry: {app="nginx"} may expand to one series per pod, region or level. That answers "does this selector match anything" and "how many streams am I about to read" without fetching log lines. For the lines themselves, use query_range; for label names and values in isolation, use labels and label_values.
Returns the raw Loki JSON response: {"status","data":[{"label":"value"}]}, one object per stream. A selector matching nothing comes back as an empty list. Read-only: it never writes to or mutates Loki.
Inputs: match (required), end, start.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 5 tools
Each tool serves a distinct purpose: labels lists names, label_values lists values for a given label, query runs instant queries, query_range runs range queries, and series lists matching streams. No overlap or ambiguity between them.
All tool names are in snake_case and follow a clear pattern: label_values, labels, query, query_range, series. They are consistent in style and predictable, with multi-word names clearly separated by underscores.
With 5 tools, the server is well-scoped for a log querying service. Each tool is essential and there are no redundant or excessive entries.
The tool surface covers the full read-only workflow for Loki: discovering labels, discovering label values, running instant queries, running range queries, and checking stream coverage. No obvious gaps for typical use cases.
Maintenance
Related MCP Connectors
An MCP server giving access to Grafana dashboards, data and more.
Open-source Zapier/n8n alternative as an MCP server: agents build, run and debug your workflows.
An MCP server that let you interact with Cycloid.io Internal Development Portal and Platform
An MCP server that provides read access to your cloud storage providers, bank accounts and more.
Related MCP Servers
- AlicenseDqualityDmaintenanceAn MCP interface that allows AI assistants to query and analyze Grafana Loki logs using LogQL, with support for authentication and various output formats.31,511 npm6MIT
- AlicenseNot gradedqualityDmaintenanceAn MCP server that enables querying logs and metrics from Graylog, Prometheus, and InfluxDB 2.x. It provides tools for executing Lucene log searches, PromQL queries, and Flux queries directly within MCP-compatible clients.MIT
- AlicenseNot gradedqualityBmaintenanceThis MCP server enables natural-language querying of Grafana logs by automatically detecting log sources and service labels. It provides read-only access to log data with intelligent caching for efficient repeat queries.98 npmMIT
- FlicenseNot gradedqualityDmaintenanceAn MCP server that enables AI assistants to query and analyze logs from Grafana Loki using LogQL, supporting label discovery and keyword search.4-