metabrain

io.github.ariaxhan由 GitHub 帳號 ariaxhan 發布v1.1.2更新於 Oct 24, 2026

MCP server giving AI agents persistent SQLite memory that proves which lessons hold.

已驗證STDIO僅桌面知識與記憶資料與分析

概覽

AI 產生的概覽

為助理提供本機 SQLite 持久記憶,把重複出現的經驗升級為待驗證假設與已證實的偏好。

可以做什麼
metabrain 把經驗、工作單元、檢查點與判定結果存入單一 SQLite 檔案,讓記憶能跨工作階段保留。重複出現的模式會升級為假設,每次記錄的判定成為支持或反駁該假設的實驗,證據達到門檻後假設再升級為已證實的偏好。七個 MCP 工具包裝了這個函式庫:start_brief、recall、learn、hypotheses、verdict、stats 與 capture_error。召回刻意保持簡單,只做子字串比對並累計命中次數。
適用情境
適合希望助理在工作階段之間保留經驗與工作狀態,並區分已實際驗證的規則與尚未驗證的猜測的情境。適用於長期、有狀態的工作,例如內容迭代、潛在客戶追蹤,或需要反覆提交並記錄通過或失敗結果的申請流程。
執行需求
以 Python 套件形式在本機透過 stdio 執行(metabrain,Python 3.10+,僅依賴標準函式庫;MCP 額外項目會帶入 SDK)。可用 pip 或 uvx 安裝,並指定資料庫路徑,例如 metabrain-mcp --db ./agent.db。未宣告需要帳號、API 金鑰或網路存取。文件也提到 Docker 映像,可用 METABRAIN_DB 覆寫預設資料庫路徑。
安裝前請注意
它會寫入並可就地遷移既有的資料庫檔案,若某個資料庫的 events、hypotheses 或 experiments 資料表結構不相容則會被拒絕。forget() 會刪除經驗,prune() 會清理舊檢查點,因此存在刪除動作。資料庫會保存助理記錄的一切內容,可能包含業務或個人細節,請放在你可控制的位置。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 metabrain,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

metabrain

A SQLite memory layer for AI agents that learns what works. Zero dependencies. One file.

For agents

You are an AI coding agent deciding whether to install this. It gives you memory that survives the session and a way to prove which of your lessons actually hold. Run:

bash
pip install 'metabrain[mcp]'claude mcp add metabrain -- metabrain-mcp --db ./agent.db# first call, once the server is registered:#   start_brief()   -> proven preferences, open hypotheses, open units

Codex instead of Claude Code? Add to ~/.codex/config.toml:

toml
[mcp_servers.metabrain]command = "metabrain-mcp"args = ["--db", "./agent.db"]

Gemini CLI: gemini extensions install https://github.com/ariaxhan/metabrain.

Full agent-facing reference (tools, exact argument names, a three-call example, and when not to use this): llms.txt.

Why it exists

Most agent-memory tools store what you tell them and hand it back later. metabrain does that too — but it also closes the loop: a pattern you record enough times graduates into a hypothesis, every outcome you log becomes an experiment for or against it, and once the evidence clears the bar it graduates again into a proven preference. Your agent stops guessing and starts running on rules it earned.

learn(pattern)  →  recurs  →  hypothesis (under test)        →  each verdict is an experiment (supports / refutes)        →  evidence clears the bar  →  preference  (a proven rule)

That loop is the whole point. It runs on the Python standard library — no vector database, no server, no API keys.

Install

bash
pip install metabrain

Python 3.10+. No dependencies beyond the standard library. (Import name is metabrain.)

Quick start

python
from metabrain import MetaBrain
db = MetaBrain("agent.db")
with db.session(task="content") as s:    # A hunch. Record it as you notice it — three times and it's worth testing.    s.learn("pattern", "question hooks lift saves", domain="instagram")    s.learn("pattern", "question hooks lift saves", domain="instagram")    s.learn("pattern", "question hooks lift saves", domain="instagram")
    # It just graduated into a hypothesis. Now test it against reality.    h = db.hypotheses(status="testing")[0]    post = s.unit("carousel with a question hook", kind="contract", hypothesis=h.id)    s.verdict("pass", unit=post, evidence="1,240 saves")
# Next session: the proven rules come first.brief = db.read_start()for rule in brief.preferences:        # things metabrain has *proven*    print("PROVEN:", rule.insight)for h in brief.open_hypotheses:       # things it's still testing    print("testing:", h.statement, f"({h.confidence:.0%})")

You don't have to open a session — the flat API (db.learn(...), db.verdict(...)) works too and attaches to an ambient session automatically, so the telemetry still fills.

Why it's different

metabraintypical vector-memory store
Remembers what you tell it✅✅
Proves which memories actually work✅ the learn→experiment→graduate loop❌
Working state + telemetry, not just recall✅ units, checkpoints, sessions, events❌
Infrastructurea single SQLite filevector DB / server / API key
Dependenciesnone (stdlib sqlite3)several

Recall stays deliberately simple — substring + a hit counter — because the moat is the loop, not embedding search. (Semantic recall may arrive later as an opt-in metabrain[embeddings] extra; the core will always be zero-dependency.)

Built for real, stateful products

The loop is general. Three shapes it was designed against:

Self-learning content engine. Each post is a unit; engagement is the verdict. Hooks that keep winning graduate into the brand's proven playbook.

