Memory system
An MCP server and memory layer that gives AI agents durable memory without loading all of it into every session.
- Type
- Local stdio MCP server plus a maintenance CLI
- Runtime
- TypeScript on Node 24
- Tools
- 13: write, pad, retrieval and read
- Start packet
- 800 tokens at most, plus up to 700 of task recall
- Search
- 5 compact rows, full records for up to 10 ids
- Quality check
- A recall evaluation that runs in CI
Problem
I use AI coding agents across many sessions, and every new session starts knowing nothing about the work it was not part of. Decisions I made last week, patterns an agent learned the hard way and the state of a half-finished task are all gone.
Loading everything into each session is wasteful and noisy. I wanted memory that injects little, points to files and lets the agent pull the rest on demand.
Approach
I split memory into layers by how much of it should enter a session. A small always-on start packet carries the decisions in force and the important learnings, one line each, capped at 800 tokens. After the first prompt, a recall step adds up to 700 tokens of what matches the task.
Everything else is fetched in three narrowing steps: search, timeline, get. A short-lived pad handles hand-overs between agents on one piece of work. Agents write only through one server, so locking and duplicate rules live in one place.
What I built
memory-mcp is a stdio MCP server in TypeScript with 13 tools. Three write tools cover memory: add_decision locks in a decision, add_learning records a reusable pattern once, and add_summary adds a task summary of at most five bullets.
Three pad tools handle hand-overs. pad_write adds a finding, decision or handoff entry, pad_read returns unexpired entries filtered by agent, type or age, and pad_status counts what is on the pad.
Three retrieval tools do the reading. memory_search returns ranked rows, memory_timeline shows the records around one hit, and memory_get returns full records. Four read tools remain: load_decisions, load_summaries, memory_status for file sizes and entry counts, and get_context_health, a scorecard of the memory tiers.
The tool list is generated from a command registry. A generated contract document and a drift check fail when the code and the docs disagree, and retired tool names must not be registered. A companion CLI handles maintenance: hygiene, review, migration, backup and restore.
How it works
At session start, a hook injects the cached start packet. After the first prompt, a recall hook adds the decisions and learnings that match it, and later prompts only add close new matches, never a repeat. A subagent also gets memory that matches its own task and its own top learnings.
When the agent needs more, memory_search returns at most five rows within 1,500 tokens. Each row has an id, a kind, a title, a path and line range for documents, and a 200-character snippet. Ranking fuses lexical and vector results from the document index, exact path and identifier matches, and BM25 over each memory store, combined by reciprocal rank. It then boosts by status, expiry date, age and the current project.
Writes go through the server. A write takes the transaction lock, replaces the file atomically and removes any span marked private. add_decision and add_learning then rebuild the packets they change before returning.
Key decisions
I inject a small packet and pull everything else on demand. Every token loaded before the first prompt costs context, so the packet is capped at 800 tokens and points to the rest.
I keep search, timeline and get as separate steps. Each step is narrower than the last, so an agent never pulls an unfiltered store into context.
I made a newer decision on the same topic replace the older one, and I guard near-duplicates. A decision is replaced at 70% word overlap and refused between 50% and 70% until I name what it relates to with supersedes or related. This keeps one current answer per topic.
I treat summaries as proposals, never as decisions. A small model summarizes finished sessions offline and proposes candidates. Only I can accept or reject one, and rejected texts become negative examples so the same suggestion is dropped next time.
I send all agent writes through one server. Locking, atomic replacement, duplicate handling and secret removal then live in a single place, and nothing else writes the stores.
I mark contradictions instead of blocking the write. A write that contradicts a decision in force is still saved, tagged conflicts_with, and shown to me once. Until I settle it, the owner decision is the side that reaches the packet.
In detail
Stores have retention rules. Tool calls are spooled as scrubbed observations, never the command text, and kept seven days. Summaries older than 30 days are deleted, with the newest ten always kept, and their learning lines are saved first. Agent memory is capped at 100 learnings per agent, with a view of at most 150 lines and 300 tokens injected.
A temporary decision carries an until date and leaves the packet, recall and search the day it passes. A packet line that nothing fetched, cited or raised in 90 days leaves the always-on part but is not deleted. A learning that repeats an existing one raises its count instead of adding an entry.
Pad entries default to 8 hours for findings, decisions and the starting-context entry, and 24 hours for a handoff, with a range of 1 to 72. A DECISION line on the pad is promoted into the summaries by a harvest step, but a permanent decision still goes through add_decision.
Quality is checked in CI. An evaluation runs labelled tasks against a fixture store and reports the share of required decisions and learnings that reach the context, the tokens injected and the latency of building the packet and recall. CI fails if the present rate falls more than 2 points or mean tokens rise more than 10% from the baseline. A weekly digest also reports which packet items were never used.
Status
The system is active and I use it daily. The server, the generated contract, the maintenance CLI and the CI evaluation are all in place.