Grafana Loki MCP Server & Agent Plugin
Production-ready Agent Plugin (v1.0.0) and FastMCP Execution Server for Grafana Loki 3.x and the Kubernetes Loki Operator (loki.grafana.com/v1).
Following the TalkOps Skill & Execution Layer Separation architecture:
- Procedural Intelligence (
skills/): 6 modular Agent Skills containing progressive-disclosure SOPs (SKILL.md$\le 250$ lines), deep domain references (references/*.md), and deterministic local Python CLI helpers (scripts/*.py). - Execution Plane (
loki_mcp_server/): 18 bounded, type-annotated MCP tools across 7 selectable toolsets + 9 liveloki://state resources, with read-only defaults (MCP_ALLOW_WRITE=false), mandatorydry_run=Truepreviews, and interactivectx.elicit()/confirm=Truemutation gates.
Let your AI assistant search and understand your logs in Grafana Loki: discover what's in your logs, write LogQL, summarize errors for a service, compare before and after a release, and follow a request across services.
What you get
- 18 MCP tools (14 read-only) that work against your live Grafana Loki setup
- 9 resources your assistant can read for context, under
loki:// - 6 Agent Skills: step-by-step playbooks that teach your assistant how to use the tools well
- Safe by default: only read-only tools are loaded until you turn on writes, and changes are previewed or confirmed before they happen
Quick start
You'll need:
- Python 3.12+ and uv, or Docker
- A Loki URL
- Optional: Kubernetes access to manage Loki Operator resources
1. Add the server to your MCP client. For Claude Desktop, Cursor, Windsurf, and most other clients, add this to your MCP config file:
{
"mcpServers": {
"loki": {
"command": "uvx",
"args": [
"--from",
"talkops-loki-mcp-server",
"loki-mcp-server"
],
"env": {
"LOKI_URL": "http://localhost:3100"
}
}
}
}
Using Claude Code? Run this instead:
claude mcp add loki -e LOKI_URL=http://localhost:3100 -- uvx --from talkops-loki-mcp-server loki-mcp-server
uvx downloads talkops-loki-mcp-server from PyPI and runs it, so there's nothing else to install. Prefer a normal install? Run pip install talkops-loki-mcp-server and use loki-mcp-server as the command.
Prefer Docker? Pull talkopsai/loki-mcp-server from Docker Hub—no Python setup needed:
{
"mcpServers": {
"loki": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-e",
"MCP_TRANSPORT=stdio",
"-e",
"LOKI_URL",
"talkopsai/loki-mcp-server:latest"
],
"env": {
"LOKI_URL": "http://host.docker.internal:3100"
}
}
}
}
2. Restart your client and try asking:
- "What errors is the
checkoutservice logging in the last 30 minutes?" - "Did the error rate go up after yesterday's release?"
- "Find all logs for trace ID
4bf92f3577b34da6a3ce929d0e0e4736."
Allowing changes
Out of the box the server is read-only. To let your assistant make changes (changing Ruler rule groups, deleting logs, and applying Loki Operator resources), add "--allow-write" to args (or pass -e MCP_ALLOW_WRITE=true to docker run). Even then, changes are previewed first and destructive actions ask for confirmation.
Configuration
Set these as environment variables (the env block in your client config, or -e with docker run) or pass the matching flag.
| Variable | Flag | Default | What it does |
|---|---|---|---|
LOKI_URL |
--loki-url |
http://loki:3100 |
Your Loki URL |
LOKI_ORG_ID |
--org-id |
none | Tenant (X-Scope-OrgID) for multi-tenant Loki |
LOKI_AUTH_TOKEN |
— | none | Bearer token for Loki |
MCP_ALLOW_WRITE |
--allow-write |
false |
Enable tools that change Loki |
MCP_TOOLSETS |
--toolsets |
all |
Limit tools: discovery, query, analysis, diagnostics, rules, governance, operator, readonly |
K8S_ENABLED |
--k8s-enabled |
false |
Turn on Loki Operator (Kubernetes) features |
MCP_TRANSPORT |
--transport |
stdio |
stdio or http |
MCP_PORT |
--port |
8769 (8770 in Docker) |
Port when using HTTP |
Run uvx --from talkops-loki-mcp-server loki-mcp-server --help to see every option.
Running over HTTP
To share one server between several clients or run it remotely, start it in HTTP mode with Docker or uvx:
# With Docker (starts in HTTP mode by default)
docker run --rm -p 8770:8770 \
-e LOKI_URL=http://host.docker.internal:3100 \
talkopsai/loki-mcp-server:latest
# Or with uvx
MCP_TRANSPORT=http MCP_PORT=8770 uvx --from talkops-loki-mcp-server loki-mcp-server
Then point your client at http://localhost:8770/mcp:
{
"mcpServers": {
"loki": {
"url": "http://localhost:8770/mcp"
}
}
}
Agent Skills
Skills live in skills/. Each one is a SKILL.md playbook (plus optional references/ and offline scripts/) that teaches your AI assistant how to do a job safely, while the MCP server does the actual work. Tools are the hands, skills are the know-how.
To use them, copy the folders into your assistant's skills directory, for example:
git clone https://github.com/talkops-ai/talkops-mcp.git
cp -r talkops-mcp/src/loki-mcp-server/skills/* ~/.claude/skills/
This folder is also a portable Agent Plugin (plugin.json + mcp.json + skills/), so plugin-aware clients can load the server and skills together.
| Skill | Use it to |
|---|---|
discovering-loki-schema-and-log-structure |
Find out which labels, fields, and log formats you have. |
authoring-logql-and-analyzing-logs |
Write efficient LogQL and analyze the results. |
triaging-loki-incidents-and-errors |
Summarize errors, compare time periods, and follow trace IDs. |
optimizing-loki-cardinality-and-finops |
Find out what's driving log volume and cost. |
authoring-loki-alerting-and-recording-rules |
Write and test log-based alerts and recording rules. |
operating-loki-deployments-and-ingestion |
Fix ingestion problems, delete logs safely, and size Loki. |
Reference
All 18 tools
| Tool | Access | What it does |
|---|---|---|
loki_analyze_volume |
Read | Attribute ingested log bytes and stream counts by label for FinOps optimization. |
loki_apply_operator_cr |
Write | Validate, preview (dry_run=True), or Server-Side Apply a Loki Operator CR. |
loki_compare_periods |
Read | Compare log volume, error counts, and error signatures across two windows or versions. |
loki_correlate_trace_logs |
Read | Find and chronologically order all logs matching a trace_id or request_id. |
loki_delete_rule_group |
Write (destructive) | Preview (dry_run=True) or delete a Loki Ruler rule group after confirmation. |
loki_get_detected_fields |
Read | Discover structured metadata, JSON keys, and logfmt fields with types and cardinalities in Loki 3.x streams. Read-only. |
loki_get_diagnostics |
Read | Diagnose Loki backend readiness, build version, and discarded log sample reasons. |
loki_get_label_values |
Read | Retrieve values for a specific indexed label in Grafana Loki, optionally scoped by stream selector. Read-only. |
loki_get_labels |
Read | List all indexed label names in Grafana Loki over an optional time window. Read-only. |
loki_get_log_patterns |
Read | Retrieve recurring structural <_> log patterns and line counts from Loki's pattern ingester. Read-only. |
loki_get_query_stats |
Read | Estimate streams, chunks, entries, and uncompressed bytes touched by a LogQL selector before execution. Read-only. |
loki_get_series |
Read | Return active Loki log stream label sets and per-label cardinality for a stream selector. Read-only. |
loki_manage_delete_requests |
Write (destructive) | List, preview (dry_run=True), create, or cancel a Loki Compactor log deletion request. |
loki_query_a2ui |
Read | Execute a LogQL range query and flatten results into an interactive A2UI log table payload. Read-only. |
loki_query_instant |
Read | Evaluate a LogQL metric or stream query at a single point in time. Read-only. |
loki_query_range |
Read | Execute a LogQL range query returning log streams or metric time-series matrices with cost guardrails. Read-only. |
loki_summarize_service_logs |
Read | Compute a high-signal service log health & error summary in one call. |
loki_upsert_rule_group |
Write | Validate, preview (dry_run=True), or upsert a Loki Ruler alerting/recording rule group. |
All 9 resources
| Resource | What it returns |
|---|---|
loki://compactor/delete-requests |
Active and processed Compactor log deletion requests (/loki/api/v1/delete) |
loki://config/backends |
Configured Loki backend connection details (URL, tenant, environment) with redacted secrets |
loki://config/guardrails |
Current safety thresholds for query limits, time windows, and cardinality |
loki://rules/groups |
Active Loki Ruler alerting and recording rule groups across namespaces |
loki://schema/labels |
All available label names in Loki |
loki://server/capabilities |
Server version, active toolsets, write gate status, query guardrails, and detected Loki 3.x backend capabilities |
loki://system/health |
Loki reachability, readiness status, and label count |
loki://operator/crs/{namespace} |
Inventory of Kubernetes LokiStack, RulerConfig, AlertingRule, and RecordingRule CRs in a namespace (use '_all' for cluster-wide) |
loki://operator/manifests/{kind}/{namespace}/{name} |
Sanitized and secret-redacted Loki Operator CR manifest (LokiStack, RulerConfig, AlertingRule, RecordingRule) |
Development
git clone https://github.com/talkops-ai/talkops-mcp.git
cd talkops-mcp/src/loki-mcp-server
uv sync --dev
uv run pytest
uv run loki-mcp-server --help
Get help
License
Apache 2.0. See LICENSE.
Metadata
Release files for talkops-loki-mcp-server 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| talkops_loki_mcp_server-0.2.1.tar.gz | 218.1 kB | With provenance | Details for talkops_loki_mcp_server-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| talkops_loki_mcp_server-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for talkops_loki_mcp_server-0.2.1-py3-none-any.whl |
Total release size: 298.3 kB
Release files / talkops_loki_mcp_server-0.2.1.tar.gz
| Download URL | talkops_loki_mcp_server-0.2.1.tar.gz |
|---|---|
| Size | 218.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
afba6d38fcfc13349ff0ae542b3acf60a4262299d57f0d2eb926ca4a708eada2
|
|
BLAKE2b-256 checksum How to use checksums |
335ad045d94be119f5d5d729876143156d3424a23063c8f8eecf790bb4306c9b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.
Transparency logRelease files / talkops_loki_mcp_server-0.2.1-py3-none-any.whl
| Download URL | talkops_loki_mcp_server-0.2.1-py3-none-any.whl |
|---|---|
| Size | 80.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2fca95a8b6aaa9e92aa8a381ec019128635f51733301b7f443e5d16639e83cc7
|
|
BLAKE2b-256 checksum How to use checksums |
e37fb545698694140d1c76b02386d50a9d096529b905f0bdf5690adfd0adfdf7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.
Transparency logSecurity for talkops-loki-mcp-server 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for talkops_loki_mcp_server-0.2.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.