recall-memory-mcp

recall-memory-mcp

Enables AI agents to store, retrieve, and self-improve procedural memories (lessons learned) based on relevance to the current task, pruning unused memories to reduce context load and prevent repetition of past mistakes.

Category
访问服务器

README

recall-memory-mcp

A relevance-gated, self-improving procedural memory for AI agents, as an MCP server.

Most agent-memory tools remember facts (conversations, preferences). This one stores the lessons an agent learns, surfaces only the ones relevant to the task at hand, and gets better over time by learning from failures, deduping, and pruning what it never uses. So the agent stops dumping its whole history into context, and it stops repeating its own mistakes.

Why

A long-running agent accretes memory and usually loads all of it every session. That is expensive, slow, and it drowns the current truth in stale history, so the agent drifts back to old, superseded decisions.

Measured on a real 64-day production agent: ~91,000 tokens were loaded every session, and ~90% of it was never used. Relevance-gating cut that to a few hundred tokens per task (about a 99% reduction), and the drift stopped, because stale history only surfaces when a task is actually about it.

The full lifecycle (eight tools)

  • recall(task, k) -- only the lessons and state relevant to what you are about to do, each with an actionable check. Self-tracks which lessons get used.
  • preflight(task, k) -- a pre-action checklist: the specific things to verify before editing a file, sending a message, deploying, or querying a database. Built for a PreToolUse hook so the right guardrails fire automatically, with no prose to re-read.
  • learn(title, body, check) -- turn a failure or insight into a retrievable lesson. Closes the loop: next time the same situation comes up, recall surfaces it. Dedupes -- a recurring failure bumps a seen_count instead of cloning the lesson.
  • memory_audit() -- how much loaded memory is never used (archive candidates) and how much is stale.
  • prune() -- retire learned lessons safely: only those never retrieved and not recurring and older than a grace period, so fresh and recurring lessons are never lost.
  • consolidate() -- flag near-duplicate lessons to merge.
  • maintain() -- one self-maintenance pass: audit + safe prune + consolidate report. Safe to run on a schedule or at session wrap.
  • reindex() -- rebuild after the memory files change.

How it works

  • Chunks the agent's markdown memory (rules whole; state, session log, and index at paragraph level), its .claude/skills, and its runtime-learned lessons.
  • Ranks with BM25 (length-normalised, so big stale blocks do not dominate), with source-weighting (real lessons beat index pointers), recency (current decisions beat superseded ones), and a generic-term down-weight (words like "task" or "file" stop inflating noise).
  • preflight adds a concept-overlap gate: a guardrail only fires if the task shares at least two distinctive (non-generic) terms with it, so a single coincidental word never trips a false checklist. This is corpus-size independent.
  • Optional semantic/hybrid retrieval (semantic.py, model2vec static embeddings, CPU, no torch) blends cosine similarity with BM25 so a differently-worded task still finds the right lesson. It degrades gracefully to pure BM25 if the dependency is absent.
  • An on-disk index cache keyed on source-file mtimes keeps preflight fast on the hot path (it runs before every risky tool call); a stale or truncated cache simply fails validation and rebuilds, so it can never serve wrong results.

Performance

On the production agent, with preflight wired into a PreToolUse hook (fires before every file edit / deploy / risky shell command):

  • Warm hook latency ~80 ms (down from ~330 ms) -- index cache + skipping the embedding import in fast mode.
  • In-process preflight lookup ~0.5 ms.
  • Per-task context ~99% smaller than loading all memory.

Tested

A committed test suite covers retrieval precision (the right guardrail fires; benign and irrelevant actions stay silent), latency, hook robustness against malformed and hostile input, and the full auto-learn loop end-to-end (a failure is detected, distilled into a lesson, and becomes retrievable). A second, self-contained smoke test builds a tiny fake agent repo in a tempdir and exercises the whole lifecycle with no external data:

python3 tests/test_smoke.py

Install and use

pip install mcp
RECALL_MEMORY_ROOT=/path/to/your/agent/repo python mcp_server.py   # as a stdio MCP server

By default it indexes .claude/rules/anti-paperclip.md, memory/state.md, memory/session-log.md, and memory/INDEX.md under RECALL_MEMORY_ROOT, plus the .claude/skills it finds and a learned.json it maintains.

To use your own layout, drop a recall.sources.json in RECALL_MEMORY_ROOT (any key you omit falls back to the default):

{
  "rules": [{"path": "docs/rules.md", "split": "\\n###\\s+Rule\\s+"}],
  "paragraphs": [
    {"path": "docs/state.md", "label": "state", "split": "\\n##\\s+"}
  ],
  "skills_dir": ".claude/skills",
  "weights": {"rule": 1.2, "state": 1.0}
}

rules files are chunked whole per section (each carries an extracted check); paragraphs files are chunked per paragraph with a source label and weight. Set skills_dir to null to skip skill indexing.

CLI without the MCP runtime:

RECALL_MEMORY_ROOT=/path/to/repo python recall.py "about to publish a repo"
RECALL_MEMORY_ROOT=/path/to/repo python recall.py --preflight "edit the server entrypoint"
RECALL_MEMORY_ROOT=/path/to/repo python recall.py --learn "Title" "What happened" "What to check next time"
RECALL_MEMORY_ROOT=/path/to/repo python recall.py --maintain
RECALL_MEMORY_ROOT=/path/to/repo python recall.py --audit

Tuning

Env var Default Meaning
RECALL_MEMORY_ROOT . Root of the agent repo to index.
RECALL_LEARNED_PATH <root>/harness-memory/learned.json Where runtime lessons are stored.
RECALL_FAST unset Skip the embedding import (pure BM25); used on the hook hot path.
RECALL_PREFLIGHT_FLOOR 0 Minimum score for a preflight check (the overlap gate does the real filtering).
RECALL_OVERLAP_MIN 2 Distinctive terms a task must share with a guardrail before it fires.

Status and roadmap

v0.3: retrieve / preflight / learn (with dedup) / audit / safe-prune / consolidate / maintain lifecycle, plus optional semantic retrieval, an index cache, env-tunable precision, and tests. It does the thing the fact-memory tools (Mem0, Zep, Letta, Cognee) do not: procedural, relevance-gated, self-pruning memory of how to do the work, that learns from its own failures.

Ahead: auto-firing learn from failure signals; generating evals from failures; behavioural model-diffing on new model releases; and federation.

License

MIT.

推荐服务器

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

官方
精选