内容
# 内存银行 MCP
[](https://www.npmjs.com/package/@diazstg/memory-bank-mcp)
[](https://github.com/diaz3618/memory-bank-mcp/actions/workflows/semgrep.yml)
[](https://opensource.org/licenses/MIT)
<a href="https://glama.ai/mcp/servers/@diaz3618/memory-bank-mcp">
<img width="380" height="200" src="https://glama.ai/mcp/servers/@diaz3618/memory-bank-mcp/badge" />
</a>
一个 MCP 服务器,为 AI 助手提供跨会话的持久内存。它将项目上下文、决策和进度存储在结构化的 Markdown 文件中 — 本地或通过 SSH 在远程服务器上。
> **相关仓库:**
>
> - **HTTP + Postgres + Redis 变体** → [diaz3618/memory-bank-mcp-http](https://github.com/diaz3618/memory-bank-mcp-http) — 使用 HTTP 传输的 Docker 部署
> - **VS Code 扩展** → [diaz3618/Memory-Bank-VSCode-Ext](https://github.com/diaz3618/Memory-Bank-VSCode-Ext) — 侧边栏 UI 和 GitHub Copilot 集成
## 快速开始
```bash
# 直接运行(无需安装)
npx @diazstg/memory-bank-mcp
# 或全局安装
npm install -g @diazstg/memory-bank-mcp
```
### 通过 Smithery(Claude Desktop)
```bash
npx -y @smithery/cli install @diazstg/memory-bank-mcp --client claude
```
## 配置
将以下内容添加到编辑器的 MCP 配置(`.vscode/mcp.json`、Cursor、Claude Desktop 等):
```json
{
"servers": {
"memory-bank-mcp": {
"command": "npx",
"args": ["-y",
"@diazstg/memory-bank-mcp",
"--username",
"你的用户名"
],
"type": "stdio"
}
}
}
```
> **提示**:强烈建议包含 `--username` 以进行正确的进度跟踪。
### 常见选项
```bash
npx @diazstg/memory-bank-mcp --username "github-用户" # 用于进度跟踪的用户名(推荐)
npx @diazstg/memory-bank-mcp --mode code # 设置操作模式
npx @diazstg/memory-bank-mcp --path /我的/项目 # 自定义项目路径
npx @diazstg/memory-bank-mcp --folder 我的内存 # 自定义文件夹名称(默认:memory-bank)
npx @diazstg/memory-bank-mcp --help # 所有选项
```
### 远程服务器(SSH)
将您的内存银行存储在远程服务器上:
```bash
npx @diazstg/memory-bank-mcp --remote \
--remote-user 用户名 \
--remote-host 示例.com \
--remote-path /home/用户名/内存银行 \
--ssh-key ~/.ssh/id_ed25519
```
参见 [远程服务器指南](docs/guides/remote-server.md)。
## 工作原理
内存银行将项目上下文存储为 `memory-bank/` 目录中的 Markdown 文件:
| 文件 | 目的 |
|------|---------|
| `产品上下文.md` | 项目概述、目标、技术栈 |
| `活动上下文.md` | 当前状态、正在进行的任务、下一个步骤 |
| `进度.md` | 更新的按时间顺序记录 |
| `决策日志.md` | 带有上下文和理由的决策 |
| `系统模式.md` | 架构和代码模式 |
AI 助手在每次会话开始时读取这些文件,并在工作过程中更新它们,从而在对话中保持连续性。
## MCP 工具
| 工具 | 描述 |
|------|-------------|
| `initialize_memory_bank` | 创建一个新的内存银行 |
| `get_memory_bank_status` | 检查当前状态 |
| `read_memory_bank_file` | 读取特定文件 |
| `write_memory_bank_file` | 写入/更新文件 |
| `track_progress` | 添加进度条目 |
| `log_decision` | 记录决策 |
| `update_active_context` | 更新当前上下文 |
| `switch_mode` | 更改操作模式 |
| `graph_upsert_entity` | 创建或更新知识图谱实体 |
| `graph_add_observation` | 向实体添加观察结果 |
| `graph_link_entities` | 在实体之间创建关系 |
| `graph_search` | 按名称或类型搜索实体 |
| `graph_open_nodes` | 获取特定实体的完整详细信息 |
| `graph_compact` | 紧凑事件日志 |
## 模式
| 模式 | 焦点 |
|------|-------|
| `code` | 实现和开发 |
| `architect` | 系统设计和规划 |
| `ask` | 问答和信息检索 |
| `debug` | 故障排除和诊断 |
| `test` | 测试和质量保证 |
可以通过 CLI (`--mode code`)、工具调用 (`switch_mode`) 或 `.mcprules-[mode]` 文件设置模式。参见 [使用模式](docs/guides/usage-modes.md)。
## 作为库
```typescript
import { MemoryBankServer } from "@diazstg/memory-bank-mcp";
const server = new MemoryBankServer();
server.run().catch(console.error);
```
## 文档
| 主题 | 链接 |
|-------|------|
| 快速入门 | [npx 使用](docs/getting-started/npx-usage.md)、[使用 Bun 构建](docs/getting-started/build-with-bun.md)、[自定义文件夹](docs/getting-started/custom-folder-name.md) |
| 指南 | [远程服务器](docs/guides/remote-server.md)、[使用模式](docs/guides/usage-modes.md)、[状态系统](docs/guides/memory-bank-status-prefix.md)、[调试 MCP](docs/guides/debug-mcp-config.md) |
| 集成 | [VS Code/Copilot](docs/integration/vscode-copilot-integration.md)、[Claude Code](docs/integration/claude-code-integration.md)、[Cursor](docs/integration/cursor-integration.md)、[Cline](docs/integration/cline-integration.md)、[Roo Code](docs/integration/roo-code-integration.md)、[通用 MCP](docs/integration/generic-mcp-integration.md) |
| 参考 | [MCP 协议](docs/reference/mcp-protocol-specification.md)、[规则格式](docs/reference/rule-formats.md)、[文件命名约定](docs/reference/file-naming-convention.md) |
| 开发 | [架构](ARCHITECTURE.md)、[测试](docs/development/testing-guide.md)、[日志系统](docs/development/logging-system.md) |
## 替代方案:HTTP + PostgreSQL + Redis
[`feature/http-postgres-redis-supabase`](https://github.com/diaz3618/memory-bank-mcp/tree/feature/http-postgres-redis-supabase) 分支提供了一个云原生变体,它用 HTTP Streamable MCP 传输、PostgreSQL(通过 Supabase 存储)和 Redis(用于缓存)取代了 stdio/本地文件系统。它专门通过 Docker 部署,**不** 发布到 npm。有关设置说明,请参见分支 README。
## 贡献
参见 [CONTRIBUTING.md](CONTRIBUTING.md)。
## 许可证
参见 [LICENSE](LICENSE)。