Skip to main content
Glama
ghrud92

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