Skip to main content
Glama
JustinHabashi

log-ai-optimizer

README.md
# log-ai-optimizer

Compresses log files into templates + stats (via [Drain3](https://github.com/IBM/Drain3)) and exposes them to Claude through an MCP server, so AI log monitoring reads compact stats instead of raw lines.

## Install

```bash
python -m venv .venv
.venv/Scripts/activate        # or: source .venv/bin/activate
pip install -r requirements.txt
pip install -e . --no-deps
```

## Configure

```bash
cp config.example.yaml config.yaml
```

Edit `config.yaml`: list the log file paths to tail, plus DB path and sampling caps.

## Run

Start ingestion (tails files, mines templates, writes to SQLite — keep this running):

```bash
log-ai-optimizer ingest config.yaml
```

In a separate process, run the MCP query server (stdio transport):

```bash
log-ai-optimizer serve config.yaml
```

To use it from Claude Desktop/Code, add it as an MCP server pointing at that command, e.g.:

```json
{
  "mcpServers": {
    "log-ai-optimizer": {
      "command": "log-ai-optimizer",
      "args": ["serve", "/path/to/config.yaml"]
    }
  }
}
```

## MCP tools

- `list_sources()` — sources with template/line counts
- `get_template_stats(source_id, since?)` — templates sorted by count
- `get_anomalies(source_id, window_minutes)` — templates new or spiking vs. prior window
- `drill_down(template_id, limit)` — sample raw params for a template
- `search_templates(query, source_id?)` — substring search over templates

## Dev

```bash
pip install -r requirements-dev.txt
pip install -e . --no-deps
pytest
```

See [log-compress-spec.md](log-compress-spec.md) for the full design.