Featured

Deploy OpenClaw in 60 seconds β€” 20% off logoDeploy OpenClaw in 60 seconds β€” 20% off

Launch OpenClaw on Hostinger in about 60 seconds and keep your agent live 24/7. Our referral link gives you 20% off, no coupon code needed.

Launch on Hostinger β†’
Run your Hermes agent on Hostinger, fully managed logoRun your Hermes agent on Hostinger, fully managed

Launch Hermes on Hostinger in one click, fully managed, no VPS knowledge needed. Use code ZACAARON10 for 10% off.

Launch on Hostinger β†’
Crawl and scrape any site into clean data, 10% off logoCrawl and scrape any site into clean data, 10% off

Firecrawl crawls and scrapes any site into clean markdown for your agent. Get 1,000 free credits, and new users get 10% off their first purchase.

Try Firecrawl free β†’
Your own AI agent, running 24/7 with QwikClaw logoYour own AI agent, running 24/7 with QwikClaw

QwikClaw sets up and runs an always-on OpenClaw agent for you. One click, no config files, no server setup.

Deploy now β†’
One API to scrape, enrich, and extract the internet. logoOne API to scrape, enrich, and extract the internet.

Context.dev gives your agents a single API to scrape, enrich, and extract live web data β€” no proxies, no parsers, no maintenance.

Start building free β†’
SetupClaw: done-for-you OpenClaw for founders & exec teams logoSetupClaw: done-for-you OpenClaw for founders & exec teams

White-glove OpenClaw for founders and exec teams (4–50+ employees): we install, harden, integrate your tools, and maintain it β€” secured from day one.

Get it set up for you β†’
SEO data APIs for your agent, $1 free credit logoSEO data APIs for your agent, $1 free credit

DataForSEO gives your agent live access to SERP results, keyword data, backlinks, and on-page SEO data through one API. New accounts get a $1 credit, good for up to 20,000 keyword or backlink lookups.

Try DataForSEO free β†’
Reach 47,000+ AI builders

A flat monthly placement in front of developers actively installing AI tools. No lock-in, cancel anytime.

Advertise here β†’

Works with

Claude CodeClaude DesktopCursorVS CodeClineCodex CLIOpenClaw+ any MCP client

Install to Claude Code

This server doesn't publish a one-line install command. Follow the setup in the source repository.

Summary

