mcp-memory-server
A knowledge-graph-based persistent memory server for the Model Context Protocol, storing entities, observations, and relations in SQLite with semantic vector search and temporal versioning.
README
MCP Memory Server
A knowledge-graph-based persistent memory server for the Model Context Protocol (MCP). Stores entities, observations, and relations in SQLite with semantic vector search, temporal versioning, and cursor-based pagination.
Attribution
This project is derived from @modelcontextprotocol/server-memory by Anthropic, PBC, originally published under the MIT License as part of the MCP Servers monorepo. The original LICENSE file is preserved in this repository.
Features
- SQLite storage with WAL mode, foreign key constraints, and database-level deduplication
- Semantic vector search via sqlite-vec + all-MiniLM-L6-v2 ONNX embeddings (automatic, no config needed)
- Temporal versioning — observations and relations track
superseded_attimestamps; old data is preserved for history but hidden from active queries - Point-in-time queries —
as_ofparameter on read/search operations recovers the graph state at any past timestamp - Entity soft-delete —
delete_entitiesmarks entities as superseded (preserving history) rather than hard-deleting - Entity name normalization — surface variants like
Dustin-Space,dustin/space, andDUSTIN SPACEall resolve to the same identity key - Observation metadata —
importance(1-5 scale),context_layer(L0/L1/null), andmemory_typeclassification on observations - Context layers —
get_context_layersreturns L0 (always-loaded rules) and L1 (session-start context) observations with token budgets - Session-start briefing —
get_summaryreturns top observations by importance, recently updated entities, and aggregate stats - Entity timeline — view full change history (active + superseded + tombstoned observations and relations)
- Similarity detection —
add_observationswarns when new observations are semantically similar to existing ones - Four-tier eviction — Active → Superseded → Tombstoned → Hard-deleted degradation chain with 6-month LRU shield and configurable size cap (default 1 GB)
- Cursor-based pagination — sorted by most-recently-updated, stable under concurrent use
- Project scoping — optional
projectIdparameter isolates entities by project - Auto-migration — upgrades from JSONL to SQLite automatically on first run
Installation
npm install
npm run build
Note:
better-sqlite3is a native C addon. You'll need C build tools (gcc, make) installed. On Fedora:sudo dnf install gcc make. On Ubuntu/Debian:sudo apt install build-essential.
Full harness install (recommended for Claude Code)
The server alone provides the storage layer. To replicate the full session-lifecycle integration — auto-loaded L0 context, freshness scanning, pre/post-compact agents, noise gating, /audit-memory and /checkpoint skills, custom QA agents — see harness/README.md:
cd harness
./install.sh
The installer is idempotent, backs up existing files, and prints the manual integration steps (settings.json merge, MCP registration, CLAUDE.md fragments) at the end.
Usage
With Claude Code
Add to your MCP server configuration:
{
"mcpServers": {
"memory": {
"command": "node",
"args": ["/path/to/mcp-memory-server/dist/index.js"],
"env": {
"MEMORY_FILE_PATH": "/path/to/your/memory.db"
}
}
}
}
Environment Variables
| Variable | Default | Description |
|---|---|---|
MEMORY_FILE_PATH |
memory.db (alongside script) |
Path to database file. Extension determines backend: .db/.sqlite → SQLite, .jsonl → JSONL |
MEMORY_VECTOR_SEARCH |
on |
Set to off to disable vector search entirely |
MEMORY_SIZE_CAP_BYTES |
1000000000 (1 GB) |
Database size cap for the eviction system. Eviction triggers at 90% of cap |
Tools
| Tool | Description | Key Parameters |
|---|---|---|
create_entities |
Create new entities in the knowledge graph | entities[], projectId? |
create_relations |
Create directed relations between entities | relations[] (from, to, relationType) |
add_observations |
Add observations to existing entities. Returns similarExisting when new observations are semantically close to existing ones |
observations[] (entityName, contents[], importances?[], contextLayers?[], memoryTypes?[]) |
delete_entities |
Soft-delete entities (preserves history for as_of and entity_timeline) |
entityNames[] |
delete_observations |
Delete specific observations from entities | deletions[] (entityName, contents[]) |
delete_relations |
Delete relations between entities | relations[] (from, to, relationType) |
supersede_observations |
Atomically retire old observations and insert replacements. Preserves history | supersessions[] (entityName, oldContent, newContent) |
invalidate_relations |
Mark relations as no longer active. Preserves history. Idempotent | relations[] (from, to, relationType) |
set_observation_metadata |
Update importance, context layer, and/or memory type on existing observations in-place | updates[] (entityName, content, importance?, contextLayer?, memoryType?) |
read_graph |
Read the knowledge graph (paginated, sorted by most recently updated) | projectId?, asOf?, cursor?, limit? |
search_nodes |
Search entities by name, type, or observation content. LIKE + semantic vector search | query, projectId?, asOf?, cursor?, limit? |
open_nodes |
Retrieve specific entities by name with full relations | names[], projectId?, asOf? |
list_projects |
List all project names in the knowledge graph | — |
entity_timeline |
Full change history for an entity (active + superseded + tombstoned items) | entityName, projectId? |
get_context_layers |
Returns L0/L1 observations sorted by importance with token budgets | projectId?, layers? |
get_summary |
Session-start briefing: top observations, recent entities, aggregate stats | projectId?, excludeContextLayers?, limit? |
Data Model
- Entities — named nodes with a type, a project scope, and timestamped observations. Entity names are normalized (case-insensitive, separator-insensitive) for identity matching while preserving the original display form.
- Relations — directed edges between entities with temporal tracking (
createdAt,supersededAt) - Observations —
{ content, createdAt, importance, contextLayer, memoryType }objects attached to an entity (the atomic unit of knowledge)
Temporal Versioning
Observations, relations, and entities support a four-tier lifecycle:
- Active items appear in
read_graph,search_nodes, andopen_nodes - Superseded items are hidden from active queries but preserved for history and
as_ofrecovery - Tombstoned items have their content stripped by the eviction system but preserve the existence skeleton
- Hard-deleted items are permanently removed when under extreme size pressure
- Use
entity_timelineto see the full history of any entity (all tiers) - Use
as_ofparameter onread_graph/search_nodes/open_nodesto recover the graph at any past timestamp
Vector Search
Vector search is automatic when using the SQLite backend:
- Uses
sqlite-vec(brute-force KNN) withall-MiniLM-L6-v2ONNX embeddings (384 dimensions) - Model downloads ~23MB on first startup (cached thereafter)
- LIKE substring search always runs; vector search adds supplementary semantic matches
- Set
MEMORY_VECTOR_SEARCH=offto disable - If the model fails to load, the system degrades gracefully to LIKE-only search
Storage Backends
SQLite (default, recommended)
SQLite is the default and recommended backend. Features: WAL mode, FK constraints, database-level deduplication, vector search, temporal versioning, schema migrations.
JSONL (deprecated)
The JSONL backend is maintained for environments without C build tools but does not support vector search, as_of queries, entity soft-delete, entity_timeline, set_observation_metadata, invalidate_relations, or eviction. Set MEMORY_FILE_PATH to a .jsonl path to use it.
Migration from JSONL
- Change
MEMORY_FILE_PATHto a.dbpath (or remove it to use the default) - On first run, the server auto-migrates data from the
.jsonlfile - The original JSONL file is renamed to
.jsonl.bak
Known Limitations
- Entity names are globally unique across all projects (relations use names as FK)
- Project filtering is advisory, not a security boundary
- Paginated relation coverage is incomplete — use
open_nodesfor full relations on specific entities - Vector search is best-effort — degrades to LIKE-only if model/extension unavailable
- vec0 is brute-force KNN — fine at current scale, consider ANN at ~50,000+ observations
- Context layers and memory types are caller-managed — the server stores them but does not auto-classify
See CLAUDE.md for detailed architecture documentation and the full limitations list.
Development
npm test # run tests (520 tests across 9 test files)
npm run test:watch # run tests in watch mode
npm run build # compile TypeScript
npm run watch # compile in watch mode
Set SKIP_VECTOR_INTEGRATION=1 to skip the vector integration tests (which download the embedding model) for faster CI runs.
License
See LICENSE for the full text and original copyright notices. The upstream project is transitioning from MIT to Apache-2.0; documentation is licensed under CC-BY-4.0.
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。