memory engine MCP Server

A living memory that decays, learns, and evolves with your AI.

Documentation

Version License: MIT Python Changelog

Memory Engine Logo

๐Ÿง  Memory Engine

A living memory system for AI assistants โ€” built on SQLite + MCP (Model Context Protocol).
Not just a key-value store. Not just a knowledge graph. A living memory that decays, learns, and evolves with your AI.

Works with: Claude Code ยท Claude Desktop ยท Cursor ยท Cline ยท Windsurf ยท OpenClaw ยท Any MCP client


โœจ 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

FilePurpose
server.pyMCP server โ€” exposes 18 tools via FastMCP
db.pySQLite layer โ€” CRUD, FTS, bonds, versions
engine.pyRanking, decay, similarity, gap detection
learning.pyQuestion generation (5 trigger types)
importer.pyMarkdown โ†’ SQLite one-way importer
session_watcher.pyWatchdog-based session JSONL monitor
schema.sqlDatabase schema (atoms, bonds, FTS, versions)

~1,800 lines of Python. Dependencies: mcp SDK + watchdog.

๐Ÿ”ง MCP Tools (18)

Memory Operations

ToolDescription
rememberCreate or update an atom
recallSmart query (FTS ร— confidence ร— recency ร— weight)
get_atomGet full atom details with all bonds
list_atomsList atoms with filters (domain, type, status)
merge_atomsMerge two atoms (secondary โ†’ primary)
export_atomExport an atom as markdown

Knowledge Graph

ToolDescription
linkCreate a typed bond between atoms
unlinkRemove a bond
search_graphTraverse the knowledge graph from an atom

Session Management

ToolDescription
recall_sessionSearch messages within a specific session
session_summaryGet session overview (message count, time range)
cleanup_sessionsDelete expired session atoms (TTL cleanup)

System & Learning

ToolDescription
statsMemory statistics (counts, domains, types)
decay_runExecute decay cycle (reduce unused atom weights)
learning_runRun learning engine (detect gaps, contradictions)
ask_pendingGet pending human questions
answer_humanAnswer a pending question
import_markdownImport 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 + polling fallback (every 30s) for reliability on Docker overlayfs
  • Persistent offsets โ€” read positions stored in SQLite, survive container restarts
  • Deduplication โ€” content_hash on every atom prevents duplicates on rescan or restart
  • Markdown digests โ€” lightweight .md summary per session, survives JSONL deletion
  • Smart filtering โ€” only captures user/assistant text; skips tool results, system messages, heartbeat noise, and system sessions (cron, MQTT, isolated)
  • Truncation detection โ€” if a JSONL file shrinks (rotation/truncation), offset resets automatically
  • Auto-expiring โ€” session atoms have a configurable TTL (default 30 days); a background thread cleans up expired atoms, digests, and stale offsets every 60 minutes
  • Automatic โ€” starts on server boot, no manual intervention needed

Configuration

Mount the sessions directory and set the env vars:

volumes:
  - /path/to/openclaw/sessions:/sessions:ro
environment:
  - OPENCLAW_SESSIONS_DIR=/sessions
  - SESSION_TTL_DAYS=30
  - SESSION_DIGEST_DIR=/data/session_digests
  - SESSION_POLL_INTERVAL=30

Advanced filtering in config.json:

{
  "session_exclude_patterns": ["cron:", "mqtt", "heartbeat", "isolated"],
  "session_max_content_chars": 2000,
  "session_cleanup_interval_minutes": 60
}

๐Ÿš€ 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

  • Developer tools memory โ€” persistent context for coding assistants (Claude Code, Cursor, Cline, Windsurf): remember project decisions, architecture choices, and coding preferences across sessions
  • 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:

SectionWhat it controls
decayInterval, decay factor, critical threshold, archive timeout
rankingWeight of FTS score, confidence, recency, and atom weight
learningThresholds for contradiction, merge similarity, gap detection
sessions_dirPath to OpenClaw sessions directory
session_ttl_daysTTL for session message atoms (default 30)
session_poll_intervalPolling fallback interval in seconds (default 30)
session_digest_dirDirectory for markdown session digests
session_exclude_patternsSession ID patterns to skip (cron, mqtt, etc.)
session_max_content_charsMax chars per session atom before truncation
session_cleanup_interval_minutesTTL cleanup loop interval (default 60)

๐Ÿงฌ How It Differs

Featurememory-graphsqlite-memoryMemory Engine
StorageSQLiteSQLiteSQLite
FTS searchโŒโœ… (BM25)โœ… (multi-factor)
DecayโŒโŒโœ…
Learning/Q&AโŒโŒโœ…
Session watcherโŒโŒโœ…
Markdown importโŒโŒโœ…
Auto-bondingโŒโŒโœ…
Graph traversalBasicโŒโœ… (depth + relation)
Merge atomsโŒโŒโœ…
TTLโŒโŒโœ…
VersioningโŒโŒโœ…

๐Ÿ“ License

MIT โ€” see LICENSE.

๐Ÿค Contributing

Contributions welcome! Open an issue or PR.


Made with ๐Ÿง  by SimoneB79