Skip to main content
Glama
ghrud92

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
ParametersJSON Schema
NameRequiredDescriptionDefault

No parameters

TDQS

D1/5.0
Behavior1/5

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.

Conciseness1/5

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.

Completeness1/5

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.

Parameters1/5

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.

Purpose1/5

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.

Usage Guidelines1/5

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
ParametersJSON Schema
NameRequiredDescriptionDefault
labelYesLabel name to get values for

TDQS

D1/5.0
Behavior1/5

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.

Conciseness1/5

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.

Completeness1/5

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.

Parameters1/5

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.

Purpose1/5

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.

Usage Guidelines1/5

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
ParametersJSON Schema
NameRequiredDescriptionDefault
batchNoBatch size for query results
forwardNoDisplay results in chronological order
fromNoStart timestamp in UTC (e.g. '2023-01-01T12:00:00Z'). Relative time expressions like '1h ago' are not supported. Use ISO 8601 format.
limitNoMaximum number of logs to return. Maximum value is 1000
outputNoOutput 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.
queryYesLoki query string
quietNoSuppress query metadata
toNoEnd timestamp in UTC (e.g. '2023-01-01T13:00:00Z'). Relative time expressions like 'now' are not supported. Use ISO 8601 format.

TDQS

D1/5.0
Behavior1/5

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.

Conciseness1/5

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.

Completeness1/5

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.

Parameters1/5

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.

Purpose1/5

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.

Usage Guidelines1/5

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.

  1. 3 tool updatesv1.0.0
    • First observedget_label_values
    • First observedget_labels
    • First observedquery_loki

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 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.
    12 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
    -