{
  "markdown": "# MCP Loki\n\n[![Go Version](https://img.shields.io/github/go-mod/go-version/lexfrei/mcp-loki)](https://go.dev/)\n[![License](https://img.shields.io/github/license/lexfrei/mcp-loki)](LICENSE)\n[![Release](https://img.shields.io/github/v/release/lexfrei/mcp-loki)](https://github.com/lexfrei/mcp-loki/releases)\n[![Release](https://github.com/lexfrei/mcp-loki/actions/workflows/release.yaml/badge.svg)](https://github.com/lexfrei/mcp-loki/actions/workflows/release.yaml)\n\nMCP server for querying Grafana Loki logs. Enables LLMs to search and analyze logs via the Model Context Protocol.\n\n## Features\n\n- **LogQL Queries** — Execute range queries with flexible time ranges\n- **Label Discovery** — List labels and their values for query building\n- **Series Exploration** — Find log streams matching label selectors\n- **Index Statistics** — Get cardinality and size metrics\n- **Prompt Templates** — Ready-made LogQL patterns for common log analysis tasks\n- **Multiple Auth Methods** — Basic auth, Bearer token, multi-tenant (X-Scope-OrgID)\n- **Multi-arch Images** — `linux/amd64` and `linux/arm64`\n- **Signed Images** — Verified with cosign keyless signing\n\n## Quick Start\n\n### Container (Podman/Docker)\n\nAdd to your MCP client configuration:\n\n```json\n{\n  \"mcpServers\": {\n    \"loki\": {\n      \"command\": \"podman\",\n      \"args\": [\n        \"run\", \"--rm\", \"-i\",\n        \"-e\", \"LOKI_URL=http://loki:3100\",\n        \"ghcr.io/lexfrei/mcp-loki:latest\"\n      ]\n    }\n  }\n}\n```\n\n### Go Install\n\n```bash\ngo install github.com/lexfrei/mcp-loki/cmd/mcp-loki@latest\n```\n\nMCP client configuration:\n\n```json\n{\n  \"mcpServers\": {\n    \"loki\": {\n      \"command\": \"mcp-loki\",\n      \"env\": {\n        \"LOKI_URL\": \"http://loki:3100\"\n      }\n    }\n  }\n}\n```\n\n## Configuration\n\nAll configuration is done via environment variables:\n\n| Variable | Required | Default | Description |\n|----------|----------|---------|-------------|\n| `LOKI_URL` | No | `http://localhost:3100` | Loki server URL |\n| `LOKI_USERNAME` | No | — | Basic auth username |\n| `LOKI_PASSWORD` | No | — | Basic auth password |\n| `LOKI_TOKEN` | No | — | Bearer token (alternative to basic auth) |\n| `LOKI_ORG_ID` | No | — | X-Scope-OrgID header for multi-tenant Loki |\n| `MCP_HTTP_PORT` | No | — | Enable HTTP SSE transport on this port |\n\n### Authentication Examples\n\n**No authentication (local Loki):**\n\n```json\n{\n  \"command\": \"podman\",\n  \"args\": [\n    \"run\", \"--rm\", \"-i\",\n    \"-e\", \"LOKI_URL=http://loki:3100\",\n    \"ghcr.io/lexfrei/mcp-loki:latest\"\n  ]\n}\n```\n\n**Basic authentication:**\n\n```json\n{\n  \"command\": \"podman\",\n  \"args\": [\n    \"run\", \"--rm\", \"-i\",\n    \"-e\", \"LOKI_URL=https://loki.example.com\",\n    \"-e\", \"LOKI_USERNAME=admin\",\n    \"-e\", \"LOKI_PASSWORD=secret\",\n    \"ghcr.io/lexfrei/mcp-loki:latest\"\n  ]\n}\n```\n\n**Bearer token (Grafana Cloud):**\n\n```json\n{\n  \"command\": \"podman\",\n  \"args\": [\n    \"run\", \"--rm\", \"-i\",\n    \"-e\", \"LOKI_URL=https://logs-prod-us-central1.grafana.net\",\n    \"-e\", \"LOKI_TOKEN=glc_xxx\",\n    \"-e\", \"LOKI_ORG_ID=123456\",\n    \"ghcr.io/lexfrei/mcp-loki:latest\"\n  ]\n}\n```\n\n## Available Tools\n\n### loki_query\n\nExecute LogQL queries against Loki.\n\n| Parameter | Type | Required | Description |\n|-----------|------|----------|-------------|\n| `query` | string | Yes | LogQL query string |\n| `start` | string | No | Start time (RFC3339, relative like `1h`, or `now`) |\n| `end` | string | No | End time (RFC3339, relative, or `now`) |\n| `limit` | int | No | Maximum entries to return (default: 100) |\n| `direction` | string | No | `forward` or `backward` (default: `backward`) |\n\n**Example:**\n\n```text\nQuery the last hour of nginx error logs:\n- query: {app=\"nginx\"} |= \"error\"\n- start: 1h\n- limit: 50\n```\n\n### loki_labels\n\nGet label names or values for a specific label.\n\n| Parameter | Type | Required | Description |\n|-----------|------|----------|-------------|\n| `name` | string | No | Label name to get values for (omit for all labels) |\n| `start` | string | No | Start time |\n| `end` | string | No | End time |\n\n**Example:**\n\n```text\nGet all label names: (no parameters)\nGet values for \"app\" label: name=app\n```\n\n### loki_series\n\nFind log streams matching label selectors.\n\n| Parameter | Type | Required | Description |\n|-----------|------|----------|-------------|\n| `match` | []string | Yes | Label selector(s), e.g., `{app=\"nginx\"}` |\n| `start` | string | No | Start time |\n| `end` | string | No | End time |\n\n**Example:**\n\n```text\nFind all nginx streams: match=[\"{app=\\\"nginx\\\"}\"]\n```\n\n### loki_stats\n\nGet index statistics for a query.\n\n| Parameter | Type | Required | Description |\n|-----------|------|----------|-------------|\n| `query` | string | Yes | LogQL selector |\n| `start` | string | No | Start time |\n| `end` | string | No | End time |\n\n**Example:**\n\n```text\nGet stats for nginx logs: query={app=\"nginx\"}\n```\n\n### loki_ready\n\nCheck if Loki is ready to accept requests. No parameters required.\n\n### loki_config\n\nGet Loki server configuration in YAML format. No parameters required.\n\n## Available Prompts\n\n### error_logs\n\nFind error logs for a specific application.\n\n| Argument | Required | Default | Description |\n|----------|----------|---------|-------------|\n| `app` | Yes | — | Application name to search errors for |\n| `timerange` | No | `1h` | Time range (e.g. `1h`, `30m`, `7d`) |\n\n### rate_query\n\nCalculate the rate of log lines matching a selector.\n\n| Argument | Required | Default | Description |\n|----------|----------|---------|-------------|\n| `selector` | Yes | — | LogQL stream selector (e.g. `{app=\"nginx\"}`) |\n| `interval` | No | `5m` | Rate interval (e.g. `5m`, `1h`) |\n\n### top_label_values\n\nFind top N values for a label by log volume.\n\n| Argument | Required | Default | Description |\n|----------|----------|---------|-------------|\n| `selector` | Yes | — | LogQL stream selector (e.g. `{app=\"nginx\"}`) |\n| `label` | Yes | — | Label name to group by |\n| `n` | No | `10` | Number of top values to return |\n| `interval` | No | `5m` | Rate interval (e.g. `5m`, `1h`) |\n\n## Time Formats\n\nAll time parameters accept:\n\n- **RFC3339**: `2024-01-15T10:30:00Z`\n- **Relative**: `30s`, `5m`, `1h`, `7d` (seconds, minutes, hours, days ago)\n- **Keyword**: `now`\n\n## Verification\n\nContainer images are signed with cosign keyless signing:\n\n```bash\ncosign verify ghcr.io/lexfrei/mcp-loki:latest \\\n  --certificate-identity-regexp=https://github.com/lexfrei/mcp-loki \\\n  --certificate-oidc-issuer=https://token.actions.githubusercontent.com\n```\n\n## License\n\n[BSD-3-Clause](LICENSE)\n",
  "bytes": 6459,
  "sha": "6c5aacbeba89bbf072fb817c9f54a6273283d02f19cdcf932e2f9279e2399d0a",
  "repo_slug": "lexfrei/mcp-loki",
  "fonte": "repo",
  "truncated": false,
  "api": "https://agentalog.com/api/listings/plg_lexfrei_mcp_loki_loki_37b8241a/readme"
}