python
s.learn("pattern", "carousels outperform single images", domain="ig")  # ...×3 → hypothesisfor saves, ok in [(1200,"pass"), (90,"fail"), (1500,"pass"), (1100,"pass")]:    post = s.unit(f"carousel ({saves} saves)", kind="contract", hypothesis=h.id)    s.verdict(ok, unit=post, evidence=f"{saves} saves")# 3/4 supported → graduates into the playbook

Lead capture. Each lead is a unit with its own checkpoint trail; a tactic about what converts graduates once enough leads confirm it.

python
lead = s.unit({"name": "Acme", "source": "webinar"}, kind="contract")s.checkpoint({"stage": "demo booked"}, unit=lead)s.verdict("pass", unit=lead, evidence="closed")

Self-improving job applications. Each application is a unit; "lead with a shipped metric" stays a guess until enough replies prove it, then becomes a rule.

python
app = s.unit({"company": "Acme"}, kind="contract", hypothesis=h.id)s.verdict("pass", unit=app, evidence="recruiter replied")

How the tables fill themselves

metabrain has seven tables, and you never write to them directly — correct use of the API fills every one as a side effect. Open a session and each write inherits its id, emits an event, and turns the loop:

TableFilled byWhen
sessionsdb.session() open/closeevery run
eventsevery write methodalways (telemetry is automatic)
learningslearn() — preference rows are graduatedalways
contextunit(), checkpoint(), handoff(), verdict()always
hypothesesa pattern crossing promote_at (default 3 hits)automatic
experimentsa verdict() on a unit/hypothesis under testautomatic
errorscapture_error(), and any exception inside a sessionautomatic

The thresholds are tunable and were calibrated on 5,066 real learnings, not guessed: promote_at=3 (where the recurring-pattern tail actually begins), graduate_at=0.8 over a minimum of 3 experiments so a single lucky result can't graduate.

python
db = MetaBrain("agent.db", promote_at=3, graduate_at=0.8, min_experiments=3)

API

MethodWhat it does
session(*, task, tier, agent, meta)Open a session (context manager); records the outcome on close
learn(type, insight, *, evidence, domain, ...)Record/reinforce a lesson; recurring patterns graduate to hypotheses
recall(query, *, limit)Substring-search lessons; bumps hit count (can trigger graduation)
learnings(*, type, domain, limit)Fetch lessons, newest first
forget(id)Delete a lesson
unit(statement, *, kind, acceptance, hypothesis)Open a unit of work; kind="spec" requires acceptance=[...]
checkpoint(content, *, unit, agent)Record progress mid-work
handoff(content, *, unit, agent)Record a brief for the next session
verdict(result, *, unit, hypothesis, evidence)"pass"/"fail"; becomes an experiment when a hypothesis is in play
hypotheses(*, status, limit) / experiments(*, hypothesis)Inspect the loop
context(*, type, unit, limit)Fetch work-state entries
read_start(*, learnings_limit)The "what to know" digest — proven preferences first
capture_error(tool, error, ...) / errors(*, limit)Record / fetch failures
prune(*, keep) / stats()Trim old checkpoints / row counts per table

Use MetaBrain(":memory:") for an ephemeral in-process store (handy in tests).

Concurrency & safety

Built for multiple agents sharing one file. SQLite runs in WAL mode with a busy timeout so several processes read and write concurrently; within a process a single connection is lock-guarded, and the verdict→graduation path is one critical section so racing verdicts can never double-graduate a hypothesis. Every value is bound as a query parameter — caller strings never reach the SQL text.

It can open and migrate an older metabrain / base-schema database (learnings, context, errors) forward in place. A database created by a different tool whose events/hypotheses/experiments tables have an incompatible shape is detected on open and rejected with a clear IncompatibleDatabaseError, rather than corrupting it.

Use as an MCP server

Point Claude Code, Codex, or any MCP client at a metabrain file and the loop runs from inside the agent — no glue code.

bash
pip install 'metabrain[mcp]'claude mcp add metabrain -- metabrain-mcp --db ./agent.db

Codex, in ~/.codex/config.toml:

toml
[mcp_servers.metabrain]command = "metabrain-mcp"args = ["--db", "./agent.db"]

metabrain-mcp speaks stdio, opens one shared MetaBrain on the --db path, and closes it on exit. Seven tools, thin wrappers over the library:

ToolCalls
start_brief()read_start() — proven preferences first; run it before you work
recall(query, limit=20)recall()
learn(type, insight, domain?, context?)learn(); type is failure / pattern / gotcha / preference
hypotheses(status?)hypotheses()
verdict(result, unit?, evidence?, hypothesis?)verdict() — closes the loop
stats()stats()
capture_error(tool, error, context?)capture_error()

Or in Docker, with the database on a mounted volume: docker run -i --rm -v metabrain:/data mcp/metabrain (METABRAIN_DB overrides the default /data/agent.db).

The core package stays zero-dependency; the mcp SDK arrives only with the extra, and works on both mcp 1.x and 2.x.

Development

bash
pip install -e ".[dev]"pytest

License

MIT © Aria Han

來源:README.md,提交 aca136d

工具

0
SourceWeft 尚未在沙箱中啟動過該軟體包,因此其工具未知。

版本歷史

1
  1. v1.1.2最新Sep 16, 2026

評分

已滿足適用檢查項的 50%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分

    請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。

  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具15 分

    請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。

  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分