Skip to main content
Glama
Log Detective MCP

Log Detective MCP

Official
by fedora-copr

Log Detective MCP

MCP server implementing core log analysis tools of Log Detective for use by other agents.

The server uses the Drain3 algorithm to cluster log messages into templates and extract a representative subset of snippets, reducing large logs to a manageable size for downstream analysis.

Installation

Requires Python 3.11+.

pip install .

Or with uv:

uv pip install .

Related MCP server: log-ai-optimizer

Usage

Running the server

logdetective-mcp

Or directly:

python -m logdetective_mcp.main

MCP client configuration

Claude Code

claude mcp add logdetective -- logdetective-mcp

Claude Desktop

Add to your Claude Desktop configuration file:

{
  "mcpServers": {
    "logdetective": {
      "command": "logdetective-mcp"
    }
  }
}

Tools

extract_log_snippets

Extracts representative log snippets using Drain3 clustering. The tool chunks the log into logical messages, clusters similar messages, and returns one representative snippet per cluster.

Log content can be provided in three ways (exactly one must be used):

Parameter

Type

Description

log_text

str

Raw log text passed directly.

log_path

str

Path to a log file on the server's filesystem.

log_url

str

HTTP(S) URL to fetch log content from.

The input schema for both tools uses oneOf to require exactly one nonempty source field. Omitted source fields and fields set to "" do not count as a source. This matches the rule checked when a tool runs. The advertised tool definitions conform to the MCP 2025-11-25 Tool schema.

Optional parameters:

Parameter

Type

Default

Description

max_clusters

int

8

Maximum number of snippets to extract.

max_snippet_len

int

2000

Maximum character length per snippet.

skip_patterns

list[str] | null

null

List of regex patterns. Chunks matching any pattern are excluded before clustering.

context

int

0

Number of lines to include before and after each snippet (0-50).

Returns a list of Snippet objects, each with line_number (position in the original log) and text (the extracted snippet content). MCP structured output wraps this list as {"result": [...]}; the advertised output schema describes that object.

extract_python_tracebacks

Extracts Python tracebacks from the log, including chained exceptions.

Parameter

Type

Default

Description

max_traceback_len

int

2000

Maximum character length per extracted traceback.

skip_patterns

list[str] | null

null

List of regex patterns. Tracebacks matching any pattern are excluded.

context

int

0

Number of lines to include before and after each traceback (0-50).

For both extractor tools, context follows grep's -C behavior: the requested number of surrounding log lines is included on each side when available. The length limit applies to the extracted snippet or traceback; context lines are additional, so the returned text can be longer than the limit. With context enabled, line_number points to the first returned line. Values outside 0-50 are rejected.

If a traceback is truncated, the extractor keeps its beginning and end with a marker when max_traceback_len permits; smaller limits keep only a prefix. Following context starts after the original traceback, without restoring its omitted middle. If a log line is split into chunks by max_snippet_len, each selected chunk keeps its own text when context is added. Neighboring lines do not replace it with the complete long line. Context boundaries follow the chunk's original source lines, including blank lines omitted from the rendered chunk.

Size limits

All downloaded inputs (via log_url) are limited to 100 MB regardless of format. Downloads are streamed in chunks and aborted as soon as the limit is exceeded.

Archives read via log_path are also checked against the 100 MB limit during decompression.

Compressed file support

Both tools transparently decompress archived log files. Supported formats:

  • Single-file compression: .gz, .bz2, .xz, .lzma

  • Archives: .zip, .tar, .tar.gz, .tar.bz2, .tar.xz

Format is detected from the file extension (or URL path). Archives must contain exactly one file.

Zip bomb protection is enforced via:

  • Maximum decompressed size of 100 MB

  • Maximum compression ratio of 100:1

  • Pre-check of declared sizes in zip/tar headers

  • No recursive decompression (nested archives are not unpacked)

Contributing

All changes to this repository must pass pre-commit checks and tests.

uv run pytest tests/

To inspect the JSON schemas returned by the installed server, run the check script with the project's virtual environment. It starts the server over MCP stdio, validates both tool schemas and structured results, and compares the returned tool definitions with the files in schemas/:

.venv/bin/python scripts/check_mcp_schemas.py

After an intentional schema change, regenerate those files with:

.venv/bin/python scripts/check_mcp_schemas.py --write

Available Tools

2 tools
extract_log_snippetsA

