Log Intelligence MCP

Log Intelligence MCP

MCP server for semantic log ingestion, hybrid retrieval, and cleanup, enabling natural-language querying of log files with dense+BM25 retrieval and full provenance.

Category
访问服务器

README

Log Intelligence MCP

Semantic log ingestion, hybrid retrieval, and cleanup for the Rapid7 SI Triage Automation POC. This is the "Application Logs MCP" in the architecture diagram: it turns raw log files (downloaded from Jira tickets by the companion Jira/Confluence MCP) into a queryable vector index, and serves the most relevant log chunks back to the triage agent during defect analysis.


What it does

  1. Ingest — reads raw log files for a ticket, parses them into logical entries (a header line plus its stack-trace/continuation lines), groups them into semantic, token-budgeted chunks, embeds each chunk, and stores the vectors in a per-ticket collection.
  2. Query — given a natural-language question, runs hybrid retrieval (dense vector similarity + BM25 keyword matching, fused with Reciprocal Rank Fusion) and returns the top-k chunks with full provenance (source file, line range, time span, log levels, trace ids).
  3. Stats — cheap aggregate view of a ticket's logs (level histogram, error count, time span, distinct trace ids).
  4. Delete — after the defect pipeline finishes, removes the ticket's vectors and the raw local log files, freeing disk and clearing stale data.

Tools

Tool Purpose
ingest_ticket_logs(ticket_id, paths?) Parse → chunk → embed → store all logs for a ticket. Reads from the shared logs/<ticket_id>/ dir by default, or an explicit paths list.
query_logs(ticket_id, query, top_k=5) Hybrid semantic + keyword retrieval of the most relevant chunks.
get_log_stats(ticket_id) Ingestion manifest + stored-chunk count + entry summary.
delete_ticket_logs(ticket_id, delete_raw=true) Remove vectors and (optionally) raw files. Cleanup step.

The chunking strategy (why it's built this way)

Chunk quality decides retrieval quality, so the chunker is the heart of this MCP.

  • Entry-aware. Logs are first assembled into entries: a timestamped header plus every continuation line (\tat …, Caused by:, … N more, wrapped messages). An entry is atomic — it is never split across chunks, which is what guarantees a stack trace always travels with the ERROR line that produced it.
  • Token-budgeted for Claude. Chunks target ~1000 tokens and are capped at 1600 (CHUNK_*_TOKENS). Large enough to hold a full error + stack trace + surrounding context; small enough that top-k results stay focused and the agent's Phase-1 prompt stays bounded.
  • Semantically grouped. Packing prefers to break at natural boundaries — a new trace/correlation id, or a fresh ERROR — so related lines for one request land in the same chunk.
  • Overlap without cutting. Each chunk is seeded with the trailing whole entries of the previous chunk (~150 tokens) so context isn't lost at boundaries, but entries are never sliced mid-way.
  • Oversized entries. A single entry larger than the hard max (e.g. a giant stack trace) is emitted whole and flagged oversized rather than truncated.

Token counting uses a fast, conservative character-based estimate (logs are punctuation-heavy, so this slightly over-estimates and keeps chunks safely under budget). Set USE_ANTHROPIC_TOKENIZER=1 to use exact Claude token counts when network is available.

Hybrid retrieval

Dense and sparse retrieval catch different things: embeddings capture semantic similarity ("payment failed" ≈ "authorization error"), while BM25 nails exact identifiers (TokenVaultException, a trace id, a filename). We run both and fuse their rankings with Reciprocal Rank Fusion:

rrf_score(d) = Σ_retriever  weight / (RRF_K + rank_retriever(d))

RRF fuses ranks rather than raw scores, so the two different score scales don't need fragile normalisation. Tunables: RRF_K (default 60), DENSE_WEIGHT, SPARSE_WEIGHT, CANDIDATE_POOL, DEFAULT_TOP_K.


Backends (production vs. offline)

Every heavy dependency sits behind an adapter with a real pure-Python fallback, so the whole pipeline runs and is testable with no network, and flips to the production backend by changing one env var.

Concern Production (default when installed) Offline fallback (real, not mock)
Embeddings sentence-transformers all-mpnet-base-v2 (768-dim) Deterministic hashed n-gram TF-IDF on numpy
Vector store Chroma (persistent) Per-ticket numpy .npz + JSON, real cosine search
Sparse Pure-Python BM25 (always) same
Token count Anthropic exact counter (optional) character estimate

EMBED_BACKEND=auto uses sentence-transformers if importable, else the hashing embedder. VECTOR_BACKEND=auto uses Chroma if importable, else the numpy store. Force a backend with EMBED_BACKEND=sentence-transformers|bedrock|hashing and VECTOR_BACKEND=chroma|numpy.

The offline fallbacks are genuine implementations (real vectors, real persistence, real similarity search) — they exist so the POC runs anywhere, not to fake results.


Install & run

cd log-intelligence-mcp
python -m venv .venv && source .venv/bin/activate
pip install -e .            # installs mcp, chromadb, sentence-transformers, numpy, uvicorn
cp .env.example .env        # adjust if needed

# stdio (for a local MCP client / Claude Desktop):
python -m log_intelligence_mcp --transport stdio

# HTTP (streamable-http, served at http://127.0.0.1:8081/mcp):
python -m log_intelligence_mcp --transport http

The first sentence-transformers run downloads the model (needs network once). With no network / no heavy deps installed, it automatically uses the offline fallbacks — the server still starts and every tool works.

Register with an MCP client (stdio example)

{
  "mcpServers": {
    "log-intelligence": {
      "command": "python",
      "args": ["-m", "log_intelligence_mcp", "--transport", "stdio"],
      "env": { "SI_DATA_DIR": "/absolute/path/to/si_data" }
    }
  }
}

How it coordinates with the Jira/Confluence MCP

Both servers share one directory tree, SI_DATA_DIR (default ./si_data) — set it to the same absolute path for both.

si_data/
  logs/<ticket_id>/…      # written by the Jira MCP, read by this MCP
  vector_store/           # owned by this MCP
  meta/<ticket_id>.json   # ingestion manifest written by this MCP

Typical flow: Jira MCP get_ticket downloads log attachments into logs/<ticket_id>/ → this MCP ingest_ticket_logs(ticket_id) indexes them → agent calls query_logs(...) during analysis → delete_ticket_logs(ticket_id) cleans up at the end.


Tests

pytest                      # in the POC environment (needs `pip install pytest`)
python tests/_runner.py     # offline harness used when pytest isn't installed

The suite covers entry assembly, the chunker invariants (no split entry, token budget respected, stack trace kept whole, overlap present, every line covered, oversized handling), BM25, hashed embeddings, the numpy store round-trip, hybrid fusion, and a full ingest → query → stats → delete end-to-end. 20 tests, all offline.

Configuration reference

See .env.example for every variable. Key ones: SI_DATA_DIR, CHUNK_TARGET_TOKENS/CHUNK_MAX_TOKENS/CHUNK_MIN_TOKENS/CHUNK_OVERLAP_TOKENS, EMBED_BACKEND/EMBED_MODEL, VECTOR_BACKEND, RRF_K/DENSE_WEIGHT/SPARSE_WEIGHT, DEFAULT_TOP_K, MCP_HTTP_HOST/MCP_HTTP_PORT (default 8081), LOG_LEVEL/LOG_JSON.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选