Memory Engine MCP
Enables AI assistants to have a living memory with atomic knowledge storage, multi-factor recall, organic decay, automatic learning, and graph traversal via MCP.
README
<p align="center"> <img src="docs/logo.jpg" width="128" height="128" alt="Memory Engine Logo" /> </p>
<h1 align="center">๐ง Memory Engine</h1>
<p align="center"> A living memory system for AI assistants โ built on SQLite + MCP (Model Context Protocol).<br> Not just a key-value store. Not just a knowledge graph. A <strong>living memory</strong> that decays, learns, and evolves with your AI. </p>
โจ Features
- Atomic memory model โ knowledge stored as atoms (facts, decisions, events, preferences, logs, procedures, notes, session messages)
- Multi-factor ranking โ recall combines FTS relevance ร confidence ร recency ร weight (not just BM25)
- Organic decay โ atoms lose weight over time if not accessed; critical ones get flagged for review
- Learning engine โ generates questions for the human when it detects contradictions, gaps, weak atoms, or merge candidates
- Session watcher โ automatically ingests OpenClaw session messages as atoms with TTL (event-driven via inotify/watchdog)
- Auto-bonding โ creates relationship links between atoms automatically during import
- Graph traversal โ navigate the knowledge graph with depth control and relation filtering
- Markdown import โ one-way sync from your existing markdown notes (coexistence, not replacement)
- Merge & deduplicate โ consolidate similar atoms intelligently
- TTL support โ atoms that expire automatically
- Versioning โ automatic atom history tracking
๐๏ธ Architecture
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Your AI Assistant โ
โ (via MCP Protocol) โ
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ MCP Server (FastMCP) โ
โ 18 tools (recall, remember, ...) โ
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Engine Layer โ
โ ranking ยท decay ยท learning ยท merge โ
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Session Watcher (watchdog/inotify) โ
โ monitors OpenClaw session JSONL files โ
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ SQLite (FTS5 + JSON1) โ
โ atoms ยท bonds ยท versions ยท Q&A โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Files
| File | Purpose |
|---|---|
server.py |
MCP server โ exposes 18 tools via FastMCP |
db.py |
SQLite layer โ CRUD, FTS, bonds, versions |
engine.py |
Ranking, decay, similarity, gap detection |
learning.py |
Question generation (5 trigger types) |
importer.py |
Markdown โ SQLite one-way importer |
session_watcher.py |
Watchdog-based session JSONL monitor |
schema.sql |
Database schema (atoms, bonds, FTS, versions) |
~1,800 lines of Python. Dependencies: mcp SDK + watchdog.
๐ง MCP Tools (18)
Memory Operations
| Tool | Description |
|---|---|
remember |
Create or update an atom |
recall |
Smart query (FTS ร confidence ร recency ร weight) |
get_atom |
Get full atom details with all bonds |
list_atoms |
List atoms with filters (domain, type, status) |
merge_atoms |
Merge two atoms (secondary โ primary) |
export_atom |
Export an atom as markdown |
Knowledge Graph
| Tool | Description |
|---|---|
link |
Create a typed bond between atoms |
unlink |
Remove a bond |
search_graph |
Traverse the knowledge graph from an atom |
Session Management
| Tool | Description |
|---|---|
recall_session |
Search messages within a specific session |
session_summary |
Get session overview (message count, time range) |
cleanup_sessions |
Delete expired session atoms (TTL cleanup) |
System & Learning
| Tool | Description |
|---|---|
stats |
Memory statistics (counts, domains, types) |
decay_run |
Execute decay cycle (reduce unused atom weights) |
learning_run |
Run learning engine (detect gaps, contradictions) |
ask_pending |
Get pending human questions |
answer_human |
Answer a pending question |
import_markdown |
Import markdown files (bulk or single) |
๐ Usage Examples
Remember a decision
remember(
title="Switched from npm to pnpm",
body="Faster installs, better monorepo support. Migration completed 2026-06-15.",
type="decision",
domain="project:frontend",
confidence=0.9,
tags=["tooling", "npm", "pnpm"]
)
Recall relevant context
recall(query="frontend build tool choice", limit=5)
# Returns ranked results combining FTS match, confidence, recency, and weight
Link related concepts
link(
from_id="switched_from_npm_to_pnpm",
to_id="monorepo_setup",
relation="depends_on",
strength=0.8
)
Search within a session
recall_session(
session_id="abc123-def456",
query="database schema design",
limit=10
)
Get a session summary
session_summary(session_id="abc123-def456")
# Returns: message count, user/assistant breakdown, time range, first topics
Import existing markdown notes
import_markdown() # Bulk import all markdown files
import_markdown(filepath="/notes/project-decisions.md") # Single file
Run the learning engine
learning_run()
# Detects: contradictions, weak atoms, merge candidates, decay-critical, gaps
# Generates human questions for findings
ask_pending(limit=5)
# Returns questions that need human input
๐ Session Watcher
The session watcher monitors OpenClaw session JSONL files in real-time:
- Event-driven โ uses
watchdog/inotify, near-zero overhead (not polling) - Incremental reads โ tracks file offsets, only processes new lines
- Smart filtering โ only captures user/assistant text, skips tool results, system messages, and heartbeat noise
- Auto-expiring โ session atoms have a configurable TTL (default 30 days)
- Automatic โ starts on server boot, no manual intervention needed
Configuration
Mount the sessions directory and set the env var:
volumes:
- /path/to/openclaw/sessions:/sessions:ro
environment:
- OPENCLAW_SESSIONS_DIR=/sessions
- SESSION_TTL_DAYS=30
๐ Quick Start
Docker (recommended)
# docker-compose.yml
services:
memory-engine:
build: .
restart: unless-stopped
expose:
- "8085"
volumes:
- memory-data:/data
- ./your-markdown-notes:/workspace/memory:ro
# Optional: OpenClaw sessions for session watcher
- /path/to/openclaw/sessions:/sessions:ro
environment:
- MEMORY_DB_PATH=/data/memory.db
- MARKDOWN_SOURCE=/workspace/memory
- MEMORY_HOST=0.0.0.0
- MEMORY_PORT=8085
# Optional: session watcher
- OPENCLAW_SESSIONS_DIR=/sessions
- SESSION_TTL_DAYS=30
volumes:
memory-data:
docker compose up -d
Local (Python โฅ3.11)
pip install -r requirements.txt
python server.py
Connect to your MCP client
Add to your MCP client config (e.g., Claude Desktop, OpenClaw, Cline, etc.):
{
"mcpServers": {
"memory-engine": {
"url": "http://localhost:8085/sse",
"transport": "sse"
}
}
}
See mcp.json for a ready-to-use example.
๐ Use Cases
- Personal AI assistant memory โ remember preferences, decisions, project context across sessions
- Session continuity โ automatically capture conversation context, never lose where you left off
- Team knowledge base โ shared memory accessible to AI agents
- Project documentation โ import existing markdown docs, query them naturally
- Learning journal โ track decisions and their rationale over time
โ๏ธ Configuration
Edit config.json to tune:
| Section | What it controls |
|---|---|
decay |
Interval, decay factor, critical threshold, archive timeout |
ranking |
Weight of FTS score, confidence, recency, and atom weight |
learning |
Thresholds for contradiction, merge similarity, gap detection |
sessions_dir |
Path to OpenClaw sessions directory |
session_ttl_days |
TTL for session message atoms (default 30) |
๐งฌ How It Differs
| Feature | memory-graph | sqlite-memory | Memory Engine |
|---|---|---|---|
| Storage | SQLite | SQLite | SQLite |
| FTS search | โ | โ (BM25) | โ (multi-factor) |
| Decay | โ | โ | โ |
| Learning/Q&A | โ | โ | โ |
| Session watcher | โ | โ | โ |
| Markdown import | โ | โ | โ |
| Auto-bonding | โ | โ | โ |
| Graph traversal | Basic | โ | โ (depth + relation) |
| Merge atoms | โ | โ | โ |
| TTL | โ | โ | โ |
| Versioning | โ | โ | โ |
๐ License
MIT โ see LICENSE.
๐ค Contributing
Contributions welcome! Open an issue or PR.
<p align="center"> Made with ๐ง by <a href="https://github.com/SimoneB79">SimoneB79</a> </p>
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.