Labsco
MCP SERVER

Loki MCP Server

by gigapipehq

One tool, one job: run a LogQL query against Grafana Loki from a chat, with the server URL, tenant and credentials pre-set in the environment.

Observability, Monitoring & Incident Response
Summary
Set the connection once, then just ask for logs.

The value is not the tool count — it is that URL, tenant and credentials live in the environment, so "find error logs from the last hour for job varlogs" becomes one call with no configuration in the prompt. The org argument mapping onto X-Scope-OrgID is what makes it workable against a multi-tenant Loki.

What it is

A small Go MCP server that fronts Grafana Loki. It exposes a single query tool and handles the connection details — endpoint, tenant header, authentication — so the assistant only supplies LogQL and a time range.

What you get
  • `loki_query` — takes a LogQL query string and optionally a Loki URL, start and end times, a result limit and an organization ID
  • Sensible defaults on the optional arguments: the last hour, and a limit that keeps a broad query from flooding the reply
  • Multi-tenant support — the org argument is sent as the X-Scope-OrgID header, so one server reaches several tenants
  • Authentication by basic credentials or bearer token, read from the environment when the call does not supply them
  • Two transports: stdio for local clients, or an HTTP server exposing /sse and /mcp for tools like n8n
Requirements

A reachable Loki instance and Go 1.16 or higher to build (`go build ./cmd/server`), or the provided Docker image. Defaults come from environment variables — LOKI_URL, LOKI_ORG_ID, and either LOKI_USERNAME with LOKI_PASSWORD or LOKI_TOKEN. In HTTP mode the port defaults to 8080 and is overridden with SSE_PORT. A docker-compose setup with Loki, Grafana and a log generator is included for trying it locally. MIT licensed.

Setup effort

Build from source — clone the repository and build it, then point your client at the binary