Loki

Loki

Golang based MCP Server to query logs from Grafana Loki.

55
Stars
10
Forks
6
Releases

Overview

The Loki MCP Server is a Go-based implementation of the Model Context Protocol (MCP) that integrates Grafana Loki for log querying. It exposes a dedicated Loki Query Tool (loki_query) which requires a LogQL query string and supports optional parameters such as URL (Loki endpoint), start and end times, a result limit, and an org identifier sent via the X-Scope-OrgID header. The server supports two communication modes: traditional MCP over stdin/stdout and an HTTP server that streams events using Server-Sent Events (SSE), enabling real-time integration with tools like n8n. In HTTP mode, endpoints include an SSE endpoint at /sse and an MCP endpoint at /mcp, with the SSE port configurable via the SSE_PORT environment variable (default 8080). Docker and Docker Compose support allow easy local deployment, including a complete Loki testing environment with Loki, Grafana, a log generator, and the Loki MCP server. The MCP server can be configured via environment variables (LOKI_URL, LOKI_ORG_ID, LOKI_USERNAME, LOKI_PASSWORD, LOKI_TOKEN) for default Loki connections, along with a security note about credentials. The project also provides a test client and integration guidance for Claude Desktop and Cursor, emphasizing a modular architecture with separate server, client, handlers, and models.

Details

Owner
scottlepp
Language
Go
License
Updated
2025-12-07

Features

Loki Query Tool (loki_query)

A dedicated MCP Loki tool that queries Grafana Loki log data. Requires a query parameter; supports optional url, start, end, limit, and org (X-Scope-OrgID) header.

MCP and SSE Communication

Supports MCP messaging over stdin/stdout and an HTTP SSE server for real-time streaming to MCP clients like n8n.

HTTP Endpoints (SSE and MCP)

When in HTTP mode, exposes SSE endpoint at /sse and MCP endpoint at /mcp; SSE_PORT configures the port (default 8080).

Docker & Docker Compose Support

Build and run the Loki MCP Server in Docker; includes docker build/run commands and Docker Compose support for orchestration.

Local Loki Testing Environment

Complete Docker Compose setup to run Loki, Grafana, a log generator, and the Loki MCP server for local end-to-end testing; includes test scripts.

Loki Connection Environment Variables

Supports LOKI_URL, LOKI_ORG_ID, LOKI_USERNAME, LOKI_PASSWORD, LOKI_TOKEN for default Loki configuration; notes on credential security.

Claude Desktop & Cursor Integration

Guides for integrating with Claude Desktop and Cursor, including configuration options and workflows for using the Loki MCP server with these tools.

Audience

DevelopersDevelopers building MCP clients to query Grafana Loki logs via MCP.
DevOpsOps teams testing Loki integration and log queries in Dockerized environments.
AI/NLP IntegrationsIntegrators using Claude Desktop or n8n to orchestrate Loki queries through MCP.

Tags

MCPGrafana LokiGoLoki QuerySSEDockerClaude DesktopCursor