Skip to main content
Glama

Loki MCP Server

by ghrud92
MIT License
86
2
  • Linux
  • Apple

简单的 Loki MCP 服务器

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

特征

  • 使用完整的 LogQL 支持查询 Loki 日志
  • 获取标签值和元数据
  • 通过环境变量或配置文件进行身份验证和配置支持
  • 提供不同输出格式的格式化结果(默认、原始、JSON 行)
  • 当环境中没有logcli可用时,自动回退到 HTTP API

先决条件

  • 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文件。

Install Server
A
security – no known vulnerabilities
A
license - permissive license
A
quality - confirmed to work

remote-capable server

The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.

MCP 接口允许 AI 助手使用 LogQL 查询和分析 Grafana Loki 日志,并支持身份验证和各种输出格式。

  1. 特征
    1. 先决条件
      1. 安装
        1. 通过 Smithery 安装
        2. 对于 MCP
        3. npm
      2. 可用的 MCP 工具
        1. 查询-loki
        2. 获取标签值
        3. 获取标签
      3. 配置
        1. 环境变量
        2. 配置文件
      4. 用法
        1. 实现细节
          1. 自动回退到 HTTP API
        2. 发展
          1. 执照

            Related MCP Servers

            • -
              security
              A
              license
              -
              quality
              A proxy server that enables AI assistants to run and interact with command-line applications like Expo through the Model Context Protocol (MCP), capturing logs and allowing keypress forwarding.
              Last updated -
              12
              6
              TypeScript
              MIT License
            • -
              security
              F
              license
              -
              quality
              An MCP server that connects to Backlog API, providing functionality to search, retrieve, and update issues through natural language commands.
              Last updated -
              53
              1
              JavaScript
              • Apple
            • -
              security
              A
              license
              -
              quality
              An MCP server that allows AI assistants to interact with Foundry datasets, ontology objects, and functions through natural language queries and commands.
              Last updated -
              2
              Python
              MIT License

            View all related MCP servers

            MCP directory API

            We provide all the information about MCP servers via our MCP API.

            curl -X GET 'https://glama.ai/api/mcp/v1/servers/ghrud92/loki-mcp'

            If you have feedback or need assistance with the MCP directory API, please join our Discord server