OpenMemory
AI memory engine exposed as an MCP server with structured knowledge capture, entity extraction, and hybrid search for persistent, portable memory across AI tools.
README
OpenMemory
AI memory engine exposed as an MCP server. Structured knowledge with server-side intelligence - domain routing, entity extraction, deduplication, and supersession. Any AI tool can query it. You own the data.
The Problem
AI agents can store knowledge, but existing approaches limit how effectively it can be structured and retrieved. Built-in memories like ChatGPT and Claude store flat text with no schema or relationships — and are not portable across tools. Developer libraries offer memory primitives but require significant integration work. Knowledge graph engines provide rich entity extraction at the cost of multiple LLM calls per ingestion and operational overhead. Lightweight solutions achieve cross-tool sharing but without structure, confidence scoring, or deduplication.
The common gap: structured, schema-driven knowledge with effective retrieval, working across any AI tool, without significant infrastructure cost.
The Solution
One place that accumulates structured knowledge - validated, owned by you - and every AI tool can query it with granular permissions. Works for personal identity, team knowledge, project context, or any use case where AI needs persistent memory.
Quick Start
Add to your AI tool's MCP configuration:
<!-- x-release-please-start-version -->
{
"mcpServers": {
"openmemory": {
"command": "npx",
"args": ["-y", "@openmem/mcp@0.2.0"]
}
}
}
<!-- x-release-please-end -->
Works with Claude Code, Claude Desktop, Cursor, and any MCP-compatible tool. Data is stored at ~/.openmemory by default. To change this, add "env": { "OPENMEMORY_DATA": "/absolute/path" } to the config above.
Disable your client's built-in memory. OpenMemory replaces it — running both fragments your knowledge across two systems. In Claude Desktop: Settings → Memory → off. In ChatGPT: Settings → Personalisation → Memory → off. This ensures OpenMemory is the single source of truth.
How It Works
OpenMemory captures knowledge through two complementary paths:
-
Fast capture — During conversation, the AI calls
capture_factwhenever it learns something useful. Facts are stored immediately in a session staging buffer. -
Batch consolidation — Periodically, the server processes all pending facts as a batch: classifying domains, extracting entities (people, places, organisations), detecting duplicates and contradictions, and building a knowledge graph.
Optionally, the server can also scan raw conversation events during consolidation to extract facts the AI missed — a safety net that ensures important knowledge isn't lost.
The result is a structured, evolving knowledge graph that any AI tool can query via MCP.
Features
- Hybrid knowledge capture — AI explicitly captures facts during conversation. Optionally, the server can also extract facts from raw events during consolidation as a safety net.
- Batch consolidation — Periodic processing integrates pending captures into the long-term knowledge graph: classifies domains, extracts entities, resolves duplicates, detects contradictions.
- Entity graph — People, places, organisations automatically extracted and linked. Relationship strength tracks corroboration.
- Hybrid search — BM25 keyword + structured domain + entity-graph paths, merged via Reciprocal Rank Fusion with temporal decay.
- In-session memory — Recently captured facts are immediately accessible via
get_session_context, even before consolidation. - Immutable history — Facts are never deleted, only superseded. Full history preserved.
- Source traceability — Every fact links back to the conversation events that produced it.
- Manual consolidation — Call
consolidateat natural breakpoints (topic change, task completion, pre-compaction). No reliance on session boundaries.
MCP Tools
Session
log_event— Log conversation events (messages, artifacts).get_events— Retrieve events from current or previous session.get_session_context— Recall facts captured in the current session (in-session working memory).
Reading
get_profile— Core identity factsget_preferences— Preferences by domainget_people— Person profiles with relationshipsget_context— Everything relevant to a topic (search + entity traversal)search_knowledge— Hybrid search across graduated knowledge
Writing
capture_fact— Store a fact. Fast append with session tagging. Full intelligence deferred to consolidation.consolidate— Integrate pending facts into long-term knowledge. Extracts entities, resolves duplicates, detects contradictions, builds the knowledge graph. Call at natural breakpoints or before context compaction.
Meta
get_schemas— Available domains and structureget_stats— Fact count, entity count, domain distribution
Session Event Logging
OpenMemory captures every interaction as a SessionEvent — the DIKW Data layer. This is the episodic ground truth that consolidation, search, and recall all build on.
How events are captured
All events are captured via the log_event MCP tool or the openmemory log-event CLI command. The calling AI logs conversation messages; Claude Code hooks can automate this:
Claude Code Hooks
For Claude Code, hooks provide deterministic capture — they fire every time, regardless of whether the AI "remembers" the tool description.
Available hooks
| Hook | Fires when | What it captures |
|---|---|---|
UserPromptSubmit |
User sends a message | Full prompt text |
Stop |
Assistant finishes responding | Last assistant message |
PostToolUse |
Tool call completes | Tool name, input, and response |
Setup
Install the CLI for hooks:
npm install -g @openmem/mcp
Alternatively, replace openmemory with npx -y @openmem/mcp in the hook commands below (no install needed, but adds ~2-3s latency per hook).
Add to .claude/settings.json (project-level) or ~/.claude/settings.json (global):
{
"hooks": {
"UserPromptSubmit": [
{
"hooks": [
{
"type": "command",
"command": "openmemory log-event --role user --event-type message"
}
]
}
],
"Stop": [
{
"hooks": [
{
"type": "command",
"command": "openmemory log-event --role assistant --event-type message"
}
]
}
],
"PostToolUse": [
{
"matcher": "^(?!mcp__openmemory__)",
"hooks": [
{
"type": "command",
"command": "openmemory log-event --role tool --event-type tool_result"
}
]
}
]
}
}
The CLI reads the hook JSON payload from stdin and extracts the relevant content field (prompt for UserPromptSubmit, last_assistant_message for Stop, full JSON for PostToolUse). Events are appended to the most recently active session in the database.
The PostToolUse matcher excludes OpenMemory's own tools (^(?!mcp__openmemory__)) to avoid capturing internal operations.
CLI Reference
The openmemory log-event command inserts events directly into the database (no running server needed):
# From a hook (reads JSON payload from stdin):
echo '{"hook_event_name":"UserPromptSubmit","prompt":"hello"}' | openmemory log-event --role user
# With explicit content:
openmemory log-event --role user --event-type message --content "hello world"
# Options:
# --role user | assistant | system | tool (default: user)
# --event-type message | tool_call | tool_result | artifact (default: message)
# --content-type text | json | image | audio | binary (default: text)
# --content Event content (or pipe via stdin)
# --session-id Target session (default: most recent)
# --data Data directory (default: ~/.openmemory or $OPENMEMORY_DATA)
Integration Patterns
OpenMemory's tool descriptions are the primary integration layer — they tell AI assistants when to capture facts and search knowledge, working with every MCP client out of the box. For deeper integration, clients can add rules-based hooks (instructions loaded into the AI's context) at key moments in the conversation lifecycle. These are optional but make capture and retrieval more reliable.
Without Configuration
The capture_fact tool description tells the AI to "call this proactively whenever you learn something useful." The search_knowledge description says "call this BEFORE answering questions that might benefit from personal context." These descriptions ship with the server and drive behaviour without any client setup.
Hook Points
| Hook Point | When | What to Call | Why It Matters |
|---|---|---|---|
| Session start | Conversation begins | get_profile, search_knowledge |
AI knows who you are from message one |
| Proactive capture | User mentions a preference, fact, or decision | capture_fact |
Knowledge compounds across sessions |
| Pre-response search | Before generating a reply | search_knowledge, get_context |
Responses informed by personal knowledge |
| Pre-compaction | Before context window compression | consolidate |
Processes pending facts before context is wiped |
| Natural breakpoints | Topic change, task completion | consolidate (optional) |
Keeps knowledge graph current |
On pre-compaction: This is the highest-value hook point — without it, knowledge is silently lost when the client compresses context. Calling consolidate before compaction processes all pending facts into long-term knowledge. If event extraction is enabled, the server also scans the raw conversation events to extract facts the AI missed.
Claude Code
Create .claude/rules/openmemory.md in your project (or ~/.claude/rules/openmemory.md globally). This loads automatically into context:
# OpenMemory
- At the start of each conversation, call `get_profile` to load identity context
- Before answering questions about preferences, people, or history, call `search_knowledge`
- When the user mentions preferences, personal details, relationships, or decisions, call `capture_fact`
- When the conversation is getting long, call `consolidate` to process pending facts before they are lost to compaction
- At natural breakpoints (topic change, task completion), call `consolidate` to keep the knowledge graph current
To allow OpenMemory tools without per-call approval prompts, add to the permissions.allow array in .claude/settings.json:
{
"permissions": {
"allow": [
"mcp__openmemory__*"
]
}
}
Cursor / Windsurf
Add to .cursorrules (Cursor) or .windsurfrules (Windsurf) in your project root:
When the openmemory MCP server is available:
- At conversation start, call get_profile to load user context
- Before answering questions about preferences or history, call search_knowledge
- When the user shares preferences, facts, or decisions, call capture_fact
- When context is getting long, call consolidate to process pending facts before they are lost
Claude Desktop / Other MCP Clients
No configuration needed. Tool descriptions handle integration automatically — the AI assistant reads the tool descriptions and knows when to capture and search.
Development
git clone https://github.com/gordonkjlee/openmemory
cd openmemory
npm install
npm run build
npm test
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。