Loki MCP Server
シンプルな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 claudeMCP用
{
"mcpServers": {
"simple-loki": {
"command": "npx",
"args": ["-y", "simple-loki-mcp"],
"env": {
"LOKI_ADDR": "https://loki.sup.band"
}
}
}
}npm
リポジトリをクローンします。
git clone https://github.com/ghrud92/loki-mcp.git
cd loki-mcp依存関係をインストールします:
npm installプロジェクトをビルドします。
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のテナントIDLOKI_BEARER_TOKEN: 認証用のベアラートークンLOKI_BEARER_TOKEN_FILE: ベアラートークンを含むファイルLOKI_CA_FILE: TLS 用のカスタム CA ファイルLOKI_CERT_FILE: TLSのクライアント証明書ファイルLOKI_KEY_FILE: TLSのクライアントキーファイルLOKI_ORG_ID: 複数組織設定の組織IDLOKI_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が環境にインストールされ、使用可能かどうかを自動的に確認します。
logcliが利用可能な場合は、すべてのクエリに使用され、CLIツールの全機能が提供されます。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 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-