Drain MCP logo

Drain MCP

Community
NickLennonLiu

A FastMCP server for Drain3 log template mining, training, inference, and cluster inspection.

PublisherNickLennonLiu
Repositorydrain_mcp
LanguagePython
Forks
0
Stars
54
Available tools
0
Transport typestdio
Links
  • Connect tools to AI workflows

    Drain MCP exposes MCP capabilities that can be used by compatible AI clients and agents.

  • 0 available tools

    Browse the callable actions below, including names and descriptions when provided by the server.

  • Ready-to-copy setup

    Use the installation snippets to configure this server in your preferred MCP client.

  • Open source signals

    54 stars and 0 forks from the linked repository.

Drain MCP

Drain MCP is a FastMCP server that exposes Drain3 log template mining as MCP tools. It can learn templates from individual log lines or whole log files, run read-only inference against the trained model, inspect mined clusters, and manage Drain masking rules at runtime.

The server uses file persistence by default, so trained clusters survive process restarts in drain3_state.bin.

Features

  • Train a Drain3 model from a local UTF-8 log file or a directly reachable HTTP/HTTPS log file.
  • Train incrementally from one log line at a time.
  • Match log lines or files against the current model without changing state.
  • Inspect model statistics and page through mined clusters.
  • List, add, and remove masking rules used before template extraction.
  • Run as a Streamable HTTP MCP server on http://localhost:8101/mcp.

Requirements

  • Python 3.10 or newer
  • uv or another Python environment manager

Project dependencies are declared in pyproject.toml:

  • drain3
  • fastmcp

Quick Start

Install dependencies:

bash
uv sync

Start the MCP server:

bash
uv run python server.py

By default the server listens on:

text
http://0.0.0.0:8101/mcp

For local MCP clients, use:

text
http://localhost:8101/mcp

MCP Client Configuration

Configure your MCP client to use Streamable HTTP with the server URL:

json
{
  "mcpServers": {
    "drain-mcp": {
      "url": "http://localhost:8101/mcp"
    }
  }
}

If your client requires an explicit transport field, choose Streamable HTTP.

Tools

train_file

Train the Drain model from a local file path or HTTP/HTTPS URL.

Input:

  • file_url: absolute local path or directly reachable URL

Returns the number of processed lines, cluster counts before and after training, new cluster count, and message counts for clusters touched during the run.

train_line

Train the model with one log line.

Input:

  • line: a single log message without a newline

Returns the mined template, extracted parameters, cluster id, cluster size, and whether a cluster was created or its template changed.

inference_line

Match one log line against the trained model without updating model state.

Input:

  • line: a single log message without a newline

Returns whether the line matched, the cluster id, template, parameters, and cluster size.

inference_file

Run read-only inference over a local file path or HTTP/HTTPS URL.

Input:

  • file_url: absolute local path or directly reachable URL

Returns total line count, matched count, unmatched count, match rate, and the first 100 per-line inference results.

model_stats

Return aggregate model statistics:

  • total cluster count
  • total trained message count

list_clusters

List mined clusters with pagination.

Inputs:

  • page: 1-based page number, default 1
  • page_size: clusters per page, default 20

Returns cluster id, size, and template for each cluster on the page.

list_masking

List the currently configured Drain masking rules.

add_masking

Add a runtime masking rule.

Inputs:

  • regex_pattern: regular expression to mask before template mining
  • mask_with: placeholder name to use for matches

The model is saved and reinitialized so the new rule applies to future training and inference. Existing persisted clusters are preserved.

remove_masking

Remove a runtime masking rule by exact regex pattern.

Input:

  • regex_pattern: exact pattern to remove

The model is saved and reinitialized so the updated masking configuration applies to future training and inference. Existing persisted clusters are preserved.

Persistence and Configuration

The server loads Drain configuration from:

text
drain_demos/drain3.ini

The default configuration includes masking rules for common identifiers such as IP addresses, hexadecimal values, numeric values, and command strings. It also sets the Drain similarity threshold, tree depth, child limit, max cluster count, and extra delimiters.

Model state is stored at:

text
drain3_state.bin

This file is ignored by git because it is runtime state. Delete it if you want to start with a fresh model.

Runtime masking changes are kept in memory for the current server process and applied after the model is reinitialized. To make a masking rule permanent, add it to drain_demos/drain3.ini.

Demo Scripts

