th-memory-mcp
memory-mcp
面向 OpenCode 的长期记忆 MCP 服务器——将偏好、经验教训和使用历史存储在单个本地 SQLite 文件中(100% 本地,无外部 API),使 AI 能够通过基于上下文的记忆学习来“记住并适应”用户。
状态: v1.1.0 — 全部 4 个阶段已实现,测试通过 70/70 断言(冒烟 53 + 捕获 8 + 蒸馏 9)
ไทย / Thai: README.th.md
架构
OpenCode ──┬─ Plugin learning-capture (Bun) ── auto-captures prompts/tool/error into DB
│ └─ injects profile back into context on compaction
└─ MCP memory-mcp (Node.js stdio) ── 9 tools read/write the same SQLite DB
▲
Global instructions (memory-protocol.md) teach the AI to use the tools详见 design.md。
Related MCP server: MCP Vector Memory
脚本
命令 | 描述 |
| 编译 TypeScript → |
| 从 |
| 基于规则的蒸馏:交互 → 档案部分 + 修剪旧数据(环境变量 |
| 通过 JSON-RPC 的端到端冒烟测试( |
| 测试 capture-core(过滤机密、去重、截断、插入 SQL) |
| 测试 distill-core(泰语分词、统计、档案部分、修剪) |
工具(9)
工具 | 描述 |
| 更新或插入偏好(类别+键)——重新保存相同的键会使置信度增加 0.1(上限 1.0) |
| 搜索偏好 + 经验教训(FTS5)+ 最近匹配的交互。在开始新任务前使用 |
| 用户档案概览:档案部分 + 热门偏好 + 最近 5 条经验教训 |
| 记录从纠正中学到的经验教训(情况 / 错误 / 纠正) |
| 按关键词搜索过去的用户提示(每行 200 字符片段) |
| 按 id 删除一条记忆记录(偏好/经验教训/交互)(+类型防止跨表 id 冲突) |
| 记忆统计:按类型计数、数据库大小、最早/最新交互、档案部分 |
| 列出最近的原始交互(按类型过滤)——智能蒸馏的原料 |
| 将记忆导出为 JSON,仅限 |
使用 OpenCode 安装
将
opencode.example.json中的mcp部分合并到你的opencode.json(全局或项目级别)重要: 为服务器和插件设置
MEMORY_DB_PATH为同一个数据库文件(示例使用<ABSOLUTE_PATH>/memory-mcp/data/memory.db),否则自动捕获插件会写入与 AI 读取不同的数据库如何设置(任选其一):
在 mcp 的
environment中定义(见示例)——仅覆盖 MCP 服务器或者将其设置为系统/用户级环境变量(例如在 Windows 上使用
setx MEMORY_DB_PATH "D:/path/to/memory.db")——同时覆盖服务器和插件,因为插件与 OpenCode 在同一进程中运行
附加全局记忆规则——添加到
opencode.json:"instructions": ["C:/Users/<user>/.config/opencode/memory-protocol.md"](示例规则内容位于
AGENTS.memory.example.md——也可以附加在项目级别)(可选)部署自动捕获插件:将
src/plugin/learning-capture.ts复制到~/.config/opencode/plugins/learning-capture.ts重启 OpenCode(配置仅在启动时加载)
测试:“记住我喜欢 pnpm” → 打开新会话并询问
日常使用
AI 可以互换接受泰语和英语——你可以随时切换语言,无需警告。
泰语 | 英语 | 效果 |
"จำไว้ว่า..." | "记住..." |
|
"สรุปความจำ" / "distill memory" | "总结记忆" / "蒸馏记忆" | Smart Distill — AI 读取 |
"ระบบความจำเป็นไงบ้าง" | "我的记忆怎么样?" / "记忆状态" |
|
"สำรองความจำ" | "导出记忆" / "备份记忆" |
|
"ค้นประวัติ..." | "搜索历史..." |
|
"ลืม..." | "忘记..." |
|
长期维护:偶尔运行 npm run distill 来总结统计信息并修剪超过 30 天的交互。
data/ 结构
data/
├── memory.db # SQLite (WAL mode) — main DB (+ .db-wal, .db-shm)
└── exports/ # JSON files from export_memory (writeable only in this dir)数据库路径可以通过
MEMORY_DB_PATH环境变量覆盖data/中的所有内容都被 git 忽略
Maintenance
Related MCP Servers
- -licenseNot gradedqualityNot gradedmaintenanceProvides persistent local memory functionality for AI assistants, enabling them to store, retrieve, and search contextual information across conversations with SQLite-based full-text search. All data stays private on your machine while dramatically improving context retention and personalized assistance.3
- AlicenseNot gradedqualityNot gradedmaintenanceProvides AI coding agents with persistent, long-term memory through local semantic search and SQLite storage. It enables agents to save and retrieve architectural decisions or project context across different conversation sessions without requiring cloud services.
- AlicenseAqualityBmaintenanceProvides persistent cross-session memory and full-text search for AI coding assistants, storing project context, decisions, and preferences while enabling searchable access to conversation history via local SQLite.81MIT
- AlicenseAqualityBmaintenanceProvides AI coding assistants with persistent memory storage using a local SQLite database. Enables tools to remember project details, notes, and relationships across sessions to maintain context and reduce repetitive explanations.174MIT
Related MCP Connectors
Persistent memory and cross-session learning for AI coding assistants (hosted remote MCP).
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/worakorn-prince/th-memory-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server