Skip to main content
Glama
Loki MCP Server

Loki MCP Server

by ghrud92

シンプルなLoki MCPサーバー

鍛冶屋のバッジ

Loki MCPサーバーは、 logcliを使用してGrafana Lokiログを照会するためのモデルコンテキストプロトコル(MCP)インターフェースです。このサーバーにより、AIアシスタントはLokiのログデータに直接アクセスして分析できるようになります。

特徴

  • 完全な LogQL サポートを使用して Loki ログをクエリする

  • ラベル値とメタデータを取得する

  • 環境変数または設定ファイルによる認証と設定のサポート

  • さまざまな出力形式(デフォルト、生データ、JSON 行)でフォーマットされた結果を提供します。

  • 環境でlogcliが利用できない場合は、HTTP API に自動的にフォールバックします。

Related MCP server: Loki MCP Server

前提条件

  • Node.js v16以上

  • タイプスクリプト

  • (オプション) Grafana Loki logcliがインストールされ、PATHでアクセス可能。logcli logcli利用できない場合、サーバーは代わりにLoki HTTP APIを自動的に使用します。

  • Loki サーバーインスタンスへのアクセス

インストール

Smithery経由でインストール

Smithery経由で Claude Desktop 用の Simple Loki MCP Server を自動的にインストールするには:

npx -y @smithery/cli install @ghrud92/simple-loki-mcp --client claude

MCP用

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

npm

  1. リポジトリをクローンします。

git clone https://github.com/ghrud92/loki-mcp.git
cd loki-mcp
  1. 依存関係をインストールします:

npm install
  1. プロジェクトをビルドします。

npm run build

利用可能なMCPツール

クエリロキ

フィルタリング オプションを使用して Loki からログをクエリします。

パラメータ:

  • query (必須): Loki クエリ文字列(LogQL)

  • from : 開始タイムスタンプ(例: "2023-01-01T12:00:00Z")

  • to : 終了タイムスタンプ(例: "2023-01-01T13:00:00Z")

  • limit : 返されるログの最大数

  • batch : クエリ結果のバッチサイズ

  • output : 出力形式("default"、"raw"、または "jsonl")

  • quiet : クエリメタデータを抑制する

  • forward : 結果を時系列順に表示します

ラベル値の取得

特定のラベルのすべての値を取得します。

パラメータ:

  • label (必須): 値を取得するラベル名

ラベルを取得する

利用可能なすべてのラベルを取得します。

パラメータは必要ありません。

構成

Loki アクセスは以下を使用して設定できます。

環境変数

  • LOKI_ADDR : Lokiサーバーのアドレス(URL)

  • LOKI_USERNAME : 基本認証のユーザー名

  • LOKI_PASSWORD : 基本認証のパスワード

  • LOKI_TENANT_ID : マルチテナントLokiのテナントID

  • LOKI_BEARER_TOKEN : 認証用のベアラートークン

  • LOKI_BEARER_TOKEN_FILE : ベアラートークンを含むファイル

  • LOKI_CA_FILE : TLS 用のカスタム CA ファイル

  • LOKI_CERT_FILE : TLSのクライアント証明書ファイル

  • LOKI_KEY_FILE : TLSのクライアントキーファイル

  • LOKI_ORG_ID : 複数組織設定の組織ID

  • LOKI_TLS_SKIP_VERIFY : TLS検証をスキップする(「true」または「false」)

  • LOKI_CONFIG_PATH : 設定ファイルへのカスタムパス

  • DEBUG : デバッグログを有効にする

注: クライアントが HTTP API モードを使用している場合 ( logcliが使用できない場合)、同じ構成パラメータを使用して Loki サーバーを認証および接続します。

設定ファイル

または、次のいずれかの場所にlogcli-config.yamlファイルを作成します。

  • LOKI_CONFIG_PATHで指定されたカスタムパス

  • 現在の作業ディレクトリ

  • ホームディレクトリ ( ~/.logcli-config.yaml )

設定ファイルの例:

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

使用法

サーバーを起動します。

npm start

開発の場合:

npm run dev

実装の詳細

HTTP APIへの自動フォールバック

サーバーはlogcliが環境にインストールされ、使用可能かどうかを自動的に確認します。

  1. logcliが利用可能な場合は、すべてのクエリに使用され、CLIツールの全機能が提供されます。

  2. logcliが利用できない場合、サーバーは自動的に Loki HTTP API の使用にフォールバックします。

    • 追加の設定は必要ありません

    • HTTP APIにも同じ認証パラメータが使用される

    • 応答のフォーマットはCLI出力と一致している

    • どちらのモードでも、クエリごとに1000ログのデフォルトの制限が適用されます。

この自動検出により、手動で構成することなく、サーバーがさまざまな環境でシームレスに動作することが保証されます。

発達

# Run linter
npm run lint

# Fix linting issues
npm run lint:fix

# Run tests
npm run test

ライセンス

このプロジェクトは MIT ライセンスに基づいてライセンスされています - 詳細については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
      -