一个适用于Claude、ChatGPT和其他大型语言模型(LLM)的持久AI记忆的生产就绪型MCP(模型上下文协议)服务器。
Memory Forge 是一个完整的基础设施解决方案,它赋予AI助手持久的记忆和上下文感知能力。它包括:
curl -sSL https://raw.githubusercontent.com/cpretzinger/memory-forge/main/scripts/setup.sh | bash
git clone https://github.com/cpretzinger/memory-forge.git
cd memory-forge
npm install
npm run setup
memory-forge/
├── src/ # TypeScript源代码
│ ├── server.ts # 主MCP服务器
│ ├── handlers/ # 请求处理器
│ ├── storage/ # 存储适配器
│ └── types/ # TypeScript定义
├── docs/ # 文档
│ ├── SERVICES.md # 服务架构
│ ├── DOCKER.md # Docker设置指南
│ ├── RAILWAY.md # Railway部署
│ └── SMITHERY.md # Smithery部署
├── scripts/ # 设置及部署脚本
│ ├── setup.sh # 通用设置脚本
│ ├── deploy.ts # 部署辅助工具
│ └── test.ts # 系统测试脚本
├── config/ # 配置文件
│ ├── docker-compose.yml
│ ├── railway.toml
│ └── smithery.yml
└── examples/ # 示例实现
├── .env.example # 环境模板
└── claude-config.json
git clone https://github.com/cpretzinger/memory-forge.git
cd memory-forge
npm install
cp examples/.env.example .env
# 编辑.env文件以包含您的设置(参见配置部分)
npm run setup
# 这将:
# - 检查先决条件
# - 生成安全密码
# - 设置数据库
# - 配置服务
# - 启动所有服务
npm test
# 应显示所有服务为✅运行
从示例创建一个.env文件:
# 项目配置
PROJECT_NAME=my-ai-assistant
NODE_ENV=production
# 数据库凭证(由设置脚本生成)
POSTGRES_PASSWORD=<自动生成>
REDIS_PASSWORD=<自动生成>
QDRANT_API_KEY=<自动生成>
# MCP配置
MCP_AUTH_TOKEN=<自动生成>
MCP_PORT=3005
# API密钥(可选 - 添加您自己的)
OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=
添加到您的Claude桌面配置(~/.config/claude/claude_desktop_config.json):
{
"mcpServers": {
"memory-forge": {
"command": "node",
"args": ["/path/to/memory-forge/dist/bridge.js"],
"env": {
"MCP_SERVER_URL": "http://localhost:3005/mcp",
"MCP_AUTH_TOKEN": "your-token-here",
"AUTO_SAVE": "true"
}
}
}
}
npm run docker:up
# 在http://localhost:3005访问
npm run deploy:railway
# 按提示进行配置
npm run deploy:smithery
# 或使用Smithery CLI:
smithery publish cpretzinger/memory-forge
npm run deploy:vercel
# 在Vercel仪表板中配置环境变量
smithery search memory-forge
smithery install cpretzinger/memory-forge
{
"mcpServers": {
"memory-forge": {
"command": "npx",
"args": ["-y", "@smithery/memory-forge"],
"env": {
"API_KEY": "your-api-key"
}
}
}
}
smithery auth
name: memory-forge
version: 1.0.0
description: 普适AI记忆系统
author: yourname
runtime: typescript
smithery publish
| 服务 | 目的 | 端口 | 技术 |
|---|---|---|---|
| MCP 服务器 | 上下文API | 3005 | TypeScript/Express |
| PostgreSQL | 持久存储 | 5432 | PostgreSQL 16 |
| Redis | 缓存与会话 | 6379 | Redis 7 |
| Qdrant | 向量搜索 | 6333 | Qdrant |
| n8n | 自动化 | 5678 | n8n(可选) |
graph LR
A[Claude/LLM] -->|MCP协议| B[MCP服务器]
B --> C[Redis缓存]
B --> D[PostgreSQL]
B --> E[Qdrant向量]
C -->|快速读取| B
D -->|持久化| B
E -->|语义搜索| B
store_context存储对话上下文,带有自动保存
{
sessionId?: string, // 可选,未提供时自动生成
userId?: string, // 可选用户标识符
context: object, // 必需的上下文数据
metadata?: object // 可选元数据
}
retrieve_context检索对话上下文
{
sessionId?: string, // 可选,未提供时获取最新
userId?: string // 可选用户过滤器
}
search_context搜索所有上下文
{
query: string, // 必需的搜索查询
limit?: number, // 可选结果限制(默认:10)
semantic?: boolean // 使用向量搜索(默认:false)
}
list_sessions列出所有可用会话
{
userId?: string, // 可选用户过滤器
limit?: number // 可选限制(默认:10)
}
npm test
npm run test:mcp # 测试MCP服务器
npm run test:storage # 测试存储层
npm run test:e2e # 端到端测试
# 测试MCP端点
curl -X POST http://localhost:3005/mcp \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"tools/list","id":1}'
.env文件# 检查所有服务
npm run health
# 单独检查
curl http://localhost:3005/health
我们欢迎贡献!请参阅CONTRIBUTING.md了解指南。
# 安装开发依赖
npm install --save-dev
# 在开发模式下运行
npm run dev
# 使用热重载运行
npm run dev:watch
MIT许可证 - 详见LICENSE文件
Q: 服务无法启动?
# 重置一切
npm run reset
npm run setup
Q: 无法连接到MCP服务器?
# 检查是否在运行
npm run health
# 查看日志
docker logs memory-forge-mcp
Q: 如何升级?
git pull
npm install
npm run migrate
由Memory Forge团队用心打造