incu6us/loki-mcp-server MCP server](https://glama.ai/mcp/servers/incu6us/loki-mcp-server/badges/score.svg)](https://glama.ai/mcp/servers/incu6us/loki-mcp-server) 🏎️ 🏠 🍎 πŸͺŸ 🐧 - An MCP server for querying Grafana Loki directly with a discovery-first...

README.md

Loki MCP Server

![CI](https://github.com/incu6us/loki-mcp-server/actions/workflows/ci.yml) ![Release](https://github.com/incu6us/loki-mcp-server/actions/workflows/release.yml) ![codecov](https://codecov.io/gh/incu6us/loki-mcp-server) ![Go Report Card](https://goreportcard.com/report/github.com/incu6us/loki-mcp-server) ![License: MIT](https://opensource.org/licenses/MIT) !Stars !MCP

![loki-mcp-server MCP server](https://glama.ai/mcp/servers/incu6us/loki-mcp-server)

Query Grafana Loki logs directly from AI agents using the Model Context Protocol (MCP).

Built in Go. Enables AI-powered log analysis using LogQL.

Supports integration with:

  • Claude Desktop
  • AI agent frameworks
  • automation tools
  • DevOps workflows

Motivation

The official grafana/loki-mcp exposes a single loki_query tool, which means the LLM must already know valid label names and values before it can build a query. This project takes a different approach by providing 5 granular tools β€” labels, label_values, and series let the LLM discover what's available in Loki first, then construct precise query_range or query calls. The result is more accurate log retrieval with fewer wasted round-trips.

Additionally, this server enforces strict input validation (limit caps, direction validation, label name format checks, mutually exclusive auth) to surface errors early instead of forwarding bad requests to Loki.

Features

  • query_range β€” Execute LogQL range queries to fetch logs over a time window
  • query β€” Execute LogQL instant queries for point-in-time evaluation
  • labels β€” List all available label names
  • label_values β€” List values for a specific label
  • series β€” Find active log stream series matching a selector

Installation

Homebrew

brew install incu6us/tap/loki-mcp-server

Go install

go install github.com/incu6us/loki-mcp-server/cmd/loki-mcp-server@latest

Or build from source:

git clone https://github.com/incu6us/loki-mcp-server.git
cd loki-mcp
go build -o loki-mcp-server ./cmd/loki-mcp-server

Configuration

The server is configured entirely via environment variables, injected by the MCP client.

| Variable | Required | Default | Description | |----------|----------|---------|-------------| | LOKI_URL | yes | β€” | Base URL of the Loki instance | | LOKI_USERNAME | no | β€” | Basic auth username | | LOKI_PASSWORD | no | β€” | Basic auth password | | LOKI_BEARER_TOKEN | no | β€” | Bearer token authentication | | LOKI_TLS_SKIP_VERIFY | no | false | Skip TLS certificate verification | | LOKI_TENANT_ID | no | β€” | X-Scope-OrgID header for multi-tenant deployments | | LOKI_HTTP_TIMEOUT | no | 30s | HTTP request timeout (Go duration, e.g. 10s, 1m) |

Note: Basic auth (LOKI_USERNAME/LOKI_PASSWORD) and bearer token (LOKI_BEARER_TOKEN) are mutually exclusive.

Usage with Claude Code

Add to your Claude Code MCP configuration (~/.claude.json):

{
  "mcpServers": {
    "loki-mcp-server": {
      "type": "stdio",
      "command": "/path/to/loki-mcp-server",
      "args": [],
      "env": {
        "LOKI_URL": "http://loki:3100",
        "LOKI_USERNAME": "admin",
        "LOKI_PASSWORD": "secret"
      }
    }
  }
}

Usage with Claude Desktop

Add to your Claude Desktop config (~/Library/Application Support/Claude/claude_desktop_config.json on macOS):

{
  "mcpServers": {
    "loki-mcp-server": {
      "type": "stdio",
      "command": "/path/to/loki-mcp-server",
      "args": [],
      "env": {
        "LOKI_URL": "http://loki:3100",
        "LOKI_USERNAME": "admin",
        "LOKI_PASSWORD": "secret"
      }
    }
  }
}

Tools

query_range

Execute a LogQL range query against Loki to fetch logs over a time window.

| Parameter | Type | Required | Default | Description | |-----------|------|----------|---------|-------------| | query | string | yes | β€” | LogQL query expression | | start | string | no | 1 hour ago | Start of time range (RFC3339 or Unix nano) | | end | string | no | now | End of time range | | limit | number | no | 100 | Max entries (max 5000) | | direction | string | no | backward | forward or backward |

query

Execute a LogQL instant query for point-in-time evaluation.

| Parameter | Type | Required | Default | Description | |-----------|------|----------|---------|-------------| | query | string | yes | β€” | LogQL query expression | | limit | number | no | 100 | Max entries (max 5000) | | time | string | no | now | Evaluation timestamp | | direction | string | no | backward | forward or backward |

labels

List all available label names in Loki.

| Parameter | Type | Required | Default | Description | |-----------|------|----------|---------|-------------| | start | string | no | 6 hours ago | Start of time range | | end | string | no | now | End of time range |

label_values

List values for a specific label.

| Parameter | Type | Required | Default | Description | |-----------|------|----------|---------|-------------| | label | string | yes | β€” | Label name | | start | string | no | 6 hours ago | Start of time range | | end | string | no | now | End of time range |

series

Find active log stream series matching a selector.

| Parameter | Type | Required | Default | Description | |-----------|------|----------|---------|-------------| | match | string | yes | β€” | Stream selector (e.g. {app="nginx"}) | | start | string | no | 6 hours ago | Start of time range | | end | string | no | now | End of time range |

Local Development Stack

A Docker Compose setup is included under deploy/ to spin up a full Loki environment for testing:

  • Loki β€” log storage at http://localhost:3100
  • Grafana β€” UI at http://localhost:3000 (anonymous admin, Loki pre-configured as datasource)
  • Promtail β€” collects container logs and ships them to Loki
  • Log generator β€” emits structured JSON logs with randomized apps (nginx, api, gateway, auth, payments), levels, and messages
# Start the stack
docker compose -f deploy/docker-compose.yml up -d

# Use loki-mcp-server against local Loki
LOKI_URL=http://localhost:3100 loki-mcp-server

# Stop the stack
docker compose -f deploy/docker-compose.yml down

Development

# Run tests
go test ./...

# Build
go build -o loki-mcp-server ./cmd/loki-mcp-server

# Vet
go vet ./...

⭐ If this project is useful for you, please star the repository.

See related servers & alternatives β†’

Related MCP servers

Browse all β†’

Related guides

Hand-picked reading to help you choose and use Observability servers.