MCP Server for Grafana Loki log exploration, LogQL queries, and schema discovery
272
An MCP server that gives AI assistants the power to explore, query, and analyze logs from Grafana Loki — with LogQL query construction, log structure discovery, cardinality-aware schema exploration, and production-safe query guardrails.
rate(), count_over_time(), avg_over_time()) handled by a single tool with automatic result formatting.X-Scope-OrgID header injection for multi-tenant Loki deployments.This Docker image runs an MCP server that connects to your Grafana Loki backend. AI assistants (Claude, Cline, Cursor, or any MCP client) connect to the server over HTTP, SSE, or stdio.
docker run --rm -it \
-p 8770:8770 \
-e LOKI_URL=http://host.docker.internal:3100 \
-e MCP_TRANSPORT=http \
talkopsai/loki-mcp-server:latest
The server is now listening on http://localhost:8770/mcp.
Then configure your MCP client to connect:
{
"mcpServers": {
"loki": {
"url": "http://localhost:8770/mcp",
"description": "MCP Server for Grafana Loki log observability"
}
}
}
For multi-tenant Loki deployments, inject the tenant org ID:
docker run --rm -it \
-p 8770:8770 \
-e LOKI_URL=http://host.docker.internal:3100 \
-e LOKI_ORG_ID=my-tenant \
-e MCP_TRANSPORT=http \
talkopsai/loki-mcp-server:latest
To use this image over stdio transport directly inside Claude Desktop:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"loki-mcp-server": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-e", "LOKI_URL=http://host.docker.internal:3100",
"-e", "MCP_TRANSPORT=stdio",
"-e", "MCP_LOG_LEVEL=INFO",
"talkopsai/loki-mcp-server:latest"
]
}
}
}
For authenticated or multi-tenant backends, add additional -e args:
{
"mcpServers": {
"loki-mcp-server": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-e", "LOKI_URL=https://loki.example.com",
"-e", "LOKI_AUTH_TOKEN=your-bearer-token",
"-e", "LOKI_ORG_ID=my-tenant",
"-e", "MCP_TRANSPORT=stdio",
"-e", "MCP_LOG_LEVEL=INFO",
"talkopsai/loki-mcp-server:latest"
]
}
}
}
| Variable | Default | Description |
|---|---|---|
MCP_TRANSPORT | stdio | Transport protocol: http, sse, streamable-http, or stdio |
MCP_HOST | 0.0.0.0 | Host interface to bind to |
MCP_PORT | 8770 | Port for HTTP server |
MCP_PATH | /mcp | MCP endpoint path |
MCP_LOG_LEVEL | INFO | Log level: DEBUG, INFO, WARNING, ERROR |
MCP_LOG_FORMAT | json | Log format: json or text |
MCP_HTTP_TIMEOUT | 300 | HTTP server timeout (seconds) |
| Variable | Default | Description |
|---|---|---|
LOKI_URL | http://loki:3100 | Loki HTTP API base URL |
LOKI_TIMEOUT | 30 | HTTP timeout per request (seconds) |
LOKI_VERIFY_SSL | true | Verify SSL certificates |
| Variable | Default | Description |
|---|---|---|
LOKI_AUTH_TOKEN | (empty) | Bearer token for Loki authentication |
LOKI_BASIC_AUTH_USER | (empty) | Basic auth username |
LOKI_BASIC_AUTH_PASSWORD | (empty) | Basic auth password |
LOKI_ORG_ID | (empty) | Multi-tenant org ID (X-Scope-OrgID header) |
| Variable | Default | Description |
|---|---|---|
LOKI_MAX_QUERY_BYTES | 5000000000 (5 GB) | Maximum bytes a query may scan before rejection |
LOKI_MAX_TIME_WINDOW_HOURS | 336 (14 days) | Maximum query time range in hours |
LOKI_MAX_LOG_LIMIT | 5000 | Maximum log lines per query |
LOKI_HIGH_CARDINALITY_THRESHOLD | 10000 | Warn when a label exceeds this many unique values |
| Tool | Description |
|---|---|
get_cluster_labels | Discover global label taxonomy — always call first before writing any LogQL |
get_label_values | Enumerate concrete values for a label with optional scope queries |
get_active_series | Validate selectors against active streams with per-label cardinality |
| Tool | Description |
|---|---|
get_log_patterns | Detect structural patterns and auto-suggest parser pipelines |
get_detected_fields | Discover JSON/logfmt keys, types, cardinality, and required parsers (Loki 3.0+) |
| Tool | Description |
|---|---|
get_query_stats | Preflight a selector to estimate query cost before execution |
| Tool | Description |
|---|---|
execute_logql_instant | Point-in-time LogQL query for scalar answers (count, rate, avg) |
execute_logql_query | Primary query tool. Execute LogQL range queries for log lines or metric time-series with guardrails |
loki_query_a2ui | Execute LogQL and return data formatted for A2UI interactive log tables |
| Resource | Description |
|---|---|
loki://system/health | Loki reachability, readiness status, and label count |
loki://schema/labels | All available label names |
loki://config/guardrails | Current safety thresholds |
loki://config/backends | Configured backend connection details |
loki://reference/logql | LogQL syntax guide and examples |
loki://reference/best-practices | Cardinality rules, parser selection, structured metadata |
loki://reference/query-templates | Common incident, debug, audit, and performance query patterns |
loki://reference/label-governance | Label naming conventions and cardinality governance |
LOKI_ORG_ID is correctly scoped to prevent cross-tenant data leakage.LOKI_AUTH_TOKEN and LOKI_BASIC_AUTH_PASSWORD are included in every request to the backend — treat them as secrets.services:
loki-mcp-server:
image: talkopsai/loki-mcp-server:latest
ports:
- "8770:8770"
environment:
- LOKI_URL=http://loki:3100
- MCP_TRANSPORT=http
- MCP_LOG_LEVEL=INFO
depends_on:
- loki
loki:
image: grafana/loki:latest
ports:
- "3100:3100"
command: -config.file=/etc/loki/local-config.yaml
If you find this MCP server useful, consider leaving a ⭐ on the GitHub repository!
Content type
Image
Digest
sha256:fcdc27e5b…
Size
71.6 MB
Last updated
4 months ago
docker pull talkopsai/loki-mcp-server