经 AI Skill Hub 精选评估,开源MCP工具 获评「推荐使用」。这款MCP工具在功能完整性、社区活跃度和易用性方面表现出色,AI 评分 7.5 分,适合有一定技术背景的用户使用。
Inspectable local project memory for AI coding agents,帮助开发者更好地理解 AI 编码代理的本地项目内存。
开源MCP工具 是一款遵循 MCP(Model Context Protocol)标准协议的 AI 工具扩展。通过 MCP 协议,它可以让 Claude、Cursor 等主流 AI 客户端直接访问和操作外部工具、数据源和服务,实现 AI 能力的无缝扩展。无论是文件操作、数据库查询还是 API 调用,都可以通过自然语言在 AI 对话中直接触发,极大提升生产效率。
Inspectable local project memory for AI coding agents,帮助开发者更好地理解 AI 编码代理的本地项目内存。
开源MCP工具 是一款遵循 MCP(Model Context Protocol)标准协议的 AI 工具扩展。通过 MCP 协议,它可以让 Claude、Cursor 等主流 AI 客户端直接访问和操作外部工具、数据源和服务,实现 AI 能力的无缝扩展。无论是文件操作、数据库查询还是 API 调用,都可以通过自然语言在 AI 对话中直接触发,极大提升生产效率。
# 方式一:通过 Claude Code CLI 一键安装
claude skill install https://github.com/ctxr-dev/memory
# 方式二:手动配置 claude_desktop_config.json
{
"mcpServers": {
"--mcp--": {
"command": "npx",
"args": ["-y", "memory"]
}
}
}
# 配置文件位置
# macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
# Windows: %APPDATA%/Claude/claude_desktop_config.json
# 安装后在 Claude 对话中直接使用 # 示例: 用户: 请帮我用 开源MCP工具 执行以下任务... Claude: [自动调用 开源MCP工具 MCP 工具处理请求] # 查看可用工具列表 # 在 Claude 中输入:"列出所有可用的 MCP 工具"
// claude_desktop_config.json 配置示例
{
"mcpServers": {
"__mcp__": {
"command": "npx",
"args": ["-y", "memory"],
"env": {
// "API_KEY": "your-api-key-here"
}
}
}
}
// 保存后重启 Claude Desktop 生效
<p align="center"> <strong>Typed, deduplicated, self-improving project memory for AI coding agents.</strong> </p>
<p align="center"> A local Dify Knowledge stack for high-precision RAG, a stdio MCP bridge for every modern agent client, a two-stage <code>flush + compile</code> pipeline that distils sessions into typed atoms instead of dumping transcripts, and a dedicated <code>self_improvement</code> dataset where the agent records every correction you give it (and looks up the lesson before related work, so it stops making the same mistake twice). </p>
<p align="center"> <a href="https://github.com/ctxr-dev/memory/actions/workflows/ci.yml"><img alt="CI" src="https://github.com/ctxr-dev/memory/actions/workflows/ci.yml/badge.svg"></a> <a href="https://github.com/ctxr-dev/memory/releases/latest"><img alt="Latest release" src="https://img.shields.io/github/v/release/ctxr-dev/memory?display_name=tag&sort=semver"></a> <a href="LICENSE"><img alt="License: MIT" src="https://img.shields.io/badge/License-MIT-green.svg"></a> <img alt="Local First" src="https://img.shields.io/badge/Local--First-memory-0A7C66"> <img alt="Dify" src="https://img.shields.io/badge/RAG-Dify-2F6FEB"> <img alt="MCP" src="https://img.shields.io/badge/MCP-stdio-6E56CF"> <img alt="Docker Compose" src="https://img.shields.io/badge/Docker-Compose-2496ED"> <img alt="Node.js" src="https://img.shields.io/badge/Node.js-20+-339933"> <img alt="Claude Code" src="https://img.shields.io/badge/Claude%20Code-supported-D97706"> <img alt="Codex/OpenAI" src="https://img.shields.io/badge/Codex-supported-10A37F"> <img alt="Cursor" src="https://img.shields.io/badge/Cursor-supported-111827"> </p>
<p align="center"> <a href="#install">Install</a> | <a href="#how-memory-is-built">Pipeline</a> | <a href="#what-gets-saved">Categories</a> | <a href="#updates">Updates</a> | <a href="#client-config">Clients</a> | <a href="STACK.md">Stack docs</a> | <a href="CONTRIBUTING.md">Contributing</a> | <a href="SECURITY.md">Security</a> | <a href="CHANGELOG.md">Changelog</a> </p>
<p align="center"> <img src="images/memory-installed.png" alt="Dify Knowledge installed and AI aware of it" width="920"> </p>
---
<p align="center"> <img src="images/img.png" alt="Dify Knowledge UI showing project memory knowledge bases" width="920"> </p>
jq or other extras needed)awk, sed, grep, find, mktemp, tr, cut)git, curlCross-platform: macOS and Linux are first-class. Windows works via WSL2 or Git Bash: bootstrap is bash-only and intentionally avoids jq, realpath, gsed, or any other non-portable binary.
<details> <summary>Docker via Rancher Desktop / Colima (non-standard path)</summary>
If your docker comes from Rancher Desktop (~/.rd/bin/docker), Colima, or another non-standard location, the install scripts auto-resolve it: bootstrap.sh and scripts/lib.sh probe ~/.rd/bin, /usr/local/bin, /opt/homebrew/bin, and the Rancher app bundle before giving up, and you can force a specific binary with DOCKER_BIN=/path/to/docker. One caveat the scripts can't fix for you: the Claude Code / MCP-client process that spawns the memory server runs docker exec … from its own environment, and Rancher only adds ~/.rd/bin to your interactive shell PATH (via .zshrc/.bashrc). If the MCP server fails to start with "docker: command not found", ensure your client is launched from a shell that has ~/.rd/bin on PATH (or symlink docker into /usr/local/bin). </details>
<details> <summary>Windows-specific gotchas</summary>
- Line endings: the repo ships .gitattributes forcing LF on shell + Node + config files. If you cloned with core.autocrlf=true (Git for Windows default) BEFORE these directives existed locally, run git add --renormalize . && git checkout . to fix any CRLF in your working tree, otherwise bash will choke on #!/usr/bin/env bash\r. - Docker Desktop file sharing: under Docker Desktop → Settings → Resources, enable the drive (non-WSL) or the WSL2 distro that contains your project. Without this, the workspace bind mounts empty and scan_documents / absorb_files see no source files. - Symlinks: the repo ships zero symlinks; do not introduce any locally without enabling Windows Developer Mode (or accept that Git will substitute a 1-line text file for the symlink target). </details>
./.memory/src/scripts/mcp-smoke.sh
The boilerplate is consumed as ./.memory/src/ inside your project, with its own git history retained for git pull updates. Two phases, drive each manually or via an AI prompt:
| Phase | What it does | Manual | AI-driven |
|---|---|---|---|
| **1. Host install** | clone, render configs, start Docker stack | [Manual install](#manual-install) | [🤖 AI-driven install](#-ai-driven-install) |
| **2. Dify onboarding** *(after MCP-client restart)* | API key, dataset slots, metadata schema, optional doc absorb | [Manual flow](#manual-flow) | [🤖 AI-driven flow](#-ai-driven-flow) |
Why two prompts? The MCP server only becomes callable AFTER your client (Claude Desktop, Cursor, Codex) restarts to pick it up. Phase 2 uses MCP tools (list_datasets,create_dataset,absorb_files, ...) that don't exist before that restart, so it can't share a session with Phase 1. Run Phase 1, restart your client, then run Phase 2.
```bash
Phase 1 of 2. Host-side install only (clone, bootstrap, docker stack up). Run Phase 2 AFTER the stack is up AND your MCP client restarts.
Paste this prompt into your agent (Claude Code, Cursor, Codex) running inside the target project root:
Install the local Dify MCP memory boilerplate into this project. Target the current working directory unless I explicitly give you another path.
Steps:
1. Confirm the boilerplate Git URL with me first if you cannot infer it. Default: https://github.com/ctxr-dev/memory
2. Ask me for the project slug. Lowercase ASCII a-z, 0-9, hyphen (e.g. billing-api, docs-site). If I give you a name, propose a sanitised slug derived from the project folder name and confirm. The slug becomes the per-project Docker container, image, and Compose project name, so multiple projects can run their own memory stacks without collisions.
3. Ask me which LLM provider to use for the flush + compile pipeline:
- claude (recommended; spawns `claude -p`, no API key needed)
- codex (spawns `codex exec --json`, no API key needed)
- anthropic (REST with ANTHROPIC_API_KEY in ./.memory/settings/.env)
- openai (REST with OPENAI_API_KEY in ./.memory/settings/.env)
Detect which CLIs are on PATH before asking. If only one is available, default to it and ask me to confirm.
4. Ask whether to install Claude Code hooks (default: yes). Hooks live in .claude/settings.json and wire SessionStart, PreCompact, PostCompact, SessionEnd, and PostToolUse (matcher ExitPlanMode, for auto-capturing approved plans into the `plans` slot) to ./.memory/src/scripts/hooks/. Other clients can adapt .agents/hooks.json manually.
5. Ask which MCP clients I want registered: Claude Desktop, Cursor, Codex/OpenAI, generic. Note the choices for step 8; the actual snippets only exist after bootstrap.sh runs.
6. Verify host prerequisites or tell me exactly what is missing:
- docker (Docker Desktop or engine) with `docker compose` 2.24.4+
- node 20+
- git, curl, bash 3.2+
bootstrap.sh itself only enforces docker + node + docker-compose-version; git and curl are needed by `git clone` and the Dify-version probe. No `jq`, `realpath`, or other extras are required (the install path is intentionally portable to Git Bash on Windows).
7. Run the install. If I chose Codex/OpenAI as a client in step 5 AND the `codex` CLI is on PATH, append `--register-codex` so bootstrap auto-runs `codex mcp add` for me; otherwise tell me to run that command manually after step 8:
git clone <boilerplate-git-url> ./.memory/src
./.memory/src/bootstrap.sh --slug <slug> --llm-provider <provider> [--no-hooks if I declined] [--register-codex if Codex picked]
8. Static verification only (Docker not yet required; the stack is not up yet):
bash -n ./.memory/src/bootstrap.sh ./.memory/src/scripts/*.sh ./.memory/src/scripts/hooks/*.sh
node --check ./.memory/src/scripts/compile.mjs ./.memory/src/scripts/hooks/flush.mjs ./.memory/src/scripts/hooks/session-start.mjs
node --check ./.memory/src/scripts/lib/*.mjs ./.memory/src/mcp-server/src/*.js
( cd ./.memory/src && npm test )
Then print the requested client snippets from `./.memory/src/.agents/clients/` (now that bootstrap has rendered them):
./.memory/src/scripts/mcp-config.sh all
For Codex (if not auto-registered in step 7):
codex mcp add <slug>-memory -- docker exec -i <slug>-memory node src/index.js
9. Start the stack. WARN ME this is slow on first run: dify-bootstrap clones the upstream Dify repo (~hundreds of MB) and `up.sh` then pulls and builds Dify + the bridge image (2-5 minutes on a cold pull, multi-GB; ~30-60s once the Docker image cache is warm):
./.memory/src/scripts/up.sh
(`up.sh` invokes `ui-url.sh` itself, so the Dify UI URL is printed when it finishes.)
10. Tell me the exact next steps after the stack is up:
a) Open the printed Dify UI URL.
b) Create the admin account, configure an embedding model under Settings -> Model Provider (REQUIRED before any high_quality dataset can be created).
c) Open Knowledge -> Service API, create a Knowledge API key.
d) Restart your MCP client (Claude Desktop / Cursor / Codex / your terminal-spawned agent) so it picks up the new memory MCP server. The server only becomes callable after this restart.
e) Run `./.memory/src/scripts/dify-setup.sh` to wire datasets, install the per-document metadata schema, and (optionally) absorb my existing docs. ALTERNATIVELY paste the second AI prompt from the README (under "Onboarding -> AI-driven flow") to a fresh agent session for an MCP-driven walkthrough that uses list_datasets / create_dataset / scan_documents / absorb_files instead of the wizard.
f) Final end-to-end smoke (only valid after step e): `./.memory/src/scripts/mcp-smoke.sh` — read-only round-trip across get_memory_config, search_memory (plain + filtered), and recall_lessons.
Stop and ask me whenever you would otherwise guess. Do not proceed past any step on assumption. Your config lives in `./.memory/settings/.env` (created from `.memory/src/.env.example`); the wizard (`dify-setup.sh`) manages it. If you must hand-edit, edit `./.memory/settings/.env` (there is no `.memory/src/.env`).
<details> <summary>Expand: atom types table</summary>
Seven atom types are produced by the flush LLM extractor (prompts/flush.md) and routed by compile. Each carries the metadata block (project_module, language, task_type, optional error_pattern) plus tags. The compile prompt biases toward update over create when atom_type, project_module, and (for lessons) error_pattern match: same fact never gets written twice; same lesson converges into one canonical document.
| Type | Use when | Routes to |
|---|---|---|
decision | "We chose X over Y because Z." Architectural or product choice with rationale. | knowledge |
bug-root-cause | The misleading symptom, the actual cause, and the trap to avoid. (Not the diff: that's in git.) | knowledge |
feedback-rule | A workflow rule the user gave you. Conventions, exit predicates, do/don't. | knowledge |
project-lore | Who's doing what, deadlines, integration quirks not in the code. Decays fast; atoms include dates. | knowledge |
reference | A pointer to a dashboard, runbook, or external project, with the reason to consult it. | knowledge |
pattern-gotcha | A reusable code-level lesson: API quirk, framework footgun, library behavior. | knowledge |
self-improvement-lesson | NEGATIVE OR CORRECTIVE user feedback revealing a behaviour the AI should change next time. | self_improvement |
</details>
bash -n ./.memory/src/bootstrap.sh ./.memory/src/scripts/.sh ./.memory/src/scripts/hooks/.sh node --check ./.memory/src/scripts/compile.mjs ./.memory/src/scripts/hooks/flush.mjs ./.memory/src/scripts/hooks/session-start.mjs node --check ./.memory/src/scripts/lib/.mjs ./.memory/src/mcp-server/src/.js
docker exec -i "$(grep '^MCP_CONTAINER_NAME=' ./.memory/settings/.env | cut -d= -f2 | tr -d '\r')" \ node src/memory-cli.js list-metadata-fields --datasetId self_improvement
<details> <summary>Expand: client config</summary>
Generated client snippets live under .agents/clients/ after bootstrap:
./.memory/src/scripts/mcp-config.sh all # print every client snippet
./.memory/src/scripts/mcp-config.sh codex # | claude-desktop | cursor
For Codex/OpenAI:
codex mcp add <project-slug>-memory -- docker exec -i <project-slug>-memory node src/index.js
For Claude Desktop, Cursor, or generic MCP clients, merge .agents/mcp.json (or the matching .agents/clients/<client> snippet) into your client's MCP config. Do not paste API keys into client configs; they live only in ./.memory/settings/.env.
When --install-hooks is on (default), .claude/settings.json is rendered with the four lifecycle events wired to ./.memory/src/scripts/hooks/. Other clients can adapt .agents/hooks.json to their own hook format; see STACK.md for the event-to-script table.
</details>
<details> <summary>Expand: hook reference table</summary>
| Event | Script | Effect |
|---|---|---|
SessionStart | scripts/hooks/session-start.mjs | Emits an additionalContext reminder; lazily spawns compile in the background once per UTC day. |
PreCompact | scripts/hooks/flush.mjs pre-compact | Distils the recent transcript into typed atoms; writes ONE new daily-<ts>.md doc to the Dify daily dataset. Skips if fewer than MEMORY_HOOK_PRECOMPACT_MIN_TURNS turns. |
PostCompact | scripts/hooks/flush.mjs post-compact | Distils Claude Code's compact_summary into atoms. Min-turns check bypassed for compact_summary input. |
SessionEnd | scripts/hooks/flush.mjs session-end | Same as PreCompact, with MEMORY_HOOK_SESSION_END_MIN_TURNS floor. |
PostToolUse (matcher ExitPlanMode) | scripts/hooks/exit-plan-mode.mjs | When the user approves a plan, upserts plan-<slug>.md into the plans dataset slot (deterministic, no LLM, no timestamp; same title overwrites). Body is redacted + wrapped in an untrusted-content fence. Skips cleanly (exit 0) with a stderr message on rejection, empty plan, oversized plan (MEMORY_HOOK_EXITPLANMODE_MAX_BYTES, default 256KB), unbound slot, bridge failure, or MEMORY_HOOK_EXITPLANMODE_DISABLE=true. See [plan-capture skill](templates/skills/plan-capture.md). |
Hook timeouts: 130s for flush hooks (LLM defaults to 120s per call + headroom), 30s for PostToolUse/ExitPlanMode (no LLM, but multiple bridge round-trips: find + create + metadata + re-list + dedupe-delete), 15s for SessionStart (only emits a reminder + spawns compile detached).
</details>
该工具提供了一种Inspectable 本地项目内存的方法,帮助开发者更好地理解 AI 编码代理的行为和决策过程,值得关注。
AI Skill Hub 为第三方内容聚合平台,本页面信息基于公开数据整理,不对工具功能和质量作任何法律背书。
建议在沙箱或测试环境中充分验证后,再部署至生产环境,并做好必要的安全评估。
✅ MIT 协议 — 最宽松的开源协议之一,可自由商用、修改、分发,仅需保留版权声明。
AI Skill Hub 点评:开源MCP工具 的核心功能完整,质量良好。对于Claude Desktop / Claude Code 用户来说,这是一个值得纳入个人工具库的选择。建议先在非生产环境试用,再逐步推广。
| 原始名称 | memory |
| Topics | mcpagentaidifyhooksllmjavascript |
| GitHub | https://github.com/ctxr-dev/memory |
| License | MIT |
| 语言 | JavaScript |
收录时间:2026-05-23 · 更新时间:2026-05-23 · License:MIT · AI Skill Hub 不对第三方内容的准确性作法律背书。
选择 Agent 类型,复制安装指令后粘贴到对应客户端