Skip to main content
Glama
Loki MCP Server

Loki MCP Server

by ghrud92

Einfacher Loki MCP-Server

Schmiedeabzeichen

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 logcli in 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 logcli nicht 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 claude

für MCP

{
  "mcpServers": {
    "simple-loki": {
      "command": "npx",
      "args": ["-y", "simple-loki-mcp"],
      "env": {
        "LOKI_ADDR": "https://loki.sup.band"
      }
    }
  }
}

npm

  1. Klonen Sie das Repository:

git clone https://github.com/ghrud92/loki-mcp.git
cd loki-mcp
  1. Installieren Sie Abhängigkeiten:

npm install
  1. Erstellen Sie das Projekt:

npm run build

Verfü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 Protokolle

  • batch : Batchgröße für Abfrageergebnisse

  • output : Ausgabeformat („Standard“, „raw“ oder „jsonl“)

  • quiet : Abfragemetadaten unterdrücken

  • forward : 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 Basisauthentifizierung

  • LOKI_PASSWORD : Passwort für die Basisauthentifizierung

  • LOKI_TENANT_ID : Mandanten-ID für Loki mit mehreren Mandanten

  • LOKI_BEARER_TOKEN : Bearer-Token zur Authentifizierung

  • LOKI_BEARER_TOKEN_FILE : Datei mit dem Inhabertoken

  • LOKI_CA_FILE : Benutzerdefinierte CA-Datei für TLS

  • LOKI_CERT_FILE : Client-Zertifikatsdatei für TLS

  • LOKI_KEY_FILE : Client-Schlüsseldatei für TLS

  • LOKI_ORG_ID : Organisations-ID für Multi-Org-Setups

  • LOKI_TLS_SKIP_VERIFY : TLS-Verifizierung überspringen („true“ oder „false“)

  • LOKI_CONFIG_PATH : Benutzerdefinierter Pfad zur Konfigurationsdatei

  • DEBUG : Debug-Protokollierung aktivieren

Hinweis : Wenn der Client den HTTP-API-Modus verwendet (wenn logcli nicht 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_PATH

  • Aktuelles Arbeitsverzeichnis

  • Ihr Home-Verzeichnis ( ~/.logcli-config.yaml )

Beispielkonfigurationsdatei:

addr: https://loki.example.com
username: user
password: pass
tenant_id: mytenant

Verwendung

Starten Sie den Server:

npm start

Für die Entwicklung:

npm run dev

Implementierungsdetails

Automatischer Fallback auf HTTP-API

Der Server prüft automatisch, ob logcli installiert und in der Umgebung verfügbar ist:

  1. Wenn logcli verfügbar ist, wird es für alle Abfragen verwendet und bietet die volle Funktionalität des CLI-Tools

  2. Wenn logcli nicht 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 test

Lizenz

Dieses Projekt ist unter der MIT-Lizenz lizenziert – Einzelheiten finden Sie in der Datei LICENSE.md .

Available Tools

3 tools
get_labelsD

Inputs: no named parameters.

get_label_valuesD

Inputs: label (required).

query_lokiD

Inputs: query (required), batch, forward, from, +4 more.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    D1.8/5.0

    Scored across 3 tools

    Disambiguation5/5

    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.

    Naming Consistency5/5

    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.

    Tool Count3/5

    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.

    Completeness2/5

    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

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      D
      maintenance
      A server that enables AI assistants to access and query Grafana dashboards, metrics, logs, and configurations through an MCP protocol interface.
      10
      6
      MIT
    • F
      license
      Not graded
      quality
      D
      maintenance
      Enables 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.
      -
    • A
      license
      Not graded
      quality
      B
      maintenance
      This 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.
      69 npm
      MIT
    • F
      license
      Not graded
      quality
      D
      maintenance
      An MCP server that enables AI assistants to query and analyze logs from Grafana Loki using LogQL, supporting label discovery and keyword search.
      4
      -