portable-memory
Exports memories to Markdown mirror files and imports memories from Markdown templates.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@portable-memory recall what we decided about pagination defaults in this project"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
portable-memory
跨编辑器、跨会话的本地外挂记忆系统。一个 Python 服务负责捕获、去重、检索和召回,通过 MCP / REST 暴露给所有 AI 编辑器;DeepSeek Harness 通过上层插件适配。带本地 Web 面板,可可视化管理项目、会话和记忆。
底层服务零第三方依赖(Python 3.9+ 标准库即可运行),数据全部留在你本机。
Web 面板(两个版本)
启动服务后有两个面板,共用同一套 REST API、数据完全互通:
版本 | 地址 | 特点 |
简洁版(原生) |
| 单文件 HTML,零依赖,开箱即用 |
工作台(Vue 3) |
| Vue 3 + Element Plus 工程,召回可视化、项目/会话联动、更完整的布局 |
两个版本都能:
项目切换:点击项目即切换命名空间,记忆互不干扰;
会话管理:记录每次协作,可新建、结束、删除;
记忆增删查改:按类型/标签过滤;
统计:记忆总数、项目数、累计访问次数。
工作台版额外提供:
召回演示台:输入一句 AI 会问的话,展示实际召回的记忆和分数拆解(BM25 相关性 / 时间衰减 / 访问频次 / 命中词),全部来自后端真实计算;
项目隔离可视化:侧栏直接显示每个项目的记忆数;
会话回溯:点击会话可筛出那次协作产生的记忆。
如果设置了 PMEM_TOKEN,在页面右上角输入令牌即可。
前端开发(仅工作台版需要)
工作台版的构建产物已提交在 src/webui/dist/,运行服务不需要 Node。只有修改前端源码时才需要:
cd frontend
npm install
npm run build # 输出到 ../src/webui/dist/源码结构:frontend/src/App.vue 组装,components/ 下按区域拆分(HeroSection / RecallLab / SidePanels / MemoryLibrary),api.ts 是 REST 客户端,types.ts 与后端 DTO 对齐。
Windows 注意:若 esbuild 报
winmm.dll not found或版本不匹配,把frontend/node_modules/@esbuild/win32-x64/esbuild.exe复制到短路径并用ESBUILD_BINARY_PATH指向它再构建。
Related MCP server: Logica Context
和静态记忆文件的区别
静态 CLAUDE.md / MEMORY.md | portable-memory | |
记录 | 手动写 | hook / MCP 自动捕获 |
检索 | 全量塞进上下文 | BM25 按需召回相关项 |
去重 | 无 | SHA-256 内容指纹 |
隐私 | 无 | 写入前自动脱敏密钥 |
时效 | 永久有效、会过时 | 时间衰减 + 重要性排序 |
纠错 | 手工改文件 |
|
跨编辑器 | 每个工具一份 | 一个服务,MCP 通用 |
架构(两层)
上层:DSH 插件 / WorkBuddy Skill ── 适配各编辑器的事件与注入时机
│ MCP
下层:Python 记忆服务(本仓库) ── 捕获 → 处理 → 召回 → SQLite 存储底层编辑器无关,换框架不用重写;上层只是一层薄适配器。
快速开始
git clone <this-repo>
cd portable-memory
# 直接跑 CLI(无需安装依赖)
export PYTHONPATH=$PWD/src
python -m portable_memory remember "分页默认 10 条,不开特例" --type rule
python -m portable_memory recall "分页 默认多少条"
python -m portable_memory statsWindows 用 set PYTHONPATH=%CD%\src 或在安装脚本里自动配。
项目隔离与自动识别
在每个项目根目录跑一次 init,生成 .pmem.json 标记文件:
cd /path/to/my-project
python -m portable_memory init my-project --name "我的项目"之后在这个目录(含子目录)里,CLI 和 MCP 会自动识别项目,记忆自动归到对应 namespace——换项目不用手动切。面板顶部也能随时手动切换查看。
python -m portable_memory project list # 列出所有项目
python -m portable_memory project add --namespace x --name "X" # 手动注册会话管理
python -m portable_memory session start --title "支付模块联调"
python -m portable_memory remember "支付回调要用幂等键" --session 1 --type decision
python -m portable_memory session close --id 1 --summary "确定幂等方案"
python -m portable_memory session listMCP 客户端可用 session_start / session_end 工具。会话记录标题、起止时间、摘要和关联记忆数,可在面板回溯。
安装为命令
pip install -e .
pmem serve # 启动 HTTP 服务
pmem mcp # 以 MCP stdio 方式运行(供编辑器调用)接入编辑器
python scripts/setup_editors.py --list
python scripts/setup_editors.py --all --dry-run
python scripts/setup_editors.py --all --repo-root /path/to/project支持:Claude Code、Cursor、Windsurf、WorkBuddy、DeepSeek Harness、GitHub Copilot。
脚本把 MCP 服务注册到各自的配置文件,指向 python -m portable_memory mcp。
两种接入模式
全局模式(默认):每个编辑器写一份 home 目录配置,MCP 进程靠 cwd 向上找 .pmem.json 判断项目。
python scripts/setup_editors.py --all --dry-run
python scripts/setup_editors.py --all项目模式(推荐):在项目根目录生成项目级配置,把 namespace 写死进环境变量:
cd /path/to/my-project
python -m portable_memory init my-project # 1. 生成 .pmem.json
python scripts/setup_editors.py --all --project . # 2. namespace 自动从 .pmem.json 读
# 或显式指定:--namespace my-project生成的 .mcp.json(各编辑器路径不同)里 env 包含:
"env": {
"PYTHONPATH": ".../src",
"PMEM_DATA_DIR": "~/.portable-memory",
"PMEM_NAMESPACE": "my-project"
}这样无论编辑器从哪启动(命令行、开始菜单、桌面图标),MCP 进程都明确知道自己属于哪个项目,不会把记忆写进 default。优先级:工具参数 > PMEM_NAMESPACE > cwd 的 .pmem.json > default。
项目级配置文件路径:Claude Code .mcp.json、Cursor .cursor/mcp.json、Windsurf .windsurf/mcp.json、Copilot .vscode/mcp.json、WorkBuddy .workbuddy/mcp.json、DSH .dsh/config.json。
DeepSeek Harness 集成
portable-memory 是一个 MCP server,可被 DeepSeek Harness(dsh)直接调用,为其提供跨会话长期记忆:
python scripts/setup_editors.py --editors dsh --dry-run
python scripts/setup_editors.py --editors dsh脚本在 ~/.dsh/config.json 注册名为 portable-memory 的 MCP server(python -m portable_memory mcp)。
dsh 会话中即可通过 memory_add / memory_recall / session_start / session_end 工具读写记忆。
本项目不是 dsh 核心的一部分,也不修改 dsh 源码;它是一个独立的 MCP 服务,遵循 dsh 的插件可发现约定。 dsh 处于 Developer Preview,配置格式可能随版本变化——接入前请用你锁定的 dsh 版本验证一次路径。
REST API
服务默认监听 127.0.0.1:8765,设置 PMEM_TOKEN 后需 Authorization: Bearer <token>。
方法 | 端点 | 说明 |
GET |
| 健康检查 |
POST |
| 写入 |
GET |
| 检索(BM25 + 衰减) |
GET |
| 列出记忆 |
GET |
| 统计 |
DELETE |
| 软删除 |
PUT |
| 编辑记忆内容 |
POST |
| 导出 Markdown 镜像 |
POST |
| 从 Markdown 模板批量导入 |
GET |
| 列出项目 |
POST |
| 注册项目 |
GET |
| 列出会话 |
POST |
| 新建会话 |
POST |
| 结束会话 |
DELETE |
| 删除会话 |
MCP 工具
编辑器可直接调用:memory_add、memory_recall、memory_list、memory_delete、session_start、session_end、project_list。
建议使用时机:会话开始时 memory_recall 当前任务;用户明确表达偏好时 memory_add;协作开始时 session_start,结束时 session_end 并写摘要。
namespace 缺省时自动从当前目录的 .pmem.json 推断,所以同一套 MCP 配置跨项目复用,记忆天然隔离。
配置项
全部通过环境变量,无需配置文件:
变量 | 默认 | 说明 |
|
| 数据目录 |
|
| HTTP 监听 |
| 空 | Bearer token |
|
| 时间衰减半衰期 |
|
| 召回条数 |
检索原理
无向量库、无 LLM 调用:
中文按 bigram、英文按词切分;
BM25 计算词法相关性;
叠加时间衰减(半衰期可配)、访问频次、重要性;
返回带分数明细的结果,可解释为什么召回。
测试
PYTHONPATH=src python -m unittest discover -s tests -v目录
src/portable_memory/
config.py 配置
db.py SQLite 存储、去重、脱敏、导入导出
workspace.py 项目注册、会话管理、.pmem.json 自动识别
pipeline.py 捕获/处理/召回、BM25、衰减
server.py REST 服务 + Web 面板托管
mcp.py MCP stdio 桥接
cli.py 命令行入口
src/webui/
index.html 零依赖可视化面板
scripts/
setup_editors.py 编辑器 MCP 自动配置
dsh-plugin/ DeepSeek Harness 适配层(骨架)
tests/ 单元测试License
Apache-2.0(见 LICENSE)
Available Tools
7 toolsmemory_addB
Store a long-term memory (preference, decision, fact, pitfall).
Inputs: content (required), tags, type, namespace, +1 more.
memory_deleteB
Soft-delete a memory by id.
Inputs: id (required).
memory_listC
List stored memories, optionally filtered by namespace.
Inputs: namespace.
memory_recallB
Search long-term memory. Use at session start and when a past decision matters.
Inputs: query (required), limit, since, until, +1 more.
project_listA
List all projects with their namespaces.
Inputs: no named parameters.
session_endC
Close a session with an optional summary.
Inputs: id (required), summary.
session_startC
Start a new collaboration session for the current project.
Inputs: title, namespace.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 7 tools
Each tool targets a distinct operation: add/recall/list/delete on memories, start/end on sessions, and project_list. The only mild overlap is memory_recall (search) vs memory_list (enumerate), but the descriptions differentiate them reasonably well.
All tools use a consistent namespace_action snake_case pattern (memory_add, memory_recall, session_start, project_list). No camelCase or verb-style mixing.
Seven tools is well-scoped for a memory-plus-session server, with each tool earning its place. No bloat or thin coverage.
Memory has add/recall/list/delete but no update/edit operation, and delete is soft-only with no restore. Session lifecycle has start/end but no session_list or session summary retrieval, and project_list exists without any project creation/registration tool.
Maintenance
Related MCP Connectors
An MCP memory server. One memory your agents share — across models, devices and apps.
Cloud-hosted MCP server for durable AI memory
Self-hosted AI workspace: semantic RAG document search, long-term memory, and AI chat via MCP.
One memory, every AI. A shared, user-owned markdown memory your AI clients read and write over MCP.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceA self-hosted MCP server that provides AI assistants with a shared, persistent SQLite-backed memory for storing and retrieving project context, decisions, and discoveries. It enables cross-session continuity and team-wide knowledge sharing to keep AI coding tools aligned and informed.3MIT
- AlicenseNot gradedqualityCmaintenanceAn MCP server that provides persistent, cross-session memory and team knowledge sharing for AI development workflows. It enables project DNA scanning, semantic search, context budgeting, and git-aware indexing to prevent AI context loss between sessions.11 npmMIT
- AlicenseBqualityDmaintenanceMCP server that provides cross-session persistent memory for AI coding assistants using local vector database and semantic search, enabling automatic recall of project context, issues, and tasks.992Apache 2.0
- AlicenseNot gradedqualityCmaintenanceA self-hosted MCP server that provides a personal semantic memory layer for AI tools. It enables storing, searching, and managing memories using hybrid vector and keyword search, allowing AI assistants to recall information by meaning.MIT