LBrain MCP Server

LBrain MCP Server

Enables AI agents to perform hybrid semantic+keyword search over structured markdown lairs and memory files, with tools for protocol checks and anti-pattern detection.

Category
访问服务器

README

NeurAInetic Layered Brain Harness

LBrain — AI-native engineering memory on the Lair Protocol. By Metavolve Labs.

LBrain indexes structured markdown lairs and memory files and gives an AI agent fast hybrid (semantic + keyword) search over everything you've chosen to remember — surfacing what's stored, never editorializing.

Why

Existing "RAG" tools index text and forget structure. The lair protocol is structure — priority hierarchies, wikilink graphs, frontmatter types, governance cadence. LBrain reads those signals and treats them as first-class retrieval inputs. The protocol is the product; the search engine just respects it.

What it does

  • Hybrid retrieval — BM25 (SQLite FTS5) + cosine (sqlite-vec) fused by Reciprocal Rank Fusion, then wikilink graph boost + priority-folder boost + supersession-aware de-ranking + frontmatter-type filter.
  • Call-when-needed precision / recency — opt-in per query (rerank=True for precise lookups; recency=True for "latest on X"). Off by default — both are situational (measured: rerank helps precise lookups but hurts broad coverage), so they're enabled per call, not globally.
  • Always-on core memory — an optional curated, user-authored block injected ahead of results (the essentials are always present); gated and token-budgeted by the AMP layer.
  • Prompt-injection containment — retrieved note text is fenced and framed as untrusted data, never instructions, before it reaches the agent.
  • Lair Protocol checkshould_commit_to_lair(text) decides what's worth saving so you don't have to think about it.
  • Anti-pattern detection — cross-checks proposed actions against your saved feedback_*.md rules.
  • Onboarding flow — three-minute questionnaire scaffolds CLAUDE.md + starter priority lairs.
  • MCP server — direct integration with Claude Code (claude mcp add -s user lbrain -- /path/to/lbrain-mcp).

Stack

  • Python 3.10+
  • SQLite + sqlite-vec + FTS5 (native, no WASM, no daemon)
  • OpenAI text-embedding-3-small (~$0.12 per 6M-token corpus; pennies on updates)
  • the official mcp SDK (FastMCP) for the MCP server
  • ~2,750 LOC core + ~1,370 LOC optional Tier-2 archive subpackage. No moving parts.

Install

cd lbrain
pip install -e .            # lean core (index → embed → search → MCP)
# pip install -e ".[rerank]"    # + call-when-needed cross-encoder precision pass
# pip install -e ".[archive]"   # + encrypted Tier-2 archive
# pip install -e ".[arweave]"   # + real permaweb (Arweave L1) writes

# Initialize config + DB
lbrain init --api-key=$OPENAI_API_KEY \
            --source=/path/to/your/lairs \
            --source=/path/to/your/memory

# Walk + ingest
lbrain import

# Embed
lbrain embed --stale

Use

# Hybrid semantic search
lbrain query "how do we sign C2PA"

# Filter by frontmatter type
lbrain query "code style" --type feedback

# Priority lairs only
lbrain query "current quarter goals" --priority

# Pure keyword (no embedding call, sub-50ms)
lbrain search "snake_case lock"

# "Should I save this?"
lbrain commit-check "user said: don't auto-format imports in this repo"

# "Does this action conflict with anything I've been told?"
lbrain check-action "going to mock the database for these tests"

# Brain stats
lbrain stats

Onboard a new project

lbrain onboard ~/repos/new-project

Three minutes of opinionated questions → working CLAUDE.md + three priority lairs + LAIR_RULES.md.

Register MCP with Claude Code

chmod +x /path/to/lbrain/scripts/lbrain-mcp
claude mcp add -s user lbrain -- /path/to/lbrain/scripts/lbrain-mcp

Tools surfaced: lair_query, lair_search, lair_protocol_check, lair_check_action, lair_stats.

Containerized deployment — for autonomous agents

For agents running in containers / Kubernetes / outside Claude Code, run LBrain as an HTTP MCP service:

# Local (no container): bind 127.0.0.1 unless you front it with authenticated ingress
# (the server has no built-in auth). Use --host 0.0.0.0 only inside a trusted network.
lbrain mcp --transport streamable-http --host 127.0.0.1 --port 7370

