Grafana Loki
An MCP ( Model Context Protocol ) Server for Grafana Loki
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
Maintainer
Works with
Installation
Manual Installation
npx lokiConfiguration
Configuration Details
claude_desktop_config.json
Performance
Response Metrics
Resource Usage
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)
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-mcpBuild the server binary
Compile the Go server into a single binary.
go build -o loki-mcp-server ./cmd/serverSet 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=passwordRun 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/serverConfigure 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.
Grafana Loki Alternatives — Similar Monitoring & Observability Servers
Looking for alternatives to Grafana Loki? Here are other popular monitoring & observability servers you can use with Claude, Cursor, and VS Code.
Netdata
★ 78.9kReal-time infrastructure monitoring with metrics, logs, alerts, and ML-based anomaly detection.
Kubeshark
★ 11.9keBPF-powered network observability for Kubernetes. Indexes L4/L7 traffic with full K8s context, decrypts TLS without keys. Queryable by AI agents via MCP and humans via dashboard.
Mission Control
★ 4.9kSelf-hosted AI agent orchestration platform: dispatch tasks, run multi-agent workflows, monitor spend, and govern operations from one mission control dashboard.
Grafana
★ 3.0kThis MCP server enables natural-language querying of Grafana logs by automatically detecting log sources and service labels. It provides read-only access to log data with intelligent caching for efficient repeat queries.
Sentrux
★ 2.4kReal-time architectural sensor that helps AI agents close the feedback loop, enabling recursive self-improvement of code quality. Pure Rust.
OpenInference
★ 986OpenTelemetry Instrumentation for AI Observability
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.
Set Up Grafana Loki in Your Editor
Choose your AI client for step-by-step setup instructions.
Quick Config Preview
Add this to your claude_desktop_config.json or .cursor/mcp.json
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.