The drain_demos directory contains standalone Drain3 examples:

  • drain_stdin_demo.py: interactive training and inference from standard input
  • drain_bigfile_demo.py: batch processing demo using the public SSH log data set from Zenodo
  • drain3.ini: shared Drain3 configuration

Run a demo with:

bash
uv run python drain_demos/drain_stdin_demo.py

Development

Check that the Python files compile successfully:

bash
uv run python -m py_compile server.py main.py drain_demos/*.py

The repository currently has no automated test suite. For functional testing, start the server and call the MCP tools from a compatible MCP client.

Use Drain MCP MCP with multiple AI models

TypingMind connects MCP tools at the workspace level, so once Drain MCP is connected, you can use it with different AI models in TypingMind instead of setting it up separately for each model. This MCP runs locally through the TypingMind MCP connector on your device.

Setup guide to use the local connector

Use this when the MCP server needs access to local files, apps, or private resources on your computer.

1

Open the MCP settings

In TypingMind, go to Settings, Advanced Settings, then Model Context Protocol and choose Setup Connector.

  1. Open TypingMind in your browser.
  2. Click the Settings icon.
  3. Go to Advanced Settings.
  4. Open the Model Context Protocol section.
  5. Click Setup Connector and choose This Device.
TypingMind MCP connector setup screen with This Device selected
2

Run the connector command

Choose This Device, copy the command from TypingMind, and run it in Terminal. Keep the process running while you use MCP.

  1. Copy the setup command shown by TypingMind.
  2. Open Terminal on macOS or Windows Terminal on Windows.
  3. Paste and run the command.
  4. Approve the package install if Terminal asks you to proceed.
  5. Keep the Terminal window running while using MCP tools.
3

Add Drain MCP as a server

When the connector status is Ready, click Edit Servers and paste the MCP server configuration.

  1. Wait until the connector status shows Ready.
  2. Click Edit Servers.
  3. Paste the Drain MCP MCP server configuration.
  4. Save the server list.
  5. Refresh if you want to confirm the connector is still ready.
TypingMind MCP settings showing active server and Edit Servers button
{
  "mcpServers": {
    "drain-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "<mcp-server-package>"
      ]
    }
  }
}
4

Use it across models

Save the server list, open Plugins, enable the Drain MCP MCP tools, then select any supported AI model in TypingMind and use the tools in chat or assign them to an AI agent.

  1. Open the Plugins page in TypingMind.
  2. Enable the Drain MCP MCP tools.
  3. Start a chat and choose the AI model you want to use.
  4. Use the MCP tools in chat or assign them to an AI agent.
  5. Switch to another AI model whenever needed without reconnecting MCP.
TypingMind chat using enabled MCP tools with a selected AI model
Can you use Drain MCP to help me with this task?
Drain MCP
Sure. I read it.
Here is what I found using Drain MCP.

Frequently asked questions

What is the Drain MCP MCP server used for?

Drain MCP is an MCP server that lets compatible AI clients connect to external tools and context. In TypingMind, you can add this MCP server once and make its tools available in your AI workspace.

Can I use Drain MCP MCP with multiple AI models in TypingMind?

Yes. TypingMind connects MCP tools at the workspace level, so you can use Drain MCP with different AI models such as Claude, ChatGPT, Gemini, or other models you have configured in TypingMind without setting up the MCP server separately for each model.

Why use Drain MCP MCP with TypingMind?

TypingMind is one of the best frontends for LLM chat because it brings multiple AI models, prompts, plugins, AI agents, API keys, and MCP tools into one workspace. With Drain MCP connected, you can use its MCP tools across your preferred models while keeping your chat workflow organized in TypingMind.

How do I connect Drain MCP MCP to TypingMind?

Drain MCP runs through the TypingMind local MCP connector. This is best when the MCP server needs access to local files, desktop apps, command-line tools, or private resources on your computer.

What tools does Drain MCP MCP provide in TypingMind?

Drain MCP exposes MCP capabilities that can be enabled from the TypingMind Plugins page and used in chat or assigned to AI agents.

Do I need to share my API keys with TypingMind to use Drain MCP MCP?

No. TypingMind is local-first and lets you keep your model providers, API keys, prompts, and MCP configuration under your control. If Drain MCP requires authentication, add the required headers, OAuth settings, or local configuration for that MCP server when you create the connection.

Related MCP Servers

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