mcp-loki
Provides read-only tools for querying and exploring Grafana Loki through its HTTP API, including LogQL log and metric queries, log context, labels, series, detected fields, volume, stats, patterns, and ruler rules.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
@mgcrea/mcp-loki
A Model Context Protocol server for the Grafana Loki HTTP API: query logs and LogQL metrics, explore labels, fields, volume and patterns, with answers shaped to fit a context window.
The server is read-only. It sends only reads: Loki's push, delete-request and ruler-write
endpoints are not wrapped, and the loki_request escape hatch only sends GET.
Features
Logs merged across streams, in time order. Labels every stream shares come once as
common_labels. Each line keeps only the labels that tell its stream apart, plusleveland structured metadata. Timestamps are exact RFC3339 nanoseconds, so thenextcursor andloki_get_log_contextanchors round-trip without loss.Cheap before expensive.
loki_get_statsandloki_get_volumeanswer from the index without reading a line.loki_list_patternssummarizes what a service logs as templates.loki_query_metriccounts and ranks without returning lines.Long lines are cut at
max_line_chars(some services log 300 KB lines), ANSI colour codes are stripped, and the Kubernetesfilenamelabel is hidden by default.Errors carry a remedy. Loki answers a rejected query with plain text. The common ones (empty-compatible matchers, parse errors, range and series limits, timeouts) come back with what to change.
Identity and limits up front.
loki_auth_statusnames the tenant, the version, retention, max query length, max lines and series per query, and whether volume and patterns are enabled. Every data answer carriestenant.
Related MCP server: LGTM MCP Server
Configure
Variable | Required | Description |
| yes | Loki base URL (gateway, query-frontend or single binary), with any path prefix. |
| no | Basic auth. Behind the Loki Helm chart's nginx gateway the username is the tenant. |
| no | Basic auth password. |
| no | Bearer token instead of basic auth (Grafana Cloud, an OAuth proxy). |
| no | Sent as |
| no | Extra headers as a JSON object. |
| no | HTTP timeout per request, seconds (default 60). |
| no | Retries for 429 and proxy 502/503 (default 2). A 504 is never retried: on Loki it is a slow query, and a retry triples the load. |
With nothing configured the server still starts and serves loki_auth_status, which says what
to set.
Quick start
pnpm install
pnpm buildThen copy .mcp.json.example to .mcp.json and fill it in.
Tools
Tool | What it does |
| URL, auth, tenant, version and this tenant's limits; setup steps when unconfigured |
| LogQL log query over a range, lines merged across streams, with a |
| The lines just before and after one line, in its own stream |
| LogQL metric query at an instant, ranked largest first |
| LogQL metric query over a range, on a step grid, with per-series stats |
| Stream labels with their cardinality |
| Values of one label, optionally within a selector |
| Streams matching a selector |
| JSON / logfmt / structured-metadata fields in the lines, or one field's values |
| Bytes per namespace / app / stream from the index, largest first |
| Streams, chunks, lines and bytes a selector covers, from the index |
| Line templates with counts, from the pattern ingester |
| The Loki ruler's alerting and recording rules |
| GET any other read endpoint ( |
Develop
pnpm dev # tsdown --watch
pnpm test # vitest
pnpm typecheck
pnpm lint
pnpm formatPublish
pnpm dlx release-it # bump, commit, tag
git push --follow-tags # CI publishes to npm from the tagLicense
MIT
This server cannot be deployed
Maintenance
Related MCP Connectors
Read-only access to Auralogs production logs: search logs, inspect errors, review AI analyses.
Read-only access to a Lumin project's logs, metrics, uptime checks, alerts and infrastructure.
Query OneLens cloud-cost data in natural language: breakdowns, trends, cost centers. Read-only.
Ingest and search LogsLoom logs from coding agents.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables querying and formatting Loki logs from Grafana via the Model Context Protocol. It supports LogQL queries, label retrieval, and provides results in text, JSON, or markdown formats.88 PyPI29MIT
- AlicenseNot gradedqualityCmaintenanceProvides read-only access to Loki, Prometheus, and Tempo APIs, enabling natural language queries for logs, metrics, and traces. Supports multiple instances and authentication via bearer tokens.1MIT
- AlicenseAqualityCmaintenanceEnables read-only querying of Grafana Loki logs through tools like label discovery, LogQL queries, and recent log retrieval, without requiring knowledge of the Loki API.4MIT
- FlicenseNot gradedqualityCmaintenanceEnables read-only querying of a local Grafana Loki instance, providing log search, service listing, and health check capabilities.-