Skip to main content
Glama
Amos666
by Amos666

log-mcp-python

MCP(Model Context Protocol)に基づくリモートログ検索サービス、Python実装。

本プロジェクトは、オープンソースのLog-MCP(Java版)の再設計・実装です:外部には完全に一致するMCPツールインターフェース(JSON-RPC 2.0、STDIO / HTTPの2つの転送モード)を提供し、内部はPythonの慣習に従って全体アーキテクチャを再構築し、「ログ取得方法」をプラグイン可能な実行チャネルとして抽象化しています——ログ取得の具体的なコマンドはサービスが一元的に構築し、コマンドを実行するチャネルだけが多種多様です。

特性

  • インターフェース互換:元のJava版と一致する5つのMCPツール(search_logs / tail_logs / read_log_file / list_log_files / list_servers)、入出力契約を整合。

  • プラグイン可能な実行チャネル

    • ssh — SSH秘密鍵による直接接続(paramiko、接続プールと自動再接続付き)

    • pyinfra — 既存のpyinfraホスト資産を再利用(@localroot@host:22などのホストspecをサポート)

    • local — ローカル実行(開発/テスト)

  • コマンド統一構築:すべてのログ操作をターゲットマシンで実行するシェルコマンド(grep -n -A -B / tail -n / sed -n / find)に正規化し、実行チャネルから分離——新しいチャネルはCommandExecutor.execute()を実装するだけでよい。

  • セキュリティ:パラメータ検証、相対パス検証、危険文字検出、元のバージョンと一致するシェルシングルクォートエスケープ。

  • 軽量依存:コアはparamikoのみに依存;pyinfraはオプション依存で、pyinfraチャネルを使用する場合のみインストール。

Related MCP server: mcplogview

アーキテクチャ

MCP 客户端(AI 助手 / IDE)
        │  JSON-RPC 2.0
        ▼
mcp/            传输与协议层(stdio_server / http_server / handler)
        ▼
tools.py        5 个工具的声明式定义(名称 + JSON Schema + 处理函数)
        ▼
service/        业务编排层(参数校验 → 文件推导 → 命令构建 → 解析)
        ▼
executors/      可插拔执行通道(ssh_key / pyinfra_exec / local + registry)
        ▼
目标服务器上的 shell 命令(grep / tail / sed / find)

詳細設計は docs/DESIGN.md を参照。

インストール

pip install .            # 核心功能(ssh + local 通道)
pip install .[pyinfra]   # 需要 pyinfra 通道时
pip install .[dev]       # 运行测试

設定

config.example.json を参照。元のJava版のconfig.json構造と互換性があり、以下の拡張が行われています:

  • 各サーバーはconnectorフィールドで実行チャネルを個別に指定:ssh(デフォルト)/ pyinfra / local

  • pyinfraチャネルはpyinfraHost(完全なホストspec、例:root@192.168.5.20:22 または @local)とpyinfraData(pyinfraに透過的に渡すホストデータ、例:ssh_key)をサポート

  • 文字列は${VAR}環境変数プレースホルダーをサポート(未定義の場合はそのまま保持)

{
  "servers": [
    {
      "name": "ssh-server",
      "connector": "ssh",
      "host": "192.168.5.169",
      "port": 22,
      "username": "root",
      "privateKeyPath": "${SSH_KEY_PATH}",
      "logRootPath": "/home/docker/logs/myapp/",
      "default": true
    },
    {
      "name": "pyinfra-server",
      "connector": "pyinfra",
      "pyinfraHost": "root@192.168.5.20:22",
      "pyinfraData": { "ssh_key": "/root/.ssh/id_rsa" },
      "logRootPath": "/var/logs/app/"
    },
    {
      "name": "dev-local",
      "connector": "local",
      "logRootPath": "/tmp/logs/"
    }
  ],
  "logLevels": ["info", "warn", "error", "debug"],
  "logFilePattern": "{level}/log-{level}-{date}.{seq}.log"
}

主要フィールドの説明:

フィールド

説明

connector

実行チャネル:ssh / pyinfra / local

logRootPath

ログルートディレクトリ(相対パス検証の基準)

logFilePattern

ログファイル命名パターン、{level}/{date}/{seq}プレースホルダー

sshPool

SSH接続プール(接続数上限 / タイムアウト / リトライ)

queryDefaults

クエリのデフォルト値と上限(maxResults / maxReadLines / contextLines など)

実行

# STDIO 模式(MCP 客户端拉起,默认)
log-mcp --config config.json

# HTTP 模式(独立部署,端口默认 8892,路径 / 与 /mcp,健康检查 GET /health)
log-mcp --config config.json --transport http --port 8892

環境変数もサポート:LOG_CONFIGTRANSPORT_MODESERVER_PORT

MCPクライアントへの接続(HTTPモードの例):

{
  "mcpServers": {
    "log-mcp": {
      "url": "http://your-host:8892/mcp"
    }
  }
}

STDIOモードでの接続:

{
  "mcpServers": {
    "log-mcp": {
      "command": "log-mcp",
      "args": ["--config", "/path/to/config.json"]
    }
  }
}

MCPツール

ツール

説明

search_logs

キーワード(オプションで正規表現)で日付・レベルを横断してログを検索、前後のコンテキスト付き

tail_logs

指定レベルの最新N行のログを取得

read_log_file

指定ログファイルの行範囲を読み取り

list_log_files

サーバー上で利用可能なログファイルを一覧表示(サイズ / 変更時刻)

list_servers

設定済みの全サーバーを一覧表示

呼び出し例(HTTP):

curl -s -X POST http://127.0.0.1:8892/mcp -H 'Content-Type: application/json' \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/call",
       "params":{"name":"search_logs","arguments":{"keyword":"ERROR","levels":["error","info"]}}}'

テスト

python -m pytest tests/ -q

テスト範囲:パラメータ/パス検証、シェルエスケープ、コマンド構築、grep出力解析(既知ファイルの決定的解析を含む)、JSON-RPCプロトコル処理、およびlocal / pyinfra(@local)の2つのチャネルのエンドツーエンド統合テスト(合計100ケース)。

ライセンス

Apache-2.0

A
license - permissive license
Not graded
quality - not tested
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    Not graded
    quality
    C
    maintenance
    An MCP server that connects Claude (or any MCP compatible client) to your existing log infrastructure. Query, summarize, and trace logs in plain English across GCP Cloud Logging, AWS CloudWatch, Azure Log Analytics, Grafana Loki, and Elasticsearch without writing filter expressions or leaving your editor.
    11
    3
    MIT
  • A
    license
    Not graded
    quality
    C
    maintenance
    Exposes configured log files as MCP tools, enabling agents to list, query, and follow logs from local and SSH sources.
    MIT
  • F
    license
    Not graded
    quality
    C
    maintenance
    MCP server for infrastructure discovery and remote management, enabling SSH command execution, file transfer, log tailing, and machine/service inventory with a companion web dashboard.
    1
  • A
    license
    A
    quality
    C
    maintenance
    Provides a standardized MCP interface for querying Graylog logs, enabling AI agents to search, diagnose, and correlate runtime logs with code via configurable profiles.
    5
    MIT

View all related MCP servers

Related MCP Connectors

  • Personal assistant MCP server with search, execute, packages, jobs, secrets, and integrations.

  • Scans MCP servers for tool poisoning, prompt injection and supply chain risks.

  • A paid remote MCP for hosted MCP server, built to return verdicts, receipts, usage logs, and audit-r

View all MCP Connectors

Latest Blog Posts

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/Amos666/log-mcp-python'

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