mem0-lite
mem0-lite
通过 MCP 为编码代理提供自托管的记忆功能。无需 Docker。无需 Mem0 平台。无需 REST 守护进程。
该 MCP 封装了 mem0ai 的 Memory(),向量数据存储在磁盘上的 ~/.mem0/qdrant 目录下。工具调用在进程内完成。侧车保持 Qdrant 打开状态;第二个 MCP 在同一目录下通过 lite.lock / lite.want 进行协调——无需额外的守护进程。
为什么存在
官方 Mem0 提供了三个组件,但它们并不适合本地 MCP 环境的组合使用:
官方路径 | 此处的问题 |
平台 MCP ( | 记忆数据离开你的机器,需要付费。 |
开源 REST 服务器 | 需要 Docker + Postgres;重量级,难以维护,在非 Linux 机器上消耗电池。 |
| 仅客户端,不包含服务器 |
mem0-lite 是一个轻量级的本地 Python 应用,将开源 mem0 库作为 MCP 服务暴露出来。
Related MCP server: int
你得到什么
MCP 工具 —
add_memory、search_memories、get_memory_by_id、list_memories、update_memory、delete_memory、delete_all_memories(调用方式见工具文档)本地存储 — 磁盘上的 Qdrant(
on_disk=True),非/tmp,具有并发协调机制使用时机 — 精简的 AGENTS.md 指引
MCP 注册 — uv 启动片段
存储内容
向量数据库、历史记录、配置、访问日志、lite.lock 和 lite.want 均存储在 ~/.mem0 目录下
安装
需要 uv、Python 3.11+ 和 OPENAI_API_KEY(或 Ollama——参见 架构)。
克隆此仓库。
向你的主机注册 MCP 服务器(见下方片段)。在主机配置或系统环境中设置
OPENAI_API_KEY;不要提交到版本控制。粘贴 AGENTS.md 指引。
环境变量
MCP 从进程环境中读取以下变量。如果某个变量已在系统环境中设置,并且 MCP 未在沙箱中运行,主机将直接传递该变量——你无需在主机 env 块中重复设置。该 env 块中的值会覆盖系统环境中的值。
OPENAI_API_KEY— 必需,除非使用 Ollama(见下文)MEM0_DIR— 数据目录(默认~/.mem0)MEM0_LITE_USER_ID— 默认用户作用域(默认$USER)MEM0_LITE_AGENT_ID— 可选的代理作用域MEM0_LITE_LOCK_TIMEOUT— 存储锁等待时间(秒,默认30)MEM0_LITE_LLM_PROVIDER— 例如ollama(默认:通过 mem0ai 使用 OpenAI)MEM0_LITE_LLM_MODEL— 大模型名称(使用 Ollama 时默认llama3.2)MEM0_LITE_EMBEDDER_PROVIDER— 例如openai或ollamaMEM0_LITE_EMBEDDER_MODEL— 嵌入模型(使用 Ollama 时默认nomic-embed-text)
完整默认值:架构。可选评分:反馈模式(MEM0_LITE_FEEDBACK_MODE,默认关闭)。
MCP 注册
合并到你的 MCP 主机配置文件中。Cursor:~/.cursor/mcp.json 或项目根目录下的 .cursor/mcp.json。替换目录路径。
{
"mcpServers": {
"mem0-lite": {
"command": "uv",
"args": ["run", "--directory", "/ABS/PATH/TO/mem0-lite", "mem0-lite", "mcp"],
"env": { "OPENAI_API_KEY": "sk-..." }
}
}
}AGENTS.md
粘贴到 AGENTS.md(或用户规则中)。工具的具体调用方式在 MCP schemas 中。以下说明何时使用。
## Memory
MCP `mem0-lite` is registered. Search at task start, context switch, or when the user references past work. After the reply, write only if a new agent would benefit in days/weeks (future utility, novelty, factual, no secrets). Do not announce recall. Prefer `update_memory`. Most turns write nothing.指标
每次工具调用都会向 ~/.mem0/access-log.jsonl 追加一行(工具、代理、连接复用、锁等待、耗时)。汇总:
uv run python scripts/access-report.py反馈模式
追踪记忆存储的有效性。
启用后,工具响应中包含 ts 字段,可用于通过 rate_memory_call 工具对响应进行评分。
启用后(MEM0_LITE_FEEDBACK_MODE=1):
检索响应中包含
ts代理可以在命中、未命中或噪声后调用
rate_memory_call(call_ts, helpful, reason)评分追加到
~/.mem0/feedback.jsonlscripts/access-report.py将评分与访问日志中的ts关联,并报告覆盖率、有效率和反馈延迟(ts − call_ts)
在主机的 env 块中启用(不要将其放入默认注册片段中):
"env": {
"OPENAI_API_KEY": "sk-...",
"MEM0_LITE_FEEDBACK_MODE": "1"
}如果启用,请在 AGENTS.md 中添加此内容。
After a retrieval call, if you used a hit, clearly missed a fact, or got noise, call rate_memory_call with that response's ts.reason 的值为:used | empty_ok | miss | noise | stale | bad_query。跳过预期为空的空结果。 n
| 文档 | n| 架构 | 进程模型、工具、数据布局 | n| 替代 Mem0 架构 | 平台、Docker REST、SDK 进程内、此仓库 | n| 替代存储 | 文件、SQLite、向量数据库、托管内存 | n| 决策 | 为什么选择 MCP,为什么infer=false,为什么不是 REST | n| 坑点 | 密钥在 git 中,/tmp Qdrant,CLI 作为工具,查询重写 | n
非此仓库范围
第二个 Mem0 服务器实现
与平台兼容的 HTTP API
mem0-cli的替代品图记忆(实际上仅限平台)
此仓库采用 MIT 许可证。mem0ai 仍为 Apache-2.0。此封装文件归你所有,可保持本地使用。
Available Tools
8 toolsadd_memoryA
Store a memory. Prefer infer=false with a self-contained third-person fact.
memory_type: decision | convention | anti_pattern | user_preference | task_learning | environmental | identity | rule | project
infer=true lets mem0 extract facts from raw conversation; skip for explicit facts.
Never store secrets. Skip small talk, tool dumps, and one-shot commands.
Inputs: text (required), infer, user_id, agent_id, +2 more. Returns: result
delete_all_memoriesC
Delete all memories in scope. Requires confirm=true.
Inputs: confirm, user_id, agent_id. Returns: result
delete_memoryC
Delete one memory by id.
Inputs: memory_id (required). Returns: result
get_memory_by_idA
Fetch one memory by id. When MEM0_LITE_FEEDBACK_MODE is enabled, rate via rate_memory_call(call_ts).
Inputs: memory_id (required). Returns: result
list_memoriesC
List memories in scope. Not a substitute for search_memories. When MEM0_LITE_FEEDBACK_MODE is enabled, responses include ts; rate useful/miss/noise via rate_memory_call.
Inputs: top_k, user_id, agent_id, memory_type. Returns: result
rate_memory_callA
Rate a prior retrieval by call_ts (from response ts when MEM0_LITE_FEEDBACK_MODE is enabled).
Call when you used a hit, clearly missed a fact, or got irrelevant noise. Skip empty-and-expected results.
reason: used | empty_ok | miss | noise | stale | bad_query
Inputs: reason (required), call_ts (required), helpful (required), note. Returns: result
search_memoriesA
Semantic search. Rewrite the query to 3-6 keywords matching stored third-person facts.
Do not pass the user's raw message. Drop pronouns and question words.
When useful, run 2-4 parallel searches with memory_type: decision, convention, anti_pattern, or omit for catch-all.
When MEM0_LITE_FEEDBACK_MODE is enabled, responses include ts; rate useful/miss/noise via rate_memory_call.
Inputs: query (required), top_k, user_id, agent_id, +1 more. Returns: result
update_memoryA
Replace memory text in place. Prefer this over delete+add when a fact changed.
Inputs: text (required), memory_id (required). Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 8 tools
Each tool has a clearly distinct purpose: add, update, search, get by ID, list, delete single, delete all, and rate. Potential confusion between search_memories and list_memories is addressed in descriptions, ensuring no ambiguity.
All tool names follow a consistent verb_noun pattern in snake_case (e.g., update_memory, search_memories, delete_all_memories). The naming is predictable and uniform across the set.
With 8 tools, the server is well-scoped for a memory management system. The count covers essential operations without being excessive or insufficient.
The tool surface provides complete coverage for memory CRUD (add, get, update, delete) plus search, listing, bulk deletion, and a feedback rating mechanism. No obvious gaps for the declared purpose.
Maintenance
Related MCP Connectors
Hosted MCP memory for coding agents: persistent across sessions, editable markdown, team sharing.
Hosted memory for AI agents over MCP. One memory shared by all your agents.
Persistent memory, knowledge graph, task management and more for AI agents via MCP.
Persistent, inspectable memory for AI agents with lineage, correction, and a hosted MCP endpoint.
Related MCP Servers
- AlicenseNot gradedqualityAmaintenanceProvides persistent memory for AI coding agents via MCP, enabling agents to store and semantically recall facts, events, and lessons across sessions, all running locally without cloud dependencies.Apache 2.0
- FlicenseNot gradedqualityCmaintenanceSelf-hosted AI memory system for coding assistants, providing project-scoped memory storage and retrieval via MCP tools (add, search, list, delete) to recall prior learnings without re-running discovery.1-
- AlicenseNot gradedqualityBmaintenanceProvides persistent memory for AI coding agents, enabling them to save, search (hybrid vector/BM25/concept graph), list sessions, and forget memories via MCP tools.11 npmApache 2.0
- FlicenseNot gradedqualityAmaintenanceEnables AI coding agents to store, search, and recall persistent project and cross-project memories locally over MCP, keeping architectural decisions, conventions, and error patterns available across sessions. Also optionally exposes a task server for autonomous task execution driven by that same memory store.-