Skip to main content
Glama
log-analyzer-mcp

log-analyzer-mcp

by yufeizhou666

log-analyzer-mcp

一个提供日志分析和系统指标工具的 MCP(模型上下文协议)服务器。通过 stdio 传输连接到 Claude Code,并公开 5 个用于搜索、计数和分析本地日志文件的工具。

功能

工具

描述

search_logs

通过关键字或正则表达式搜索日志文件

count_by_level

按严重性级别(ERROR/WARN/INFO/DEBUG)统计日志条目

query_by_timerange

在特定时间范围内过滤日志

get_system_metrics

获取 CPU、内存和磁盘使用指标

explain_error

格式化错误内容以进行 AI 辅助分析

Related MCP server: ai-ssh-mcp

快速开始

# Install dependencies
npm install

# Build TypeScript
npm run build

# Run the server
npm start

开发

# Run with hot reload
npm run dev

与 Claude Code 集成

将服务器添加到 Claude Code:

# Project-level (only available in this directory)
claude mcp add log-analyzer -- node /path/to/log-analyzer-mcp/dist/index.js

# User-level (available globally)
claude mcp add log-analyzer --scope user -- node /path/to/log-analyzer-mcp/dist/index.js

验证连接:

claude mcp list

工具详情

通过关键字或正则表达式搜索日志文件。支持搜索单个 .log 文件或整个目录。

{
  "keywords": ["ERROR", "timeout"],
  "regex": "connection.*failed",
  "logPath": "/var/log",
  "limit": 100
}

count_by_level

按严重性级别统计日志条目,可选择按时间范围过滤。

{
  "logPath": "/var/log",
  "startTime": "2026-04-29T00:00:00Z",
  "endTime": "2026-04-30T00:00:00Z"
}

query_by_timerange

在特定时间范围内过滤日志,并可选择级别过滤器。

{
  "startTime": "2026-04-29T00:00:00Z",
  "endTime": "2026-04-30T00:00:00Z",
  "logPath": "/var/log",
  "level": "ERROR",
  "limit": 100
}

get_system_metrics

获取 CPU、内存和磁盘指标。支持 Windows 和 Linux。

{
  "metrics": ["cpu", "memory", "disk"]
}

explain_error

格式化错误内容以进行 AI 辅助的根本原因分析。

{
  "errorContent": "java.lang.NullPointerException\n  at com.example.Service.process(Service.java:42)",
  "contextLines": 10
}

架构

src/
├── index.ts           # MCP Server entry point
├── tools/             # Individual MCP tool implementations
├── utils/
│   ├── log_parser.ts  # Timestamp/level parsing, keyword/regex matching
│   └── metrics.ts     # Cross-platform CPU/memory/disk metrics
└── types/             # TypeScript type definitions

该服务器使用 @modelcontextprotocol/sdk 和 StdioServerTransport。工具通过 CallToolRequestSchema 处理程序进行注册。

关键设计决策

  • 流处理:使用 readline + createReadStream 处理大型日志文件,而无需将其全部加载到内存中

  • 跨平台:Windows (WMIC) 和 Linux (top/free/df) 双路径实现,具有运行时平台检测功能

  • 容错解析:非标准日志格式会被保留而不是丢弃(缺失级别默认为 INFO,缺失时间戳默认为当前时间)

许可证

MIT

Available Tools

5 tools
count_by_levelB

Count log entries by severity level (ERROR, WARN, INFO, DEBUG)

Inputs: logPath, startTime, endTime.

explain_errorC

AI-assisted error analysis. Formats error content for AI analysis.

Inputs: errorContent (required), contextLines.

get_system_metricsB

Get CPU, memory, and disk metrics from the system

Inputs: metrics.

query_by_timerangeC

Query logs within a specific time range

Inputs: startTime (required), endTime (required), logPath, level, +1 more.

search_logsA

Search log files by keywords or regex patterns. Returns matching log entries with timestamps.

Inputs: keywords, regex, logPath, limit.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.4/5.0

    Scored across 5 tools

    Disambiguation5/5

    Each tool has a clearly distinct purpose: counting by level, error explanation, system metrics, time-range queries, and keyword search. No overlap in functionality.

    Naming Consistency4/5

    Names follow a verb-oriented pattern (count, explain, get, query, search) but mix styles: some use 'by_' (count_by_level, query_by_timerange) while others are plain verb_noun (explain_error, get_system_metrics, search_logs). Mostly consistent but with minor deviations.

    Tool Count5/5

    5 tools is well-scoped for a log analysis server, covering essential operations without being too few or excessive.

    Completeness4/5

    Core log analysis tasks are covered: search, count by level, time-range queries, error explanation, and system metrics. Minor gaps exist, such as lacking a tool to list log sources or aggregate statistics beyond level counting.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      B
      quality
      D
      maintenance
      A Claude integration tool that enables users to query and analyze Aliyun (Alibaba Cloud) Simple Log Service logs through natural language commands.
      1
      21 npm
      2
      GPL 2.0
    • A
      license
      A
      quality
      D
      maintenance
      Enables natural language SSH server management via Claude Code, allowing users to read logs, check services, run commands, and transfer files across multiple servers.
      6
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      Enables Claude to monitor CPU, memory, disk, processes, network connections, Docker containers, and system logs for system diagnostics and troubleshooting.
      5
      MIT
    • F
      license
      A
      quality
      D
      maintenance
      Exposes homelab and IT-ops tools to Claude, including system health monitoring, Grafana alert states, Docker container status, Loki logs, SMART disk health, and more.
      8
      1
      -