mcp学习记忆
适应你的反馈的记忆。
  
这是什么?
MCP(模型上下文协议)服务器,为AI助手提供具有学习能力的持久内存。保存见解,跟踪反馈,让系统了解哪些信息随着时间的推移是有价值的。
图案:索引→ 细节
list_index返回标题和预览(便宜、快速、带过滤)search_insights通过上下文排名找到相关见解get_detail仅在需要时加载完整内容(按需)
独特功能
信任评分
根据用户反馈计算出的信任分数对见解进行排名:
trustScore = (helpful - harmful × 2) / (helpful + harmful + 1)- 更严厉地惩罚有害反馈(×2权重)
- 得分为负的见解会发出警告
- 增强搜索结果中的可靠信息
衰减因子
较旧的见解逐渐失去排名优先级:
- 新见解(\ RPC
Desktop --> RPC RPC --> Index Index --> Tools Tools --> Features Tools --> JSON
## 安装
### 先决条件
- Node.js 18+
- Claude CLI或Claude桌面
### 从源代码构建
git clone https://github.com/nulone/mcp-learning-memory cd mcp-learning-memory npm install npm run build npm test # 81 tests should pass
## 配置
### Claude CLI
Add MCP server
claude mcp add learning-memory node /path/to/mcp-learning-memory/dist/index.js
Verify
claude /mcp # Should show: learning-memory · ✔ connected
或手动编辑 `~/.claude.json`:
{ "mcpServers": { "learning-memory": { "command": "node", "args": ["/path/to/mcp-learning-memory/dist/index.js"] } } }
### 克劳德桌面版
**macOS:** `~/Library/Application Support/Claude/claude_desktop_config.json`
**Linux:** `~/.config/Claude/claude_desktop_config.json`
**窗户:** `%APPDATA%\Claude\claude_desktop_config.json`
{ "mcpServers": { "learning-memory": { "command": "node", "args": ["/path/to/mcp-learning-memory/dist/index.js"] } } }
编辑后重新启动Claude Desktop。
## 用法
### 自然语言(通过克劳德)
Save an insight "React hooks tips" with tags react, hooks and content "Always call hooks at top level"
Show all my insights
Mark the React insight as helpful
Delete the outdated insight
Export my memory as markdown
### 直接工具调用
Add new insight with source URL
add_insight: title="JWT Auth Pattern", tags=["auth","jwt"], content="Use refresh tokens...", sourceUrl="https://example.com/article"
List with filters
list_index: tags=["auth"], sortBy="helpful", limit=10
Search with ranking (uses trust score + decay)
search_insights: query="authentication", limit=5
Get full content
get_detail: id="ace-000001"
Provide feedback
mark_helpful: id="ace-000001" mark_harmful: id="ace-000002"
Delete insight
delete_insight: id="ace-000003"
Export for backup
export_memory: format="markdown"
## API 参考
### `add_insight`
将新的见解保存在记忆中。
|参数|类型|必填|说明|
|-----------|------|----------|-------------|
|title |字符串|✅ | 短标题(修剪后1-200个字符)|
|标签|字符串\[\]|✅ | 类别标签(1-10个项目,标准化)|
|内容|字符串|✅ | 完整内容(修剪后最多10000个字符)|
|覆盖|布尔值|❌ | 用相同的标题更新现有的见解|
|sourceUrl|字符串|❌ | 可追溯性的源URL(最多2000个字符)|
**自动重复数据删除:**
- 使用Levenshtein距离(\<3)检测相似的标题
- 不区分大小写的比较
- 发现重复时返回现有洞察ID
- 使用 `overwrite=true` 有意更新
**示例:**
Basic insight
add_insight: title="React Tips", tags=["react"], content="Use memo for expensive renders"
With source URL
add_insight: title="API Design", tags=["api","rest"], content="...", sourceUrl="https://docs.example.com"
Overwrite existing
add_insight: title="React Tips", tags=["react","hooks"], content="Updated content", overwrite=true
### `list_index`
列出所有见解,包括元数据和内容预览。
|参数|类型|必填|说明|
|-----------|------|----------|-------------|
|标签|字符串\[\]|❌ | 按标签筛选(AND逻辑)|
|min有用|号码|❌ | 最小帮助计数(默认值:0)|
|sortBy |字符串|❌ | 排序: `created`, `lastUsed`, `helpful` (默认值: `lastUsed`) |
|限制|数量|❌ | 最大结果(默认值:50)|
**答复包括:**
- 内容预览(100个字符)
- 信任评分(计算)
- 低信任洞察力警告
- 源URL(如果存在)
### `get_detail`
加载见解的全部内容。更新 `lastUsed` 时间戳。
|参数|类型|必填|说明|
|-----------|------|----------|-------------|
|id |字符串|✅ | 洞察ID(例如ace-00001)|
### `mark_helpful`
递增有用计数器(+1)。更新 `lastUsed` 时间戳。
|参数|类型|必填|说明|
|-----------|------|----------|-------------|
|id |字符串|✅ | 洞察ID|
### `mark_harmful`
递增有害计数器(+1)。用于过时/不正确的信息。
|参数|类型|必填|说明|
|-----------|------|----------|-------------|
|id |字符串|✅ | 洞察ID|
### `search_insights`
使用信任评分和衰减因子进行上下文排名搜索。
|参数|类型|必填|说明|
|-----------|------|----------|-------------|
|查询|字符串|✅ | 搜索查询(搜索标题、内容、标签)|
|限制|数量|❌ | 最大结果(默认值:5)|
**评分算法:**
- 标题匹配:+10分
- 部分冠军赛:+5分
- 内容匹配:+3分
- 标签匹配:每个标签+2分
- 帮助计数:每帮助一人得+1分
- 最近使用(7天):+3分
- 信任分数奖励:+trustScore×5
- 衰变因子:分数×最大值(0.1,1天龄/90)
### `delete_insight`
永久删除见解。
|参数|类型|必填|说明|
|-----------|------|----------|-------------|
|id |字符串|✅ | 要删除的洞察ID|
### `export_memory`
导出所有见解以进行备份或记录。
|参数|类型|必填|说明|
|-----------|------|----------|-------------|
|格式|字符串|❌ | `json` (默认)或 `markdown` |
**Markdown格式包括:**
- 每个见解的信任度得分
- 源URL
- 统计数据(有用/有害计数)
## 数据存储
**地点:** `$XDG_DATA_HOME/ace-flash-memory/memory.json`
- Linux/macOS默认设置: `~/.local/share/ace-flash-memory/memory.json`
**自动恢复:**
- 损坏的文件会使用时间戳进行备份
- 系统继续使用空内存
- 不会因临时损坏而丢失数据
## 发展
npm install npm run build npm test # 81 integration tests
Verify no console.log (MCP requires stderr only)
grep -r "console.log" src/ # Should be empty
### 项目结构
mcp-learning-memory/ ├── src/ │ ├── index.ts # MCP server entry point │ ├── tools.ts # 8 tool implementations + Mutex │ ├── storage.ts # Atomic file I/O + recovery │ ├── validation.ts # Input validation & normalization │ ├── logger.ts # stderr-only logging │ └── types.ts # TypeScript interfaces ├── tests/ │ └── integration.test.ts # 81 tests in isolated env ├── dist/ # Compiled JavaScript ├── package.json └── tsconfig.json
## 安全功能
### 无stdout污染
MCP使用stdout进行JSON-RPC。所有日志记录都会进入stderr。
### 静音保护
并发请求被序列化以防止丢失更新。
### 原子写入
写入时使用临时文件+重命名模式以确保碰撞安全。
### 隔离测试
测试在临时目录中运行以保护用户数据。
## 故障排除
### MCP未连接
Check if server starts
node dist/index.js
Should see: [INFO] server running
Verify config path is absolute
cat ~/.claude.json
### 数据不持久
ls -la ~/.local/share/ace-flash-memory/ cat ~/.local/share/ace-flash-memory/memory.json
### 损坏的数据
List backups
ls ~/.local/share/ace-flash-memory/*.corrupt.*
Restore if needed
cp memory.json.corrupt.TIMESTAMP memory.json
## 许可证
麻省理工学院
## 学分