mcp server
memsem
π§ Semantic memory for AI agents β auto-writes durable facts, prioritizes, handles contradictions, semantic search. One command, works everywhere, 100% local.
Set up
Runs on your computer. Pick your agent and operating system.
Before you start
- Node.js 20 or newer
{
"mcpServers": {
"memsem": {
"command": "npx",
"args": [
"-y",
"memsem"
]
}
}
}same format Cursor, GitHub Copilot CLI, Junie, JetBrains AI Assistant, Augment (Auggie CLI), Factory Droid, Kiro, Devin CLI +12
Values in angle brackets are placeholders. Restart Claude Desktop after editing its config.Claude Desktop docs
README
synced Oct 28, 2026Semantic memory for AI agents β remembers what matters, knows what to forget. One command to install. Works in every project, for every AI. 100% local.
Why β when big memory systems already exist?
They exist, and they got the hard parts right: vector stores (mem0), temporal knowledge graphs (Zep / Graphiti), agent frameworks (MemGPT / Letta). But they all share the same three flaws:
- Brute storage, no structure. They keep what you throw at them, and retrieval is a similarity search over everything. The AI doesn't know where to look β so it looks everywhere, and the noise drowns the signal.
- No precision. A fuzzy match is a fuzzy match: almost-right memories fill the context budget and waste tokens.
- No self-correction. A fact contradicted months ago stays as strong as the day it was written.
memsem fixes exactly these three things:
- π§ It knows where to search. Every session starts with a routing card
(
memory-index.md): themes + keywords, injected into the context. The AI routes by theme, crosses projects, and only pays for what it needs. Hierarchical themes + a live focus list keep the session's active branches at full priority β the rest is attenuated, never lost. - π― It is precise. Strict lexical search by default (50% word-match
threshold, no graph propagation unless you explicitly ask) β a query returns
the right facts, ranked by dynamic priority
(
importance Γ confidence Γ recency Γ frequency). Precision is measured, not assumed: P@3 0.958 on the reference benchmark (51 facts, 20 queries,scripts/bench.mjs, results inDESIGN.mdΒ§11). - π It corrects itself. Contradictions fade the old fact instead of overwriting it ("I drank milk for yearsβ¦ wait, lactose intolerant") β history is always kept, critical facts (β₯ 0.8) are protected. Background agents extract durable facts at session end, consolidate small facts into patterns, and recalibrate priorities β only when the memory stays at least as searchable.
All the big-system promises, minus their flaws: one command, 100% local, and your memory stays yours β never committed, per-user, shared across all your repos.
See it work
Install once, let it run. This is a real session on a throwaway database β your actual memory is never touched (node scripts/demo.mjs):
=== memsem β demo on a temporary database ===
(your real memory in ~/.memory-mcp stays untouched)
1. The AI writes durable facts (memory_add_many)
β 4 facts written
2. Strict search (lexical): memory_search { query: 'milk' }
β user β drinks β milk
3. Semantic search (relax, local embeddings): memory_search { query: 'cheese', relax: true }
No shared word with Β« lactose Β» β the local semantic index (Ollama) bridges it
β lactose β is-present-in β cheese, yogurt, cream
β user β is-intolerant-to β lactose
β user β drinks β milk
4. Soft supersession: the AI learns you no longer drink milk
β conflict: true, old fact faded (faded: [1])
5. Search now returns the current fact
β user β drinks β no more milk (lactose intolerant)
β user β drinks β milk
Stats: 5 active memories, semantic index OK (mxbai-embed-large)
Privacy β your memory is yours
- 100% local β stored in
~/.memory-mcp/memory.dbon your machine. No cloud, no telemetry, nothing leaves your computer. - Never committed β the database lives outside every repository. Clone a public repo, push code, share screenshots: your memory stays with you. Each user has their own memory.
- The memory follows you, not your projects β the same base is shared across all your repos. Create a new folder, a new repo: the memory is still there.
Install
opencode β one line
Add to opencode.json (project or ~/.config/opencode/opencode.json):
{ "plugin": ["memsem"] }
That's it. The plugin registers the MCP server, injects the memory protocol and the memory index into every session, grants the needed permissions, and runs the background agents. Restart opencode.
Claude Code β one command
npx -y memsem setup
This registers the MCP server (claude mcp add memory -- npx -y memsem) and adds a "memsem memory" block to ~/.claude/CLAUDE.md pointing to the full protocol.
Or install it with AI: just paste into Claude:
Install the memsem persistent memory: run
npx -y memsem setup, read~/.memsem/memory-protocol.md, and apply the protocol.
Any MCP client
npx -y memsem
The server speaks MCP over stdio. Point any MCP-capable host at it and inject memory-protocol.md into the host's instructions (e.g. as AGENTS.md) to make the AI autonomous.
Universal installer
npx -y memsem setup # detects and configures your hosts (opencode, Claude)
npx -y memsem setup --help # see options
Idempotent, safe, reversible (--uninstall).
How it works
The memory lifecycle β every fact follows the same path:
flowchart LR
W["memory_add β subject β predicate β object"] --> R["repeated β confidence β frequency β"]
W --> P["priority = f(importance, confidence, recency, frequency)"]
R --> S{"contradiction?"}
S -- yes --> F["old fact fades progressively"]
F --> A["archived β history always kept"]
S -- no --> K["kept, reinforced"]
A --> J["pinned & critical (β₯ 0.8) are protected"]
- Atomic facts β every memory is a
subject β predicate β objecttriple with importance, confidence, frequency, tags, theme, provenance, trust and evidence. - Themes & focus β hierarchical themes (
food/drinks) are the routing map; a search by theme crosses all projects. Thefocuslist keeps the session's active themes at full priority. - Dynamic priority β
0.45 Γ importance + 0.25 Γ confidence + 0.2 Γ recency + 0.1 Γ frequency. A critical fact beats a recurring pattern. - Soft supersession β contradictions fade the old fact (confidence decays) until it archives under a threshold. History is always kept.
- Semantic index (optional) β each fact is embedded locally (
mxbai-embed-largevia Ollama);relax: truesearches add cosine similarity (threshold 0.5). Without Ollama, everything works identically β strict lexical search. - Evidence and time β
inferred,verbatimandverifiedtrust states keep a short evidence trail;recorded_atis separate fromvalid_from/valid_until, with historicalasOfqueries. - Review and scope β uncertain facts can stay
pending; rejection blocks their normalized value, project scope is isolated by default, and cross-project search is explicit.
Known limitations
Read honestly, from an independent review (Agent Memory Atlas):
- The automatic correction path has no lock. A rejected value that is
re-asserted (say the same old transcript is read ten times) returns and
fades its own correction β an ordinary correction is archived at the third
re-assertion. Only a human rejecting a candidate writes a durable
suppression (
memory_suppressions) that refuses the value outright. This is a deliberate position (repetition is evidence) with a real cost. - A pin protects survival, not visibility. A pinned correction never loses
confidence and stays first in
memsem list, but a repeated rejected value can still take the topmemory_searchresult. importwrites past the gate β restoring a backup reinstates a suppressed value.- A refused write leaves no audit row, and purging a reviewed fact leaves
its text in
memory_candidates. - Consolidation and extraction safety rules are prompts, not code.
Rough edges, not bugs β each is tracked in DESIGN.md roadmap and open questions.
Comparison
| memsem | CLAUDE.md / notes | mem0 | Zep / Graphiti | official memory MCP | Obsidian as memory | |
|---|---|---|---|---|---|---|
| Auto-writes during sessions | β | β | β οΈ via app code | β οΈ via app code | β | β |
| Priority for context budget | β | β | β | β | β | β |
| Contradictions (soft supersession) | β | β (overwrites) | β (overwrites) | β (temporal versioning) | β | β |
| Semantic search | β local (Ollama) | β | β (vector store) | β (graph + embeddings) | β | β οΈ (plugins) |
| Episodic memory + self-maintenance | β | β | β οΈ (episodic add-ons) | β (temporal knowledge graph) | β | β |
| One memory across all your repos | β | β (per project) | β οΈ (per app config) | β οΈ (per app config) | β | β οΈ (vault) |
Zero dependency, npx -y | β | β | β | β | β | β |
| Human-readable / editable | β οΈ (CLI list/edit) | β | β | β | β (JSON) | β |
Comparison as of Aug 2026, from public docs; capabilities evolve β verify before choosing.
Command line
Everything that can be done through MCP can be done from a terminal:
memsem list [--theme x] [--project p] [--limit n] [--all] # read your memory
memsem edit <id> [--object "..."] [--importance 0.6] [...] # fix a fact by hand (audited)
memsem forget <id> [--yes] # archive a fact (confirm)
memsem purge <id> [--yes] # permanently erase a fact (confirm)
memsem doctor [--limit n] [--hours h] # most-modified facts β spot drift
memsem export [--output f] [--project p] # full JSON dump
memsem import <file.json> # restore / merge a dump
memsem setup [--host opencode|claude] # install for your hosts
Manual fixes are written to the audit journal β memsem doctor shows them too.
Configuration
Tunable constants (priority weights, thresholds, fade factors, modelβ¦) live in
src/config.ts. Override any of them in ~/.memsem/config.json
(or $MEMSEM_CONFIG), deep-merged with validation:
{ "priority": { "importance": 0.4, "confidence": 0.3 }, "minLexical": 0.4 }
Settings are documented and validated by a benchmark
(scripts/bench.mjs β 51 facts, 20 queries, P@k/R@k across
constant sets; results in DESIGN.md Β§11).
Durability
The database is versioned and migrated automatically at startup (schema_migrations),
with an automatic backup before any migration (~/.memory-mcp/backups/, last 5 kept).
WAL mode is on β a crash mid-write leaves the database intact. Full dumps and
restores via memsem export / memsem import.
Documentation
memory-protocol.mdβ the protocol injected into your AI: how it writes, searches, and maintains memory automatically.DESIGN.mdβ full design: vision, principles, the lactose case study, constant calibration, roadmap.scripts/demo.mjsβ reproduce the demo above on a throwaway database.
Roadmap
- Semantic index (local Ollama embeddings)
- Episodic memory + session extraction
- Hippocampus consolidation + pairwise scoring judge
- Universal opencode plugin +
memsem setup - Versioned migrations + automatic backup + export/import
- Configurable constants, validated by a benchmark
- Secure judge: dry-run, audit journal, guardrails,
memsem doctor - CLI:
list/edit/forgetβ fix a fact by hand - Evidence contract, temporal validity, candidate review, audit and confirmed purge
- Multi-hop graph propagation (relax mode)
- Write gate on the automatic path (supersession β suppression decision)
-
importbehind the gate (consult suppressions) - Audit refused writes; purge candidate text; consolidation rules in code
- Obsidian bridge: export/import memory as readable markdown notes
License
MIT β free for anything. Your memory stays yours.