Loki MCP Server
Einfacher Loki MCP-Server
Der Loki MCP Server ist eine Model Context Protocol (MCP) -Schnittstelle zum Abfragen von Grafana Loki-Protokollen mithilfe von logcli . Der Server ermöglicht KI-Assistenten den direkten Zugriff auf und die Analyse von Protokolldaten von Loki.
Merkmale
Abfragen von Loki-Protokollen mit vollständiger LogQL-Unterstützung
Abrufen von Beschriftungswerten und Metadaten
Authentifizierungs- und Konfigurationsunterstützung über Umgebungsvariablen oder Konfigurationsdateien
Bietet formatierte Ergebnisse in verschiedenen Ausgabeformaten (Standard, Rohdaten, JSON-Zeilen)
Automatischer Fallback auf die HTTP-API, wenn
logcliin der Umgebung nicht verfügbar ist
Related MCP server: Loki MCP Server
Voraussetzungen
Node.js v16 oder höher
Typoskript
(Optional) Grafana Loki logcli ist installiert und in Ihrem PATH zugänglich. Wenn
logclinicht verfügbar ist, verwendet der Server stattdessen automatisch die Loki HTTP API.Zugriff auf eine Loki-Serverinstanz
Installation
Installation über Smithery
So installieren Sie Simple Loki MCP Server für Claude Desktop automatisch über Smithery :
npx -y @smithery/cli install @ghrud92/simple-loki-mcp --client claudefür MCP
{
"mcpServers": {
"simple-loki": {
"command": "npx",
"args": ["-y", "simple-loki-mcp"],
"env": {
"LOKI_ADDR": "https://loki.sup.band"
}
}
}
}npm
Klonen Sie das Repository:
git clone https://github.com/ghrud92/loki-mcp.git
cd loki-mcpInstallieren Sie Abhängigkeiten:
npm installErstellen Sie das Projekt:
npm run buildVerfügbare MCP-Tools
Abfrage-Loki
Abfrageprotokolle von Loki mit Filteroptionen.
Parameter:
query(erforderlich): Loki-Abfragezeichenfolge (LogQL)from: Startzeitstempel (zB "2023-01-01T12:00:00Z")to: Endzeitstempel (zB "2023-01-01T13:00:00Z")limit: Maximale Anzahl der zurückzugebenden Protokollebatch: Batchgröße für Abfrageergebnisseoutput: Ausgabeformat („Standard“, „raw“ oder „jsonl“)quiet: Abfragemetadaten unterdrückenforward: Ergebnisse in chronologischer Reihenfolge anzeigen
Beschriftungswerte abrufen
Rufen Sie alle Werte für ein bestimmtes Label ab.
Parameter:
label(erforderlich): Bezeichnungsname, für den Werte abgerufen werden sollen
Etiketten abrufen
Alle verfügbaren Etiketten abrufen.
Keine Parameter erforderlich.
Konfiguration
Sie können den Loki-Zugriff folgendermaßen konfigurieren:
Umgebungsvariablen
LOKI_ADDR: Loki-Serveradresse (URL)LOKI_USERNAME: Benutzername für die BasisauthentifizierungLOKI_PASSWORD: Passwort für die BasisauthentifizierungLOKI_TENANT_ID: Mandanten-ID für Loki mit mehreren MandantenLOKI_BEARER_TOKEN: Bearer-Token zur AuthentifizierungLOKI_BEARER_TOKEN_FILE: Datei mit dem InhabertokenLOKI_CA_FILE: Benutzerdefinierte CA-Datei für TLSLOKI_CERT_FILE: Client-Zertifikatsdatei für TLSLOKI_KEY_FILE: Client-Schlüsseldatei für TLSLOKI_ORG_ID: Organisations-ID für Multi-Org-SetupsLOKI_TLS_SKIP_VERIFY: TLS-Verifizierung überspringen („true“ oder „false“)LOKI_CONFIG_PATH: Benutzerdefinierter Pfad zur KonfigurationsdateiDEBUG: Debug-Protokollierung aktivieren
Hinweis : Wenn der Client den HTTP-API-Modus verwendet (wenn
logclinicht verfügbar ist), werden dieselben Konfigurationsparameter zur Authentifizierung und Verbindung mit dem Loki-Server verwendet.
Konfigurationsdateien
Alternativ können Sie an einem dieser Speicherorte eine Datei logcli-config.yaml erstellen:
Benutzerdefinierter Pfad, angegeben durch
LOKI_CONFIG_PATHAktuelles Arbeitsverzeichnis
Ihr Home-Verzeichnis (
~/.logcli-config.yaml)
Beispielkonfigurationsdatei:
addr: https://loki.example.com
username: user
password: pass
tenant_id: mytenantVerwendung
Starten Sie den Server:
npm startFür die Entwicklung:
npm run devImplementierungsdetails
Automatischer Fallback auf HTTP-API
Der Server prüft automatisch, ob logcli installiert und in der Umgebung verfügbar ist:
Wenn
logcliverfügbar ist, wird es für alle Abfragen verwendet und bietet die volle Funktionalität des CLI-ToolsWenn
logclinicht verfügbar ist, greift der Server automatisch auf die Loki-HTTP-API zurück:Es ist keine zusätzliche Konfiguration erforderlich
Für die HTTP-API werden die gleichen Authentifizierungsparameter verwendet
Die Antwortformatierung stimmt mit der CLI-Ausgabe überein
Das Standardlimit von 1000 Protokollen pro Abfrage gilt in beiden Modi
Diese automatische Erkennung stellt sicher, dass der Server in verschiedenen Umgebungen ohne manuelle Konfiguration reibungslos funktioniert.
Entwicklung
# Run linter
npm run lint
# Fix linting issues
npm run lint:fix
# Run tests
npm run testLizenz
Dieses Projekt ist unter der MIT-Lizenz lizenziert – Einzelheiten finden Sie in der Datei LICENSE.md .
Available Tools
3 toolsget_labelsD
| Name | Required | Description | Default |
|---|---|---|---|
No parameters | |||
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
Tool has no description.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Tool has no description.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Tool has no description.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Tool has no description.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
Tool has no description.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
Tool has no description.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
get_label_valuesD
| Name | Required | Description | Default |
|---|---|---|---|
| label | Yes | Label name to get values for |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
Tool has no description.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Tool has no description.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Tool has no description.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Tool has no description.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
Tool has no description.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
Tool has no description.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
query_lokiD
| Name | Required | Description | Default |
|---|---|---|---|
| batch | No | Batch size for query results | |
| forward | No | Display results in chronological order | |
| from | No | Start timestamp in UTC (e.g. '2023-01-01T12:00:00Z'). Relative time expressions like '1h ago' are not supported. Use ISO 8601 format. | |
| limit | No | Maximum number of logs to return. Maximum value is 1000 | |
| output | No | Output format - valid values are 'default' (formatted log lines), 'raw' (unprocessed log lines), or 'jsonl' (JSON Lines format). Note: values like 'text' or 'json' are not supported. | |
| query | Yes | Loki query string | |
| quiet | No | Suppress query metadata | |
| to | No | End timestamp in UTC (e.g. '2023-01-01T13:00:00Z'). Relative time expressions like 'now' are not supported. Use ISO 8601 format. |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
Tool has no description.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Tool has no description.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Tool has no description.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Tool has no description.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
Tool has no description.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
Tool has no description.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
3 tool updates
v1.0.0- First observed
get_label_values - First observed
get_labels - First observed
query_loki
TDQS
Scored across 3 tools
Each tool has a clearly distinct purpose: get_labels retrieves label names, get_label_values fetches values for a specific label, and query_loki performs log queries. There is no overlap or ambiguity between these functions.
All tool names follow a consistent verb_noun pattern with snake_case (get_labels, get_label_values, query_loki). The naming is predictable and uniform throughout the set.
With only 3 tools, the set feels thin for a Loki server, which typically handles log management and querying. While the tools cover basic operations, more functionality (e.g., log ingestion, stream management) might be expected.
The tool surface is severely incomplete for a Loki server. It lacks essential operations like pushing logs, managing log streams, configuring settings, or performing advanced queries, leaving significant gaps that could cause agent failures.
Maintenance
Related MCP Connectors
Query application logs, traces, and metrics from your AI coding assistant via Foam's MCP server.
- SpanlyOAuthcom.spanly
MCP observability. Query live traffic, errors, duration, and alerts from your AI agent.
A paid remote MCP for AI SDK data query MCP, built to return verdicts, receipts, usage logs, and aud
The Grafbase MCP server sits in front of a GraphQL API and exposes an MCP protocol-compliant interface that allows AI agents and LLMs to explore and query GraphQL APIs using natural language. It provides tools to search schemas, introspect types and fields, and execute GraphQL queries while minimizing context bloat by returning only relevant schema subsets, with built-in support for authentication, authorization, and configurable access control.
Related MCP Servers
- AlicenseAqualityDmaintenanceA server that enables AI assistants to access and query Grafana dashboards, metrics, logs, and configurations through an MCP protocol interface.106MIT
- FlicenseNot gradedqualityDmaintenanceEnables AI models to query and analyze Kubernetes cluster logs through Grafana Loki, supporting semantic operations like error aggregation and pod restart detection. It provides tools for regex-based log searching and namespace discovery to facilitate natural language troubleshooting.-
- AlicenseNot gradedqualityBmaintenanceThis 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.12 npmMIT
- FlicenseNot gradedqualityDmaintenanceAn MCP server that enables AI assistants to query and analyze logs from Grafana Loki using LogQL, supporting label discovery and keyword search.4-