A lightweight, local-first MCP memory server for long-term AI agent context, behavioral learning, and precise action control.
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β pip install memorymesh β python -m memorymesh init β ready β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
| Feature | Anthropic Official | mem0 | Zep/Graphiti | MemoryMesh |
|---|---|---|---|---|
| GitHub Stars | ~86K | ~52K | ~24K | new |
| Behavioral Learning | β | β | β | β Instinct v2 |
| Action Choke Point | β | β | β | β |
| 3-tier Hybrid Search | β | β | β | β |
| Lossless Raw History | β | β | β | β |
| Multi-hop Knowledge Graph | β | Optional (Pro $249) | β | β |
| Temporal Decay | β | β | β | β |
| MCP Tools | 9 | 9 (MCP archived) | 9 | 24 |
| Infrastructure | JSONL file | Qdrant (self-host) | Neo4j (self-host) | β Single SQLite file |
| Installation | npx/docker | pip + services | docker + Neo4j | pip install memorymesh |
| MemoryMesh is new. These projects have larger ecosystems and communities. We focus on features the others don't offer. | ||||
| Who is this for? AI agent developers (OpenCode, Cursor, Claude Code) who lose context between sessions Β· MCP enthusiasts wanting no cloud DBs or Docker Β· Privacy-conscious users needing air-gapped memory Β· Tool builders wanting 24 tools, not 9. |
- π¬ See It in Action
- β¨ Why MemoryMesh?
- π System Architecture
- π‘ The Story Behind MemoryMesh
- π Quick Start & Installation
- βοΈ Configuration
- π§° Available MCP Tools
- π» CLI Usage
- π Development & Testing
- π€ Contributing
- π‘οΈ Security Notice
- π License
$ pip install memorymesh
$ python -m memorymesh init
β Workspace ready at ./memorymesh/
β MCP server configured for OpenCode
Agent: "what was I working on last session?"
MemoryMesh: π recall("last session context")
β 3 memories found (knowledge + user level)
Agent: β
continues seamlessly where it left off
$ memorymesh stats
π§ Memories: 1,247 Β· Sessions: 34 Β· Entities: 89 Β· DB size: 4.2 MB
These features are unique to MemoryMesh β no other MCP memory server has them. π§ Instinct v2 (Behavioral Learning) β N-gram pattern extraction, O(1) RAM-cached regex, auto-tagging at confidence > 0.8, reinforcement scoring.
βοΈ Action Choke Point β Blocks recall after 5 uncommitted actions until commit_milestone. Hostage data cached, released instantly. Prevents context overflow.
π 3-Tier Hybrid Search β Vector ANN (sqlite-vec) β FTS5 keyword β chronological fallback. Level-weighted scoring with workspace-aware soft penalty.
π Lossless Raw History β Verbatim tool call logging with zlib compression. Queryable via recall_raw (filter by tool, success/error). No LLM summarization loss.
πΈοΈ Multi-hop GraphRAG β Recursive CTE graph traversal. Entities, relations, cycle detection. Safe for Plan/Read-Only. Export as XML triplets.
π Dynamic Context Management β Keyset cursor pagination (stateless). Scoring via SQLite CTEs (importance Γ level weight Γ recency decay). Multi-threaded token counting.
π§© Flexible Embedding β pip install memorymesh (~50MB, no PyTorch). Optional [local] for SentenceTransformer offline. Remote API supported.
MemoryMesh relies on a single SQLite database packed with sqlite-vec for vector similarity, FTS5 for keyword search, and custom schema tables for Knowledge Graphs.
graph TD
%% Styling
classDef client fill:#f9f9fb,stroke:#d0d0d5,stroke-width:2px;
classDef core fill:#eef2ff,stroke:#6366f1,stroke-width:2px;
classDef db fill:#f0fdf4,stroke:#22c55e,stroke-width:2px;
classDef cache fill:#fffbeb,stroke:#f59e0b,stroke-width:2px;
%% Nodes
LLM["π€ AI Agent (OpenCode, Cursor, etc.)"]:::client
MM_SERVER["βοΈ MemoryMesh MCP Server"]:::core
subgraph Storage ["π½ Local SQLite Engine"]
VEC[("π Vector ANN (sqlite-vec)")]:::db
FTS[("π€ Full-Text (FTS5)")]:::db
G[("πΈοΈ Knowledge Graph (Entities/Relations)")]:::db
RAW[("π Lossless Raw History")]:::db
SESS[("π Session Store")]:::db
end
subgraph Memory ["β‘ In-Memory"]
INST["π§ RAM Cache (Instincts)"]:::cache
MIDDLEWARE["π οΈ Tool Execution Middleware"]:::cache
end
%% Connections
LLM -->|"1. call_tool"| MM_SERVER
MM_SERVER -->|"2. recall / trace_entity"| LLM
MM_SERVER -.-> MIDDLEWARE
MIDDLEWARE -.-> INST
MM_SERVER <==> Storage
π Hidden Gems (Under the Hood)
- Zero-Latency Context (Optimistic Hydration): Semantic anchors pre-computed before session close. AI regains context in
<5ms. - 3-Tier Fallback Retrieval: 1οΈβ£ Semantic (sqlite-vec) β 2οΈβ£ FTS5 keyword β 3οΈβ£ Chronological scan. Prevents "amnesia hallucinations".
- Choke Point Mechanism: After 5+ uncommitted actions,
recallblocked untilcommit_milestone. Prevents context overflow.
β‘ Performance (2021 MacBook Pro M1, 16GB RAM)
| Operation | Latency |
|---|---|
| recall (ANN, 50K vectors) | <15ms p50, <40ms p99 |
| trace_entity (3-hop) | <5ms |
| remember | <8ms |
| list_memories (100 items) | <3ms |
src/memorymesh/
βββ mcp_server/ # MCP protocol: server, handlers (24 tools), tool middleware
β βββ handlers/ # Tool execution, filters, trackers, semantic filter
β βββ server.py # MCP lifecycle (stdio + SSE)
βββ memory/ # Storage: sqlite-vec ANN, FTS5, session store, graph store, instincts
βββ utils/ # Rate limiter, path sanitizer, tool middleware, schemas
βββ embedder.py # Embedding factory (local SentenceTransformer / remote API)
βββ router.py # LLM router client with circuit breaker + fallback pool
βββ cli.py # CLI commands (init, stats, sessions)
βββ config.py # 50+ env vars across 7 config dataclasses
MemoryMesh was born from a common frustration: AI agents often lack true long-term memory across sessions, leading to context loss and fragmented workflows. I set out to build a lightweight, local-first MCP server that solves this without sacrificing speed or privacy. MemoryMesh is designed to be lean and easy to use, while providing sophisticated capabilities: rapid context retrieval, precise control over model behavior, autonomous learning from user interactions, and persistent, reliable context that ensures AI agents retain what matters.
- Python 3.12+
- OpenAI-compatible LLM endpoint (Ollama, vLLM, OpenAI, 9Router, etc.)
A. Remote Embedding Mode (Lightweight) β ~50MB core, remote API for embeddings.
pip install memorymeshB. Local Embedding Mode (Fully Offline) β With sentence-transformers (~1.5GB).
pip install "memorymesh[local]"C. With Rich CLI Tools
pip install "memorymesh[cli]"D. For Development (run tests)
pip install "memorymesh[test,local,cli]"π‘ Combine extras as needed:
pip install "memorymesh[local,cli]"installs everything.
E. Docker (Zero Embeddings)
docker compose -f docker/docker-compose.yml up --buildNo PyTorch, no sentence-transformers. Uses EMBEDDING_MODE=none. Ideal for containerized deployments.
python -m memorymesh initEdit the generated .env file in your workspace:
| Variable | Default | Description |
|---|---|---|
ROUTER_URL |
http://127.0.0.1:20128/v1 |
Your LLM endpoint URL. |
DEFAULT_MODEL |
your-model |
Primary model for summarization. |
BACKGROUND_MODEL_POOL |
(Empty) | Comma-separated cheap models for background fact extraction. |
EMBEDDING_MODE |
local |
local (sentence-transformers), remote (API), or none (zero-dependency, Docker). |
EMBEDDING_MODEL |
paraphrase-multilingual... |
Local embedding model name. |
REMOTE_EMBEDDING_API_URL |
(Empty) | Endpoint for remote embeddings. |
REMOTE_EMBEDDING_API_KEY |
(Empty) | API Key for the remote embedding server. |
VEC_DB_PATH |
./db/memory.db |
Location of the SQLite database. |
DEFAULT_USER_ID |
your_user_id |
Multi-agent isolation! Set different IDs for different agents. |
Place your db/ folder in Google Drive or Dropbox. Using the same DEFAULT_USER_ID on different machines synchronizes memory instantly!
MemoryMesh exposes 24 powerful MCP tools to the agent:
| Category | Available Tools |
|---|---|
| π§ Memory Operations | remember, recall, forget, archive_memory, unarchive_memory, list_memories |
| πΈοΈ Knowledge Graph | create_entity, create_relation, query_graph, trace_entity |
| β³ Session Lifecycle | new_session, end_session, resume_session, delete_session, list_sessions, get_session_context, save_system_prompt, preserve_session_memories |
| ποΈ Workspace Mgmt | commit_milestone, save_workspace_context |
| π Behavioral Learning | learn_session, recall_raw |
| π Utilities | ping |
MemoryMesh includes built-in terminal commands to inspect your databases.
# List the last 20 sessions (Status, Workspace, Timestamps)
memorymesh sessions --limit 20
# Show rich system statistics (Entities, DB size, relations)
memorymesh stats
# Initialize a new workspace
memorymesh init
# Run as SSE HTTP server (for Docker or remote access)
memorymesh serveUsing the provided Makefile makes development a breeze:
# Install everything for dev
make install-all
# Run tests (579 robust tests covering all features)
make test
make test-unit
make test-int
# Linter and Type Checking
make lint
make typecheck
# Clean artifacts
make cleanpython scripts/rebuild_vec.pyWe welcome contributions! Here's how to get started:
- Fork the repo
- Run
make install-allfor dev setup - Make your changes
- Run
make test(579 tests should pass) - Submit a PR
See CONTRIBUTING.md for detailed guidelines (coming soon).
Caution
CRITICAL DATA EXPOSURE RISK
MemoryMesh stores all data as plaintext in local SQLite databases (inside ./db/).
Never commit ./db/ or .env to a public repository! Always add to .gitignore.
MIT License Β© MemoryMesh