Skip to main content
Glama
ghrud92

Loki MCP Server

by ghrud92

简单的 Loki MCP 服务器

铁匠徽章

Loki MCP 服务器是一个模型上下文协议 (MCP)接口,用于使用logcli查询 Grafana Loki 日志。该服务器使 AI 助手能够直接访问和分析来自 Loki 的日志数据。

特征

  • 使用完整的 LogQL 支持查询 Loki 日志

  • 获取标签值和元数据

  • 通过环境变量或配置文件进行身份验证和配置支持

  • 提供不同输出格式的格式化结果(默认、原始、JSON 行)

  • 当环境中没有logcli可用时,自动回退到 HTTP API

Related MCP server: Loki MCP Server

先决条件

  • Node.js v16 或更高版本

  • TypeScript

  • (可选) Grafana Loki logcli已安装并可在您的 PATH 中访问。如果logcli不可用,服务器将自动使用 Loki HTTP API

  • 访问 Loki 服务器实例

安装

通过 Smithery 安装

要通过Smithery自动为 Claude Desktop 安装 Simple Loki MCP 服务器:

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

使用过滤选项查询 Loki 的日志。

参数:

  • query (必需):Loki 查询字符串(LogQL)

  • from :开始时间戳(例如“2023-01-01T12:00:00Z”)

  • to :结束时间戳(例如“2023-01-01T13:00:00Z”)

  • limit :返回的最大日志数量

  • batch :查询结果的批次大小

  • output :输出格式(“默认”、“原始”或“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
    -