Skip to main content
Ecosystem & Marketplaces›Open-Source MCP Servers (10)›Loki MCP Server

Loki MCP server

The Loki MCP Server is a Model Context Protocol server for querying and analyzing Grafana Loki logs safely. It exposes 9 discovery-first tools, 8 loki:// resources, and 5 guided triage prompts that require AI agents to discover valid stream labels, inspect structured JSON/logfmt fields, and check /query_stats byte-scan costs before executing LogQL queries.

Core capabilities​

Capability DomainWhat the Server Provides
Discovery-First Label TaxonomyInspects global label keys (get_cluster_labels), enumerates valid label values (get_label_values), and verifies active stream series (get_active_series) so agents never hallucinate non-existent stream selectors.
Log Pattern & Field AnalysisExtracts recurring log templates via Loki's pattern API (get_log_patterns) and discovers structured JSON/logfmt field names, types, and recommended parser stages (`
Preflight Query Cost GuardrailsCalls /loki/api/v1/index/stats (get_query_stats) to estimate streams, chunks, and bytes touched prior to execution—rejecting queries that exceed LOKI_MAX_QUERY_BYTES (5 GB default).
Unified LogQL ExecutionRuns instant scalar aggregations (execute_logql_instant), range log/metric queries (execute_logql_query), and A2UI table formatting (loki_query_a2ui).

Position in the TalkOps observability stack​

Architecture​

Tool summary​

ToolCategoryDescription
get_cluster_labelsDiscoveryList all indexed label names in the Loki cluster before constructing a query
get_label_valuesDiscoveryEnumerate valid values (namespace, app, pod) for a specific label key
get_active_seriesDiscoveryVerify matching log streams and inspect per-label cardinality
get_log_patternsStructureExtract recurring structural log shapes and suggested parser expressions
get_detected_fieldsStructureDiscover JSON/logfmt field names, data types, and cardinality estimates
get_query_statsSafetyEstimate streams, chunks, entries, and bytes scanned before executing a query
execute_logql_instantExecutionExecute point-in-time LogQL metric aggregations and scalar lookups
execute_logql_queryExecutionExecute range queries returning log lines or metric time series
loki_query_a2uiUIStream structured LogQL results into interactive A2UI log tables

Quickstart​

1
Start the Loki MCP Server container

Point LOKI_URL to your Grafana Loki gateway or querier endpoint:

docker run --rm -it \
-p 8770:8770 \
-e MCP_TRANSPORT=http \
-e LOKI_URL=http://loki.monitoring:3100 \
talkopsai/loki-mcp-server:latest
2
Connect your MCP client

Register the HTTP endpoint or launch via uvx over stdio:

mcp.json
{
"mcpServers": {
"loki": {
"url": "http://localhost:8770/mcp",
"description": "TalkOps Loki MCP Server for Log Observability"
}
}
}

Security and cost guardrails​

  • Byte-scan enforcement: LOKI_MAX_QUERY_BYTES (5 GB default), LOKI_MAX_QUERY_LOOKBACK_DAYS (14 days), and LOKI_MAX_LIMIT (5000 lines) prevent unbounded full-cluster scans from overwhelming Loki queriers or LLM context windows.
  • Tenant isolation: Set LOKI_ORG_ID in multi-tenant Loki clusters to inject the X-Scope-OrgID header on every request automatically.