Grafana Loki

v1.0.0Monitoring & Observabilitystable

An MCP ( Model Context Protocol ) Server for Grafana Loki

agentic-aiagentic-workflowgolanggrafanaloki
Share:
142
Stars
0
Downloads
0
Weekly
0/5

What is Grafana Loki?

Grafana Loki is a Model Context Protocol (MCP) server that allows AI assistants like Claude, Cursor, and VS Code to mcp ( model context protocol ) server for grafana loki

An MCP ( Model Context Protocol ) Server for Grafana Loki

This server falls under the Monitoring & Observability category on MCPgee, the world's largest MCP server directory with 33,000+ servers.

Features

  • An MCP ( Model Context Protocol ) Server for Grafana Loki

Use Cases

An MCP ( Model Context Protocol ) Server for Grafana Loki
grafana

Maintainer

LicenseMIT
Languagego
Versionv1.0.0
UpdatedMay 19, 2026
Statushealthy
Maintenanceactive

Works with

ClaudeOpenAIwindowsmacoslinux

Installation

Manual Installation

npx loki

Configuration

Configuration Details

Config File

claude_desktop_config.json

Performance

Response Metrics

Response Time< 200ms
ThroughputMedium

Resource Usage

Memory UsageLow
CPU UsageLow

How to Set Up and Use Grafana Loki

The Grafana Loki MCP Server is a Go-based server implementation of the Model Context Protocol that gives AI assistants direct access to Grafana Loki log aggregation systems. It exposes a loki_query tool that accepts LogQL query strings along with optional time ranges, result limits, and organization IDs, allowing an AI to search and analyze logs without leaving the chat interface. Teams running Loki for log aggregation can use this server to let AI assistants diagnose incidents, analyze error patterns, and answer questions about application behavior in real time.

Prerequisites

  • Go 1.16 or higher installed (for building from source)
  • A running Grafana Loki instance accessible via HTTP (local or remote)
  • The Loki URL, and optionally authentication credentials (username/password or bearer token)
  • An MCP-compatible client such as Claude Desktop
  • Docker (optional, for the bundled Docker Compose local test environment)
1

Clone the repository

Download the loki-mcp source code from the Grafana GitHub organization.

git clone https://github.com/grafana/loki-mcp.git
cd loki-mcp
2

Build the server binary

Compile the Go server into a single binary.

go build -o loki-mcp-server ./cmd/server
3

Set environment variables for Loki connection

Configure the Loki endpoint and optional authentication via environment variables. These are used as defaults when the tool is called without explicit parameters.

export LOKI_URL=http://localhost:3100
export LOKI_ORG_ID=tenant-123        # optional, for multi-tenant Loki
export LOKI_TOKEN=your-bearer-token  # optional, for authenticated Loki
# OR username/password auth:
# export LOKI_USERNAME=admin
# export LOKI_PASSWORD=password
4

Run the MCP server

Start the server. It communicates over stdin/stdout following the MCP protocol and is suitable for use with Claude Desktop and other MCP clients.

./loki-mcp-server
# or run directly without building:
go run ./cmd/server
5

Configure your MCP client

Add the Loki MCP server to your MCP client configuration, passing the LOKI_URL and any auth credentials as environment variables.

Grafana Loki Examples

Client configuration

Claude Desktop config that launches the compiled loki-mcp-server binary with Loki connection details as environment variables.

{
  "mcpServers": {
    "loki": {
      "command": "/path/to/loki-mcp-server",
      "args": [],
      "env": {
        "LOKI_URL": "http://localhost:3100",
        "LOKI_TOKEN": "your-bearer-token"
      }
    }
  }
}

Prompts to try

Example prompts using the loki_query tool once the server is connected.

- "Query Loki for all error logs from the last hour using LogQL: {job=\"myapp\"} |= \"ERROR\""
- "Show me the last 50 log lines from the varlogs job in the past 30 minutes"
- "Find log lines containing 'timeout' from the api-gateway service in the last 6 hours"

Troubleshooting Grafana Loki

loki_query returns 'connection refused' or network errors

Verify LOKI_URL is correct and the Loki instance is reachable from the machine running the MCP server. Test with 'curl http://localhost:3100/ready' — a healthy Loki returns 'ready'.

Queries return empty results even for active log streams

Check that your LogQL selector matches existing labels. Use '{job=~".+"}' to list all streams. Also verify the start/end time range; the default is the last 1 hour, so older logs require an explicit 'start' parameter.

Multi-tenant Loki returns 403 Forbidden

Set LOKI_ORG_ID to the correct tenant ID. The server passes this as the X-Scope-OrgID header. Each tenant's logs are isolated, so using the wrong org ID results in empty or forbidden responses.

Frequently Asked Questions about Grafana Loki

What is Grafana Loki?

Grafana Loki is a Model Context Protocol (MCP) server that mcp ( model context protocol ) server for grafana loki It connects AI assistants to external tools and data sources through a standardized interface.

How do I install Grafana Loki?

Follow the installation instructions on the Grafana Loki GitHub repository. Clone the repo, install dependencies, and add the server config to your AI client.

Which AI clients work with Grafana Loki?

Grafana Loki works with all major MCP-compatible AI clients including Claude Desktop, Claude Code, Cursor, VS Code (GitHub Copilot), Windsurf, and Cline.

Is Grafana Loki free to use?

Yes, Grafana Loki is open source and available under the MIT license. You can use it freely in both personal and commercial projects.

Browse More Monitoring & Observability MCP Servers

Explore all monitoring & observability servers available in the MCPgee directory. Each server includes setup guides for Claude, Cursor, and VS Code.

Quick Config Preview

{ "mcpServers": { "loki": { "command": "npx", "args": ["-y", "loki"] } } }

Add this to your claude_desktop_config.json or .cursor/mcp.json

Read the full setup guide →

Ready to use Grafana Loki?

Browse our complete directory of 33,000+ MCP servers, read setup guides for your editor, and start building with the Model Context Protocol.

33,000+ ServersFree & Open SourceStep-by-Step Guides