mcp-light-memory
这是什么?
MCP Light Memory 是一个面向编码代理和 MCP 客户端(Warp、OpenCode、JetBrains AI Assistant / PyCharm、Claude Code、Cursor)的轻量级、本地优先的持久记忆系统。它充当 检查点 + 检索层 —— 存储跨会话恢复复杂工作所需的最小持久状态,而无需将完整对话保留在模型的上下文窗口中。
当你的代理开始一个任务时,它会调用 context 并取回相关的历史决策、陷阱、约束和假设——经过排序、去重并受信任边界约束。当任务完成时,它会将工作状态保存为检查点。下一次会话,即使重启之后,记忆依然存在。
Related MCP server: M3 Memory
为什么使用它?
问题 | MCP Light Memory 的解决方案 |
代理在会话之间忘记一切 | Markdown 文件持久化在磁盘上;代理通过 BM25 + 可选嵌入检索它们 |
完整会话历史对上下文来说太大 | 只检索相关的记忆(受 token 预算限制、经 MMR 多样化) |
云依赖 / 隐私问题 | 100% 本地、离线、零网络调用、无守护进程 |
繁重的设置 / 依赖 | 零必需运行时依赖(纯 Python 3.8+ 标准库);可选的 |
通过存储的记忆进行提示注入 | 每条检索到的记忆都明确标记为 |
多项目隔离 | 带注册表白名单的路由器、 |
MCP 协议漂移 | 双时代支持:现代 |
工作原理(机制)
Markdown 是事实来源。 每条记忆都是一个带 YAML frontmatter(
id、type、status、tags、sources、links、valid_from、valid_to、supersedes)的.md文件。人类可读、可 diff、持久化。SQLite 是可重建的缓存。 BM25/FTS5 索引 + 可选的嵌入向量 + 使用跟踪。删除后一切都会从 Markdown 重建。
检索: 纯 Python BM25 + 可选的稠密嵌入 → RRF 融合 → MMR 多样化 → 策略加权(类型/状态/时间)→ token 预算截断。自适应模式:先稀疏,仅在效果弱时使用稠密。
生命周期:
remember→update→supersede(双向链接,永不删除历史)→forget(归档,永不删除)→timeline(时间视图)。使用search --at YYYY-MM-DD进行历史查询。信任边界: 检索到的内容被包裹在
=== BEGIN/END INTERNAL_RAG MEMORY ===中,并带有SECURITY NOTICE标头。结构化 JSON/MCP 携带trust: untrusted+ 可选的security_flags: ["instruction_like_content"]。证据时效性: 每个结果都包含针对本地路径类证据的
evidence_state(present/missing/unverifiable)——在检索时派生,从不持久化。多项目路由器: 通过 JSON 注册表用一个 MCP stdio 服务器统一管理多个项目。在生成子进程之前,
write:false会阻止会修改数据的工具。每次调用子进程隔离(无共享状态)。
安装
前提条件
Python 3.8+(使用
py启动器、python或python3——安装程序会自动检测真实的解释器,并拒绝 WindowsApps 存根)Git(目标项目必须是 git 仓库)
可选:
pip install sentence-transformers numpy以获得更好的语义检索
当前版本由 VERSION 文件定义——请查看它(或运行 mlm.py --version),而不是硬编码一个预期的版本号。
快速开始
克隆此仓库一次,然后安装到任意项目:
# Windows (PowerShell)
git clone https://github.com/PeterPirog/mcp-light-memory.git ~/mcp-light-memory
python ~/mcp-light-memory/install.py . --client warp# Linux/macOS
git clone https://github.com/PeterPirog/mcp-light-memory.git ~/mcp-light-memory
python3 ~/mcp-light-memory/install.py . --client warp安装程序会:
复制技能文件 + 创建
INTERNAL_RAG/+AGENTS.md运行
init+checkpoint+validate(因此guard会立即显示OK)在能够安全操作时,将 MCP 服务器自动注册到客户端配置中(或报告
MANUAL_REQUIRED/ 打印 JetBrains 操作说明)将经验证 Python 解释器的绝对路径写入配置(可避开 Windows PATH 问题)
python .agents\skills\internal-rag\mlm.py --version # reports the installed version
python .agents\skills\internal-rag\mlm.py status # expect: INTERNAL_RAG ready
python .agents\skills\internal-rag\mlm.py guard # expect: GUARD OK安装矩阵
一个安装程序,四种客户端,两种配置范围。完整指南:docs/INSTALLATION.md。
客户端 | 项目范围 | 全局范围 |
Warp(自动写入配置;项目激活可能需要批准) |
|
|
OpenCode stable (V1)(安全 JSON 配置写入自动完成) |
|
|
OpenCode 2 (V2, beta)(安全 JSON 配置写入自动完成) |
|
|
JetBrains AI / PyCharm(在 IDE 界面中手动操作) |
|
|
--global改变客户端配置的作用范围(~/.warp/.mcp.json与{repo}/.warp/.mcp.json、~/.config/opencode/opencode.json与项目opencode.json)。服务器仍然指向你安装时的目标项目。需要为多个仓库提供一个全局 MCP 端点? 请使用多项目路由器——docs/MCP-MULTI-PROJECT.md。
JetBrains/PyCharm 是辅助式而非全自动:安装程序会准备好 JSON 和 Working Directory;你需要在设置 → 工具 → AI Assistant → MCP 中添加服务器,并选择服务器级别 = Project 或 Global。
各客户端的手动设置(不使用安装程序):docs/INSTALLATION.md + 客户端页面(Warp · OpenCode)。
零配置:面向 Warp 和 OpenCode 的复制粘贴提示词
你可以将其中一条直接粘贴到客户端代理中。将 C:\Projects\App 替换为真实的目标仓库路径。
Warp —— 为单个项目安装:
Install and configure MCP Light Memory (mcp-light-memory) as an MCP server for project C:\Projects\App in Warp, using project scope. Use the repository https://github.com/PeterPirog/mcp-light-memory. If the tool is not cloned yet, clone it to a stable location outside the project; if it already exists, update it with git pull --ff-only. Apply the canonical installation contract from the repository and run install.py with TARGET_PROJECT=C:\Projects\App and --client warp without --global. Do not force-overwrite an existing configuration. After installation, verify from cwd=C:\Projects\App: mlm.py --version, mlm.py status, and mlm.py guard, and confirm that the Warp configuration contains mcp-light-memory and the C:\Projects\App path. Report success only after MCP REGISTRATION: REGISTERED and successful verification. If Warp requires an additional project activation/toggle/approval, state the exact client-side step and do not claim the server is active before it is completed.Warp —— 单个项目的全局客户端配置:
Install and configure MCP Light Memory (mcp-light-memory) in Warp globally for project C:\Projects\App. Use the repository https://github.com/PeterPirog/mcp-light-memory. If the tool is not cloned yet, clone it to a stable location outside the project; if it already exists, run git pull --ff-only. Apply the canonical installation contract and run install.py with TARGET_PROJECT=C:\Projects\App, --client warp, and --global. Remember: --global means the global Warp client configuration, while the server must still be bound to C:\Projects\App; do not use the multi-project router. After installation, verify from cwd=C:\Projects\App: mlm.py --version, mlm.py status, and mlm.py guard, and confirm that the global Warp configuration contains mcp-light-memory and the C:\Projects\App path. Report success only after MCP REGISTRATION: REGISTERED and successful verification.OpenCode —— 为单个项目安装(stable/V1):
Install and configure MCP Light Memory (mcp-light-memory) as an MCP server for project C:\Projects\App in OpenCode. By "OpenCode" I mean stable/V1, so use --client opencode, not opencode2. Use the repository https://github.com/PeterPirog/mcp-light-memory. If the tool is not cloned yet, clone it to a stable location outside the project; if it already exists, run git pull --ff-only. Run install.py with TARGET_PROJECT=C:\Projects\App and --client opencode without --global. Do not force-overwrite an existing configuration. If the installer returns MCP REGISTRATION: MANUAL_REQUIRED (for example because opencode.jsonc exists), do not report success: safely edit the JSONC while preserving comments and unrelated settings if you have appropriate file-editing tools; otherwise report the exact manual action required. After real registration, verify from cwd=C:\Projects\App: mlm.py --version, mlm.py status, and mlm.py guard, and confirm that the OpenCode configuration contains mcp-light-memory and C:\Projects\App.OpenCode —— 单个项目的全局客户端配置(stable/V1):
Install and configure MCP Light Memory (mcp-light-memory) globally in OpenCode for project C:\Projects\App. By "OpenCode" I mean stable/V1, so use --client opencode. Use the repository https://github.com/PeterPirog/mcp-light-memory. If the tool is not cloned yet, clone it to a stable location outside the project; if it already exists, run git pull --ff-only. Run install.py with TARGET_PROJECT=C:\Projects\App, --client opencode, and --global. --global means the global OpenCode client configuration, while the server must still be bound only to C:\Projects\App; do not use the multi-project router. If the installer returns MCP REGISTRATION: MANUAL_REQUIRED, do not report success and follow the safe JSONC instructions. After real registration, verify from cwd=C:\Projects\App: mlm.py --version, mlm.py status, and mlm.py guard, and confirm that the global OpenCode configuration contains mcp-light-memory and the C:\Projects\App path.对于 OpenCode 2 / V2,使用相同的提示词,但明确说明 OpenCode 2 / V2,并要求使用 --client opencode2。更多变体:docs/ZERO-SHOT-SETUP-PROMPTS.md。
配置详情
Warp
Warp 从 ~/.warp/.mcp.json(全局,自动启动)或 {repo}/.warp/.mcp.json(项目,需要根据 Warp 文档 手动切换)读取 MCP 服务器配置。格式:mcpServers.<name>,包含 command、args、working_directory(始终设置它——记忆存储会从中解析)。参见 examples/warp.example.json 和 docs/WARP-SETUP.md。
OpenCode stable (V1)
OpenCode 读取项目根目录下的 opencode.json/.jsonc,或全局的 ~/.config/opencode/opencode.json。V1 服务器在 mcp.<name> 下是扁平结构(没有 servers 子键),带有 enabled: true,且 command 是一个数组——参见 examples/opencode-legacy.example.json 和 docs/OPENCODE.md。
OpenCode 2 (V2, beta)
相同的配置文件,不同的结构:mcp.servers.<name>,command 是一个数组,并且没有 enabled 字段(V2 通过 disabled: true 来禁用)——参见 examples/opencode-v2.example.jsonc 和 docs/OPENCODE.md。
JetBrains AI Assistant / PyCharm
PyCharm 不会自动读取任何 MCP 配置文件。安装程序会打印可直接粘贴的 JSON 和 Working Directory;你需要在设置 → 工具 → AI Assistant → MCP (STDIO) 中添加服务器,并选择服务器级别 = Project 或 Global。参见 examples/jetbrains.example.json。
多项目路由器
一个 MCP 连接统一管理多个项目——注册表白名单、write:false 硬边界、每次调用子进程隔离。
注册表文件(projects.json)
{
"projects": {
"backend": { "root": "/abs/path/backend", "write": true },
"shared-lib": { "root": "/abs/path/shared-lib", "write": false }
}
}路由器的 Warp 配置
{
"mcpServers": {
"mcp-light-memory-router": {
"command": "python3",
"args": ["/abs/path/mcp-light-memory/.agents/skills/internal-rag/irag_mcp_router.py", "--registry", "/abs/path/projects.json"],
"working_directory": "/abs/path/mcp-light-memory"
}
}
}工作流
context --task "current task"
↓
recovery, if required (RECOVERY REQUIRED)
↓
checkpoint before first change
↓
implementation
↓
checkpoint after each milestone
↓
guard before finishing核心命令(CLI 别名:mlm.py 或旧版 irag.py):
mlm.py context --task "..."
mlm.py checkpoint --reason "..."
mlm.py search --query "..." --limit 8
mlm.py remember --type decision --title "..." --body "..."
mlm.py show <ref>
mlm.py update <ref> --status superseded
mlm.py status
mlm.py guard
mlm.py validate
mlm.py doctor路径映射(品牌重塑:internal-rag → MCP Light Memory)
新名称 | 旧路径(为兼容性保留) |
|
|
|
|
|
|
|
|
| — |
| — |
磁盘上的 INTERNAL_RAG/ 文件夹和技能目录 .agents/skills/internal-rag/ 有意保留其旧名称,以实现零迁移的向后兼容。参见 docs/MIGRATION-TO-MCP-LIGHT-MEMORY.md。
持久记忆(CRUD)
remember --type decision --title "..." --body "..." --tags "a,b" --evidence "src/x.py:42" --links "decisions/other.md"
show <path-or-id>
show <ref> --section Knowledge
update <ref> --add-tags "new" --append "New evidence: ..."
supersede <ref> --by <new> --reason "..."
forget <ref> # archives, does not delete
link --from <ref> --to <ref>
timeline --limit 20
status
history类型:decision、knowledge、constraint、gotcha、failure、hypothesis、session。
任务栈(中断)
mlm.py push --task "interrupted work" --reason "user-priority"
mlm.py tasks
mlm.py resume
mlm.py forget-task <id> # drop a specific task
mlm.py forget-task # clear the whole stack配置(.irag.yml,可选)
retrieval:
limit: 10
mmr_lambda: 0.4
min_score: 0.3
embeddings: auto # auto | on | off
profile: english-fast # english-fast (default) | multilingual (PL/EN projects)
embeddings_model: null # explicit model overrides the profile
tokens:
context_budget: 5000
checkpoints:
auto_archive_sessions: true
max_task_stack: 24mlm.py config 显示生效的配置。mlm.py config --init 写入一个模板。
可选嵌入(更好的检索)
pip install -r requirements-optional.txt当该包可用且 .irag.yml 中设置了 embeddings: auto(默认)时,检索会使用嵌入,并在不可用时回退到 BM25。可在运行时通过 --embeddings on|off|auto 覆盖。
两种检索配置(参见 docs/EMBEDDINGS.md):
english-fast(默认,all-MiniLM-L6-v2)multilingual(intfloat/multilingual-e5-small)——适用于波兰语-英语项目
离线 / 隔离网络
python pack.py --with-embeddings --profile english-fast
# -> internal-rag-offline-1.8.1.zip (name from pack.py; 1.8.1 = VERSION file)
# On the air-gapped machine:
unzip internal-rag-offline-*.zip -d internal-rag-offline
pip install --no-index --find-links wheels/ -r requirements-optional.txt
python install.py "/path/to/project" --client <warp|opencode|opencode2|jetbrains>详见 docs/OFFLINE.md。
隐私与 Git
默认安装模式是仅本地。安装程序使用 .git/info/exclude,而不是项目的 .gitignore,这样本地记忆和集成文件就不会被意外提交。
在发布项目之前:
python .\privacy_check.py "D:\path\to\project"预期结果:RESULT: PASS
从项目中完全移除
python .\uninstall.py "D:\path\to\project"卸载程序会在仓库外部创建备份,然后移除 INTERNAL_RAG 及其集成。使用 --keep-memory 可保留记忆数据。
文档
目标项目中的结构
project/
├── AGENTS.md
├── .irag.yml # optional config
├── INTERNAL_RAG/
│ ├── WORKING_STATE.md
│ ├── INDEX.md
│ ├── .checkpoint.json
│ ├── decisions/ knowledge/ gotchas/ failures/ hypotheses/ sessions/ archive/
│ └── exports/
├── .agents/skills/internal-rag/
│ ├── SKILL.md
│ ├── mlm.py # primary CLI (forwards to irag.py)
│ ├── irag.py # core (legacy alias, still the canonical module)
│ ├── irag_embeddings.py # optional plugin
│ └── irag_hooks.py # optional git hooks
└── .opencode/ # OpenCode integration (optional)事实来源
当前用户指令,2. 当前代码/测试/配置,3. 规范/ADR,4. 已验证记忆,5. 会话笔记,6. 假设。
记忆可能已过期。以代码为准。
许可证
MIT.
更新日志
1.8.0 — JetBrains 手动设置
--client jetbrains不再写入虚假的配置文件(PyCharm 会忽略 MCP 配置文件)。改为打印可直接粘贴的 JSON 以及 IDE 菜单操作说明。--unregister --client jetbrains会打印一条提示,提醒在 IDE 界面中移除。
1.7.2 — JetBrains cwd + 客户端专属消息
JetBrains:将
working_directory作为提示写入,并打印WARNING,其中包含需要在Settings → Tools → AI Assistant → MCP中设置的确切路径。客户端专属的重启消息(Restart PyCharm / Restart Warp / Restart OpenCode)。
安装输出中会打印
Memory store: <path>,便于立即验证。
1.7.1 — Windows Python 存根修复
detect_python()会拒绝 WindowsApps 的 0 字节存根;优先使用py -0p;并用--version验证每个候选。注册后验证:写入配置后立即运行
--version,并报告PASS/FAIL。--unregister会删除空的配置文件及父目录(修复失效的.warp/.mcp.json空壳 →GUARD STALE)。
1.7.0 — 品牌更名为 MCP Light Memory
从
internal-rag全面更名为 MCP Light Memory(mcp-light-memory)。新增 CLI 别名mlm(mlm.py)。标志/图标资源。迁移文档。GitHub 品牌更名清单。向后兼容:
irag.py、INTERNAL_RAG/以及旧的 MCP 服务器名称保留为弃用别名。18 项品牌更名一致性测试。
1.6.1 — v1.6 后续加固
变更/生命周期基准测试(11 个场景)。信任边界(ADR-015):
trust: untrusted+security_flags。证据新鲜度(ADR-016):evidence_state。规模基准测试(100/1k/10k)。路由器安全回归(+12 项测试)。文档一致性测试。249 项测试通过。
1.6.0 — 检索质量 + MCP 2026-07-28
记忆质量基准测试(37 个用例)。MCP
2026-07-28双时代(server/discover、_meta、structuredContent、outputSchema)。注册表严格write。分块前缀中的来源信息。自适应检索。链接感知上下文。consolidate --prepare。路由器延迟基准测试。ADR-010…016。
1.5.0 — 弃权门控 + 多项目路由器
相关性/弃权门控(
--meta)。FTS5 候选预过滤器。多项目 MCP 路由器。MCP 协议加固(纯 stdout、经 SDK 验证)。168 项测试。
1.4.0 — 分块 + 去重 + 时间生命周期
感知章节的分块(schema v3)。SimHash 去重。多语言 PL/EN 配置。时间生命周期(
valid_from/valid_to/supersedes/--at)。consolidate --dry-run。
1.3.0 — 持久化嵌入缓存
SQLite 中的分块级 float32 BLOB。多个模型可共存。
index --vacuum/--embed-missing。
1.0.2 — Token 预算 + 隐私
Token 预算强制执行。过期记忆检测。重复检测。写入时隐私扫描。自动检查点定时器。离线/气隙隔离包。
1.0.0 — 初始版本
BM25 + MMR 检索。完整的记忆 CRUD。任务栈。MCP 服务器(JSON-RPC stdio)。Git 钩子。诊断。导出/导入。Token 预算。
This server cannot be installed
Maintenance
Related MCP Servers
- AlicenseAqualityAmaintenanceMCP-native, local-first memory for coding agents that turns real sessions into reusable decisions, gotchas, and domain knowledge.176MIT
- AlicenseBqualityCmaintenanceLocal-first persistent memory layer for MCP agents with hybrid search, file ingestion, and GDPR compliance.2022Apache 2.0
- AlicenseNot gradedqualityBmaintenanceProvides a persistent, local-first memory for coding agents over MCP, enabling automatic recall and recording of past work, failures, and decisions to reduce repetition and token usage.MIT
- AlicenseNot gradedqualityAmaintenanceProvides persistent memory for AI coding agents via MCP, enabling agents to store and semantically recall facts, events, and lessons across sessions, all running locally without cloud dependencies.Apache 2.0
Related MCP Connectors
Universal memory for AI agents and tools. Save, organize and search context anywhere.
Persistent memory for AI agents. Search, store, and recall across sessions.
Persistent memory for AI agents — verbatim conversations, searchable by meaning.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/PeterPirog/mcp-light-memory'
If you have feedback or need assistance with the MCP directory API, please join our Discord server