butler-memory-mcp
给你的 AI agent 一份真正属于你的长期记忆。 一个 MCP 服务器,把你明确要求 记住的事实、偏好和项目上下文写入你自己的 PostgreSQL——每次写入带修订历史 与审计证据,检索自动按敏感度过滤。模型不能静默写入;推断出的东西只会变成 等你决定的候选。接任何 MCP 客户端即用。
仓库简介
Layered long-term memory for AI agents as an MCP server — PostgreSQL-backed, versioned, audited. Agents remember only what you explicitly asked.
Butler 分层记忆的 MCP 桥:把 ai-butler-framework 的
MemoryService / LayeredMemoryService 以标准 MCP 工具暴露给任何 MCP 客户端
(DSH、Claude Code、Codex 等),同时提供一个仅限 loopback 的 HTTP API 供
DSH Web 面板(dsh-butler-memory)读取。
DSH agent ──(MCP stdio)──► ai-butler-memory-mcp ──► MemoryService ──► PostgreSQL
DSH web 面板 ──(HTTP 127.0.0.1:8771)──► 同一进程、同一 principal
自包含分发(vendored)
本包运行时零依赖 ai-butler-framework:所需的记忆领域代码
(MemoryService/LayeredMemoryService/ORM 模型/数据库与配置辅助)以
vendoring 方式内置于 ai_butler_memory_mcp/vendored/,归属校验、敏感度上限、
revision 乐观锁、审计与证据同事务等语义与上游逐字一致。上游文件清单、
行号区间与漂移检查见 VENDORED.md(scripts/check-vendored.py)。
Schema 迁移仍由 ai-butler-framework 的部署负责(ai-butler-db upgrade);
本包只连接已有数据库,不创建、不修改 schema。
安装
从 PyPI(发布后推荐)
pip install butler-memory-mcp
本地开发(源码 checkout)
cd butler-memory-mcp && python3 -m venv .venv
.venv/bin/pip install -e '.[dev]'
配置
复制 .env.example 为 .env,填三个值:
AI_BUTLER_DATABASE_URL— 与框架共用的 PostgreSQL;AI_BUTLER_MCP_USER_ID— 记忆属主(ai-butler-admin bootstrap输出);AI_BUTLER_MCP_DEVICE_ID— 桥作为该用户的一台持久设备:
.venv/bin/ai-butler-admin add-device \
--user-id <USER_UUID> \
--device-name dsh-agent --device-kind agent \
--scope memory:read --scope memory:write
写操作只有在这台设备真实属于该用户时才会被框架接受——身份与审计不因 MCP 而放松。
运行
.venv/bin/ai-butler-memory-mcp # stdio MCP(给 agent 用)
.venv/bin/ai-butler-memory-mcp --transport http --port 8771 # 面板 API
暴露的工具(DSH 中为 mcp__butler__memory_*)
| 工具 | 语义 | 敏感度 |
|---|---|---|
memory_list / memory_search |
列出/检索记忆(search 自动排除 private/secret) | internal 封顶 |
memory_revisions |
不可变修订历史 | — |
memory_create / memory_revise / memory_archive |
显式写入,revision 绑定 | public/internal 封顶 |
memory_candidates / memory_candidate_accept / memory_candidate_reject |
推断候选,绝不静默入库 | — |
当前边界(v0.1 刻意取舍)
- 无浏览器式强确认:MCP 写入依赖工具描述约束("仅当用户明确要求")+ 敏感度
封顶,不等于框架 Web 端的 L2 确认卡片。后续可接 DSH
ask-user。 - 仅 loopback:HTTP 面板 API 拒绝非 loopback 绑定;stdio 模式不监听端口。
- 单用户单设备 principal:多用户映射属后续设计(见 PLAN.md)。
- 数据 durable 但备份/恢复尚未实现(框架 P9 未完成),发布说明中需如实标注。
测试
.venv/bin/pytest # 离线协议测试;vendored 领域代码与上游逐字一致
.venv/bin/python scripts/check-vendored.py --upstream ../ai-butler-framework # 漂移检查
License
Apache License 2.0,与上游 ai-butler-framework 一致。本项目不包含 任何专有模型或素材;发布衍生作品时请保留许可与署名要求。
相关项目
ai-butler-framework— 记忆领域服务的上游实现方(owner/revision/audit 语义的权威来源;本包 vendoring 其记忆领域代码并做漂移检查);- dsh-butler-memory — DeepSeek Harness 接入组合包:agent 工具 + Web 记忆面板。
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file butler_memory_mcp-0.1.1.tar.gz.
File metadata
- Download URL: butler_memory_mcp-0.1.1.tar.gz
- Upload date:
- Size: 41.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1e5f1070831531aa9d366318da12861da59d3c5d80d5c49fe6d2a771a9e27110
|
|
| MD5 |
102bc89decd331ceb2e8d920040706ae
|
|
| BLAKE2b-256 |
bc935ceb5d008eb55de390cc30c6df85f3e98224899de3bc4d3736b45ec103d8
|
File details
Details for the file butler_memory_mcp-0.1.1-py3-none-any.whl.
File metadata
- Download URL: butler_memory_mcp-0.1.1-py3-none-any.whl
- Upload date:
- Size: 43.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4d0694f3411d7baf0f462f690079eff2fd8fc5c02648a8404ae107cb8cbb243b
|
|
| MD5 |
cce30dd29c46dc918b279507ad98f998
|
|
| BLAKE2b-256 |
6f089174917337df18d088546bf9d4271467b085a4eef93466d63e6882d47223
|