Extract representative log snippets using Drain3 clustering.

Analyzes log text by chunking it into logical messages, clustering
similar messages using the Drain algorithm, and returning one
representative snippet per cluster.

Exactly one of log_text, log_path, or log_url must be provided.

Downloaded inputs are limited to 100 MB.
Compressed files (.gz, .bz2, .xz, .zip, .tar, .tar.gz, .tar.bz2,
.tar.xz) are decompressed transparently. Archives must contain
exactly one file. Compression ratios above 100:1 are rejected.

Args:
    log_text: Raw log text to analyze.
    log_path: Path to a log file on disk.
    log_url: HTTP(S) URL to fetch log content from.
    max_clusters: Maximum number of clusters/snippets to extract.
    max_snippet_len: Maximum character length per snippet chunk.
    skip_patterns: Optional list of regex patterns.
        Chunks matching any pattern are excluded before clustering.
    context: Number of lines to include before and after each snippet (0-50).
        These lines are additional to max_snippet_len. Split chunks retain
        their extracted text instead of expanding to the whole source line.

Inputs: context, log_url, log_path, log_text, +3 more. Returns: result

extract_python_tracebacksA

Extract Python tracebacks using specialized heuristic.

Analyzes log text and extracts unbroken Python tracebacks.
Traces are truncated to `max_traceback_len` characters.

Exactly one of log_text, log_path, or log_url must be provided.

Downloaded inputs are limited to 100 MB.
Compressed files (.gz, .bz2, .xz, .zip, .tar, .tar.gz, .tar.bz2,
.tar.xz) are decompressed transparently. Archives must contain
exactly one file. Compression ratios above 100:1 are rejected.

Args:
    log_text: Raw log text to analyze.
    log_path: Path to a log file on disk.
    log_url: HTTP(S) URL to fetch log content from.
    max_traceback_len: Maximum character length per extracted traceback.
    skip_patterns: Optional list of regex patterns.
        Chunks matching any pattern are excluded.
    context: Number of lines to include before and after each traceback (0-50).
        These lines are additional to max_traceback_len. A truncated
        traceback keeps its shortened text; following context begins after
        the original traceback ends.

Inputs: context, log_url, log_path, log_text, +2 more. Returns: result

Tool Schema Changelog

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

Loading tool schema changelog…

    TDQS

    A3.9/5.0

    Scored across 2 tools

    Disambiguation4/5

    The two tools target different extraction strategies (Drain3 clustering vs Python traceback heuristics), so their core purposes are clearly distinct. However, they share identical input modes (log_text/log_path/log_url, skip_patterns, context), and a log containing tracebacks could plausibly be fed to either, leaving a small boundary ambiguity an agent must reason about.

    Naming Consistency5/5

    Both names follow the same `extract_<thing>` snake_case convention with the same verb prefix and noun-phrase object. Parameter naming is also mirrored across the two tools (max_*_len, skip_patterns, context), reinforcing predictability.

    Tool Count3/5

    Two tools is thin for a server branded as 'Log Detective' — the surface is essentially one extraction family with two strategies. It is not incoherent, but there is little room for an agent to do anything beyond pulling snippets or tracebacks.

    Completeness3/5

    Input handling is thorough (text/path/URL, transparent decompression, safety limits) and both tools mirror it consistently. But the lifecycle stops at extraction: there is no summarization, severity/error-level grouping, keyword or pattern-include extraction, or structured output option, which leaves gaps for a diagnostic-oriented server.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      F
      maintenance
      Enables LLMs to analyze logs by extracting patterns, redacting secrets, and providing token-efficient summaries from files, Docker containers, or journald.
      5
      MIT
    • F
      license
      Not graded
      quality
      D
      maintenance
      Compresses log files into templates and statistics using Drain3, and exposes them to AI assistants via an MCP server for efficient log monitoring and anomaly detection.
      -
    • A
      license
      A
      quality
      D
      maintenance
      MCP server that wraps Drain3 for streaming log template mining, read-only matching, parameter extraction, and model persistence, exposing tools and resources to train on logs and query learned templates.
      8
      MIT
    • A
      license
      Not graded
      quality
      A
      maintenance
      Enables AI agents to analyze, cluster, compare, and export reports from local log files through seven read-only tools, returning compact evidence packs with line-number citations instead of raw log dumps. All processing happens on the local machine, so log data never leaves the environment.
      1,388 PyPI
      1
      MIT