# Docker:
docker build -t lbrain .
# Use a NAMED volume (brain-data) — the container runs as non-root (uid 10001) and a
# host bind mount would inherit host ownership, breaking writes to brain.db. Bind the
# published port to localhost — the MCP server has NO built-in auth, so never publish it
# on a public interface (`-p 7370:7370`); for remote access put an authenticated,
# TLS-terminating reverse proxy in front.
docker run --rm -p 127.0.0.1:7370:7370 -v brain-data:/data \
  -e OPENAI_API_KEY=$OPENAI_API_KEY lbrain

# docker-compose (Kite Apprentice / Maestro pattern):
docker compose -f docker-compose.kite.yml up

⚠️ The streamable-http MCP server exposes the full tool surface (the whole memory corpus is readable) with no authentication. Run it only inside a trusted container network or behind authenticated ingress — never directly on the public internet.

The agent's MCP client connects to http://lbrain:7370/mcp and gets the same 5 tools. Use this for:

  • Recall for autonomous loops — agent calls lair_query at decision points to pull the relevant stored context (no editorializing — just what's saved).
  • Anti-pattern guarding — agent calls lair_check_action before destructive actions; the saved feedback_*.md rules become an automatic safety net.
  • Lair-Protocol output capture — agent calls lair_protocol_check on session outputs to decide what's save-worthy, eliminating the "remind me to remember this" round trip with the user.

Two-brain pattern (recommended for production agents)

  1. Shared brain (read-only mount of your full corpus) — global recall + anti-pattern coverage.
  2. Task-specific brain (per-agent, curated subset) — focused, cheaper, faster. E.g. a Buildathon agent gets only the relevant submission/spec/integration lairs.

Both can run in the same container with different brain.db files via LBRAIN_HOME switching, or as separate containers the agent queries in parallel.

See docker-compose.kite.yml for a full Apprentice + LBrain wiring example.

Architecture

lbrain/
├── index.py          File walker + frontmatter + chunker + wikilink extractor
├── embed.py          OpenAI embeddings client (batched, stateless)
├── store.py          SQLite + sqlite-vec + FTS5 storage layer
├── search.py         Hybrid BM25 + cosine (RRF) + graph/priority/supersession boosts
├── rerank.py         Optional cross-encoder precision pass (call-when-needed)
├── amp.py            Injection gating, token budgeting, provenance, core memory + fence
├── lair_protocol.py  commit-check heuristic + feedback anti-pattern detector
├── onboard.py        Interactive scaffolding for new projects
├── mcp_server.py     MCP tool surface (FastMCP)
├── cli.py            click CLI entry point
├── config.py         ~/.lbrain/config.toml
└── archive/          OPTIONAL Tier-2 subpackage (install via lbrain[archive])
    ├── archiver.py   encrypt → transport (local/Arweave) → snapshot → index
    ├── crypto.py     AES-256-GCM + Argon2id envelopes + per-item crypto-shred
    ├── storage.py    archive tables + queries (lazy schema, shared connection)
    ├── cli.py        archive/capture/recall/retrieve/shred commands (register hook)
    └── mcp.py        lair_deep_recall tool (register hook)

The archive/ subpackage has a strict one-way dependency on the core (it imports core; core never imports it except through guarded, lazy registration). pip install lbrain gives the lean retrieval engine; pip install lbrain[archive] adds the encrypted Tier-2 archive; pip install lbrain[arweave] adds real permaweb writes. Drop the extra (or the directory) and the core runs unchanged — the archive CLI commands and the lair_deep_recall MCP tool simply don't register.

Truth hierarchy

Source files (markdown lairs and memory entries) are authoritative. The SQLite index is a derivative cache. If they disagree, trust the file and run lbrain import && lbrain embed --stale.

Acknowledgements

The injection layer (amp.py) implements patterns from Tate Berenbaum's AMP — Augmented Memory Protocol.

License

BSD 3-Clause — see LICENSE. Copyright (c) 2026 Metavolve Labs, Inc.


Metavolve Labs, Inc. — Build the infrastructure of memory for the AI age.

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选