Loki MCP Server

1

Add it to Claude Code

Run this in a terminal.

Run in terminal
claude mcp add -e "LOKI_URL=${LOKI_URL}" loki-mcp-server -- uv run server.py
Required:LOKI_URL
README.md

An MCP server for semantic log querying via Loki.

Loki MCP Server

An MCP (Model Context Protocol) server for semantic log querying via Loki. Designed to help AI models answer natural language questions about your cluster logs.

Features

  • Error Summary: Aggregate errors across your cluster with breakdowns by type
  • Pod Restart Detection: Find crashing/restarting pods
  • Log Search: Regex-based log search across your cluster
  • Namespace/Pod Discovery: List available namespaces and query specific pods
  • Semantic Tool Design: Tool names and parameters match natural language questions

Tools

`get_error_summary`

Get a summary of errors happening in your cluster.

  • namespace: Filter to specific namespace (empty = all)
  • hours: Look back this many hours (default: 1)

`find_pod_restarts`

Find pods that have restarted or crashed recently.

  • namespace: Filter to specific namespace (empty = all)
  • hours: Look back this many hours (default: 1)

`search_logs`

Search logs with a regex pattern.

  • query: Regex pattern to search for
  • namespace: Filter to specific namespace (empty = all)
  • hours: Look back this many hours (default: 1)
  • limit: Maximum log lines to return (default: 100)

`list_namespaces`

List all namespaces that have logs in Loki.

`get_pod_logs`

Get logs for a specific pod.

  • pod_name: Pod name (supports wildcards like ollama*)
  • namespace: Namespace of the pod (empty = search all)
  • hours: Look back this many hours (default: 1)
  • limit: Maximum log lines to return (default: 100)

Development

# Install dependencies
uv sync

# Run the server
uv run server.py

The server exposes FastMCP over streamable HTTP at /mcp (default port 8000).

Deployment (In-Cluster)

Add to your local-k8s-apps Helm values with:

  • Deployment with the MCP server
  • Exposed via HTTP on port 8000
  • Environment variable: LOKI_URL pointing to Loki service

The Ollama MCP bridge will load this server's tools and expose them to the model.

Tools (5)

get_error_summaryGet a summary of errors happening in your cluster.
find_pod_restartsFind pods that have restarted or crashed recently.
search_logsSearch logs with a regex pattern.
list_namespacesList all namespaces that have logs in Loki.
get_pod_logsGet logs for a specific pod.

Environment Variables

LOKI_URLrequiredThe URL pointing to the Loki service

Configuration

claude_desktop_config.json
{"mcpServers": {"loki": {"command": "uv", "args": ["run", "server.py"], "env": {"LOKI_URL": "http://your-loki-url:3100"}}}}

Try it

Find all pods that have restarted in the production namespace in the last 2 hours.
Give me a summary of errors occurring across the entire cluster.
Search for 'connection refused' errors in the logs for the last 6 hours.
List all namespaces currently available in Loki.
Show me the last 100 lines of logs for the pod named ollama-server.

Frequently Asked Questions

What are the key features of Loki MCP Server?

Aggregate errors across your cluster with breakdowns by type. Find crashing or restarting pods. Regex-based log search across your cluster. List available namespaces and query specific pods.

What can I use Loki MCP Server for?

Automated troubleshooting of crashing Kubernetes pods. Aggregating cluster-wide error reports for incident response. Searching through distributed logs using natural language queries. Monitoring application health across multiple namespaces.

How do I install Loki MCP Server?

Install Loki MCP Server by running: uv sync && uv run server.py

What MCP clients work with Loki MCP Server?

Loki MCP Server works with any MCP-compatible client including Claude Desktop, Claude Code, Cursor, and other editors with MCP support.

Turn this server into reusable context

Keep Loki MCP Server docs, env vars, and workflow notes in Conare so your agent carries them across sessions.

Need the old visual installer? Open Conare IDE.
Open Conare