SimpleMem MCP服务器
A. 模型上下文协议(MCP) 服务器 简单Mem -基于语义无损压缩的LLM代理高效终身存储系统。
概述
SimpleMem MCP Server通过模型上下文协议展示了SimpleMem强大的内存功能,使Claude等AI助手能够:
- 存储对话 语义无损压缩
- 找回记忆 使用三阶段混合检索(语义+词汇+符号)
- 回答问题 基于长期记忆,在LoCoMo-10基准测试中F1得分为43.24%
- 管理原子内存条目 具有自动同指消解和时间锚定功能
主要特点
- 三级内存管道:
1. 语义结构化压缩:转换对话→ 原子性的、自足的事实 1. 多视图索引:语义(向量)+词汇(BM25)+符号(元数据) 1. 自适应查询感知检索:基于规划的分解+反思机制
- 高级加工:
- 会议决议(他/她→ 实际姓名) - 临时锚定(明天→ 绝对时间戳) - 使用可配置的workers进行并行处理 - 窗口化批处理,提高效率
- 演出:与全上下文方法相比,标记数减少30倍,检索精度更高
建筑
┌─────────────────────────┐
│ MCP Client │
│ (Claude, Cursor, etc) │
└───────────┬─────────────┘
│ stdio
▼
┌─────────────────────────────────┐
│ SimpleMem MCP Server (Node) │
│ - Tool handlers │
│ - Resource providers │
│ - Input validation (Zod) │
└───────────┬─────────────────────┘
│ spawn
▼
┌─────────────────────────────────┐
│ SimpleMem (Python) │
│ - Semantic compression │
│ - Hybrid retrieval │
│ - LanceDB vector store │
└─────────────────────────────────┘先决条件
- Node.js 18+和npm
- python 3.8+
- 简单Mem 已安装并配置
- OpenAI API密钥 (或兼容的LLM提供商)
安装
1.克隆和安装
cd SimpleMem-MCP
npm install
npm run build2.配置SimpleMem
确保SimpleMem设置正确:
# Navigate to SimpleMem directory
cd /path/to/SimpleMem
# Copy and configure config file
cp config.py.example config.py
# Edit config.py with your settings
# - OPENAI_API_KEY
# - LLM_MODEL (e.g., "gpt-4.1-mini")
# - EMBEDDING_MODEL (e.g., "Qwen/Qwen3-Embedding-0.6B")
# Install Python dependencies
pip install -r requirements.txt3.设置环境变量
创建一个 .env SimpleMem MCP目录中的文件:
cp .env.example .env编辑 .env:
# Path to SimpleMem project directory
SIMPLEMEM_PATH=/Users/jiaqi/Myprojects/new/SimpleMem
# Path to LanceDB database directory (relative to SimpleMem)
SIMPLEMEM_DB_PATH=./lancedb_data
# Python executable (optional)
PYTHON_PATH=python3用法
Claude桌面配置
添加到您的Claude Desktop配置文件中:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json 视窗: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"simplemem": {
"command": "node",
"args": ["/path/to/SimpleMem-MCP/dist/index.js"],
"env": {
"SIMPLEMEM_PATH": "/path/to/SimpleMem",
"SIMPLEMEM_DB_PATH": "./lancedb_data"
}
}
}
}重新启动克劳德桌面
保存配置后,重新启动Claude Desktop以加载MCP服务器。
可用工具
1. add_dialogue
在内存系统中添加一个对话。
参数:
speaker(必填):发言者姓名content(必填):说了什么(最多200k个字符)timestamp(可选):ISO 8601时间戳(例如,“2025-11-15T14:30:00”)
示例:
User: "Remember this conversation. Alice said: 'Bob, let's meet at Starbucks tomorrow at 2pm.'"2. add_dialogues
批量添加多个对话(更高效)。
参数:
dialogues(必填):对话对象数组
示例:
{
"dialogues": [
{
"speaker": "Alice",
"content": "Bob, let's meet at Starbucks tomorrow at 2pm",
"timestamp": "2025-11-15T14:30:00"
},
{
"speaker": "Bob",
"content": "Sure, I'll bring the market analysis report",
"timestamp": "2025-11-15T14:31:00"
}
]
}3. finalize
将所有缓冲对话处理为内存条目。 重要:始终在添加对话后调用此命令。
SimpleMem使用窗口处理(默认值:每个窗口40个对话),因此这可以确保所有对话都得到处理。
4. ask
向记忆系统提问。
参数:
question(必填):您的问题(最多10k个字符)
运作原理:
- 分析查询复杂性
- 生成有针对性的搜索查询(计划)
- 从语义+词汇+符号层检索
- 反映充分性(可选迭代细化)
- 综合简明答案
示例:
User: "When and where will Alice and Bob meet?"
Assistant: "16 November 2025 at 2:00 PM at Starbucks"5. search_memories
没有答案合成的语义搜索(原始记忆条目)。
参数:
query(必填):搜索查询top_k(可选):结果数量(默认值:10,最大值:100)
用例:探索系统对某个主题的记忆。
6. get_all_memories
检索所有原子内存条目。
退货:完整的回忆列表,包括:
- 无损重述(自足事实)
- 关键词
- 时间戳(如果可用)
- 位置(如有提及)
- 相关人员
- 实体(公司、产品等)
- 主题
7. clear_memories
清除数据库中的所有内存。 ⚠️ 警告:无法撤消!
可用资源
1. simplemem://memories
类型:JSON 描述:所有内存条目的完整列表
访问克劳德:
User: "Can you show me all memories as JSON?"2. simplemem://stats
类型:JSON 描述:系统统计和配置
退货:
{
"total_memories": 42,
"db_path": "./lancedb_data",
"model": "gpt-4.1-mini",
"features": {
"planning_enabled": true,
"reflection_enabled": true,
"parallel_processing": true
}
}工作流示例
# Step 1: Add conversations
User: "Remember this: Alice said to Bob, 'Let's meet at Starbucks tomorrow at 2pm to discuss the project.'"
Assistant: [Uses add_dialogue tool]
User: "Bob replied: 'Great, I'll bring the market analysis report.'"
Assistant: [Uses add_dialogue tool]
# Step 2: Finalize processing
Assistant: [Calls finalize tool automatically]
# Step 3: Query memories
User: "What did Alice and Bob plan?"
Assistant: [Uses ask tool] → "Alice and Bob plan to meet at Starbucks on 16 November 2025 at 2:00 PM to discuss the project. Bob will bring the market analysis report."
# Step 4: Explore memories
User: "Show me all memories about meetings"
Assistant: [Uses search_memories tool with query="meetings"]SimpleMem的工作原理
第一阶段:语义结构化压缩
输入 (对话):
Alice: "He'll meet Bob tomorrow at 2pm at the coffee shop"输出 (原子内存条目):
{
"lossless_restatement": "John will meet Bob at Starbucks on 2025-11-16T14:00:00",
"persons": ["John", "Bob"],
"location": "Starbucks",
"timestamp": "2025-11-16T14:00:00",
"keywords": ["meet", "Bob", "John", "Starbucks"]
}变换:
- 核心决议:“他”→ “约翰”
- 临时锚定:“明天下午2点”→ “2025-16T14:00:00”
- 位置规范化:“咖啡店”→ “星巴克”(根据上下文)
第二阶段:多视图索引
每个内存都跨三个维度进行索引:
| 图层 | 类型 | 用途 |
|---|---|---|
| 语义 | 密集(1024-d) | 概念相似性 |
| 词汇的 | 稀疏(BM25) | 精确匹配关键字 |
| 象征性的 | 元数据 | 结构化过滤 |
第三阶段:自适应检索
简单查询 (低复杂性):
"When will they meet?" → Single semantic search复杂查询 (高复杂性):
"What projects did Alice and Bob discuss in November at Starbucks?"
→ Multi-query decomposition:
1. Semantic: "Alice Bob projects discuss"
2. Symbolic: persons=["Alice","Bob"], location="Starbucks", time=November
3. Keyword: ["projects", "discuss"]
→ Reflection: Check if results adequate, generate follow-up if needed
→ Synthesis: Combine results and generate answer性能基准
LoCoMo-10 数据集 (GPT-4.1分钟):
- F1得分: 43.24%
- 令牌使用情况:约550个令牌(比完整上下文少30倍)
- 检索时间:完整基准测试为388.3秒
比较:
- Mem0:34.20%F1,1350.9秒结构
- A-Mem:32.58%F1,5140.5秒施工
- LightMem:24.63%F1,577.1s检索
配置选项
SimpleMem行为通过以下方式控制 config.py 在SimpleMem目录中:
# Core Models
LLM_MODEL = "gpt-4.1-mini" # or "qwen-max", "gpt-4"
EMBEDDING_MODEL = "Qwen/Qwen3-Embedding-0.6B"
# Processing
WINDOW_SIZE = 40 # Dialogues per processing window
OVERLAP_SIZE = 2 # Window overlap for context
# Retrieval
SEMANTIC_TOP_K = 25 # Vector search results
KEYWORD_TOP_K = 5 # BM25 results
STRUCTURED_TOP_K = 5 # Metadata filter results
# Advanced Features
ENABLE_PLANNING = True # Multi-query decomposition
ENABLE_REFLECTION = True # Iterative refinement
MAX_REFLECTION_ROUNDS = 2 # Max reflection iterations
ENABLE_PARALLEL_PROCESSING = True
MAX_PARALLEL_WORKERS = 16 # Memory building workers
ENABLE_PARALLEL_RETRIEVAL = True
MAX_RETRIEVAL_WORKERS = 8 # Retrieval workers故障排除
服务器未启动
检查:
- Node.js版本:
node --version(应该是18+) - TypeScript编译:
npm run build - 环境变量设置正确
- SimpleMem路径存在且可访问
Python执行失败
检查:
- Python版本:
python3 --version(应为3.8+) - 已安装SimpleMem依赖项:
pip install -r requirements.txt config.py存在并且具有有效的API密钥- Python包含SimpleMem目录
没有回忆回来
民事诉讼:
- 忘记打电话了
finalize添加对话后 - 数据库路径不正确
- 嵌入模型未下载(首次运行可能需要时间)
- LanceDB数据库已损坏(请尝试清除并重新添加)
性能缓慢
优化:
- 使用较小的LLM进行压缩(例如“qwen2.5-1.5b”)
- 减少
SEMANTIC_TOP_K为了更快地检索 - 禁用反射:
ENABLE_REFLECTION = False - 增加并行工作者(如果您有可用的核心)
发展
构建
npm run build观看模式(用于开发)
npm run dev手动测试
# Start server (outputs to stderr for debugging)
node dist/index.js
# The server expects JSON-RPC messages on stdin
# Use MCP Inspector for interactive testing:
npx @modelcontextprotocol/inspector node dist/index.js项目结构
SimpleMem-MCP/
├── src/
│ ├── index.ts # Main MCP server (tools, resources, handlers)
│ ├── simplemem-client.ts # Python SimpleMem wrapper
│ └── types.ts # TypeScript interfaces
├── dist/ # Compiled JavaScript (generated)
├── package.json # Dependencies and scripts
├── tsconfig.json # TypeScript configuration
├── .env.example # Environment template
├── .gitignore
└── README.md # This file参考文献
- SimpleMem纸张: arXiv:2601.02553
- SimpleMem GitHub: AIMING实验室/SimpleMem
- MCP文件: 模型上下文协议
- MCP-SDK: @模型上下文协议/sdk
许可证
MIT许可证-详见SimpleMem项目。
引用
如果您在研究中使用SimpleMem,请引用:
@misc{simplemem2026,
title={SimpleMem: Efficient Lifelong Memory for LLM Agents via Semantic Lossless Compression},
author={AIMING Lab},
year={2026},
eprint={2601.02553},
archivePrefix={arXiv}
}支持
- SimpleMem问题:
- MCP问题:
______________________________________________________________________
建于❤️ 使用模型上下文协议
