qcdoc-mem
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@qcdoc-mem remember that I prefer concise responses with code examples"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
qcdoc-mem
Persistent long-term memory for AI agents, served over MCP.
Connect an MCP client, pass a user_id, and the agent remembers: facts are
extracted from conversations, stored as plain files on disk, and handed back for
injection into later sessions. No database to operate, no vector store, no
embedding pipeline.
agent ──► memory_remember_conversation ──► LLM extraction ──► facts/*.md + memory.json
agent ◄── memory_context / memory_search ◄── budgeted injection ◄──┘
Why
LLMs are stateless. Every session starts blank, so the user re-introduces
themselves, re-states preferences, and re-corrects the same mistakes. qcdoc-mem
is the memory subsystem that fixes that, packaged as a standalone service:
It lives outside your agent. One process serves any number of agents over MCP or an in-process SDK. Your client only needs the tool names.
It decides what to remember. You hand over the conversation; an LLM extracts durable facts, scores their confidence, drops the noise, dedupes near-identical entries, and merges fragments over time.
It is inspectable. Memory is Markdown and JSON on disk. You can read it, grep it, diff it, edit it, back it up with
rsync, and recover it without a database.
Related MCP server: engram
What you get
10 MCP tools | recall, explicit saves, automatic conversation extraction, fact CRUD, erasure, flush, status. See docs/tools.md. |
Two write paths |
|
Three-layer isolation | per |
Lifecycle management | confidence gates, two-level dedup, |
Budgeted injection | the memory block is ranked and truncated to a token budget, with |
No infrastructure | Markdown facts + a JSON summary + an embedded SQLite FTS5 index that is derived and rebuildable. See docs/operations.md. |
Swappable backend | the whole memory system sits behind a |
Quick start
Requires Python 3.12+.
uv sync # or: pip install -e .
uv run qcdoc-mem-mcp # streamable HTTP on http://127.0.0.1:8130/mcpOr, for a client that spawns the server itself:
uv run qcdoc-mem-mcp --transport stdioPoint your MCP client at it:
{
"mcpServers": {
"qcdoc-mem": {
"type": "http",
"url": "http://127.0.0.1:8130/mcp"
}
}
}Optional extras:
uv sync --extra cjk # jieba word segmentation, better Chinese/Japanese/Korean recallNo built-in authentication. The server binds to loopback by default for exactly that reason. If you expose it, put authentication in front of it -- anyone who can reach the port can read and write every user's memory.
Give it an LLM
Reads, explicit saves, and fact CRUD work with no model. Automatic extraction
from conversations needs one. Point qcdoc-mem at any OpenAI-compatible
endpoint:
# qcdoc-mem.config.yaml
memory:
backend_config:
model:
provider: openai # anything init_chat_model supports
model: deepseek-chat
base_url: https://api.deepseek.com/v1Run qcdoc-mem-mcp and call memory_status: it reports llm_configured: true
when the model resolved. A misconfigured model does not crash startup --
reads keep working and extraction fails at call time with a clear error.
The API key comes from the environment, never from the file -- the config file
is not interpolated, so a ${VAR} written there would be sent as the key
verbatim. Either export QCDOC_MEM_LLM_API_KEY, or omit api_key entirely and
let the provider read its own variable (OPENAI_API_KEY, ANTHROPIC_API_KEY,
...). See docs/configuration.md.
The 10 tools
Tool | One line | Needs LLM |
| Load memory as injection-ready text. Call once at the start of a task. | no |
| Find facts by query. Call before asking the user to repeat themselves. | no |
| Return the whole memory document (summaries + facts). For inspection/export. | no |
| Store one durable fact. Idempotent on exact content. | no |
| Hand a session over for automatic extraction. | yes |
| Edit a fact by id; omitted fields keep their value. | no |
| Delete one fact by id. | no |
| Erase a user's memory and cancel its pending extractions. | no |
| Force pending extractions to run now. | no |
| Report backend, mode, storage path, whether a model is configured. | no |
Plus one MCP resource: qcdoc-mem://status.
Every tool takes optional user_id / agent_name; set default_user_id on the
server and a single-tenant client can omit them entirely.
Full reference -- every parameter, every return shape, when to call it and in which phase of the agent loop: docs/tools.md.
Errors
Tools never raise at the model. They return
{"error": "...", "kind": "..."}, where kind is one of:
| Meaning |
| The caller's input was wrong (empty query, unknown role, bad confidence). |
| The configured backend does not implement that operation. |
| Storage or the backend failed. |
How it works
write path (asynchronous, batched)
client ── memory_remember_conversation ──► debounce queue
──► prompt assembly (current memory + conversation + hints)
──► one LLM call ──► JSON with 6 decision types
──► deterministic gates ──► dedup ──► capacity eviction ──► files
read path (synchronous, per turn)
client ── memory_context ──► load bucket ──► rank ──► token budget ──► text
client ── memory_search ──► FTS5 (or lexical relevance) ──► ranked factsThe design in one paragraph: one conversation turn produces at most one LLM
call, and that call is asked to do six jobs at once -- update the six summary
sections, add new facts, reinforce confirmed facts, remove contradicted facts,
re-adjudicate aged facts, and merge fragments. Everything the model proposes
then passes through deterministic code: a write gate that rejects anything not
scope=user + durable + descriptive, a confidence floor, exact and
near-duplicate dedup, and a capacity cap. The model proposes; the code decides.
Read docs/architecture.md for the full mechanism -- data model, both pipelines step by step, every gate, the concurrency protocol, and the isolation model.
Using it in an agent loop
qcdoc-mem does not hook your agent -- it cannot see your turns. The client
owns three moments:
Phase | Call | Why |
Session start |
| Prepend the returned text to the system prompt. |
Before asking the user to repeat |
| Only if facts were not already injected. |
Session end |
| Capture the session; the flush matters because extraction is batched. |
The server's MCP instructions tell the model when to make these calls, so a
client that surfaces them gets the behaviour with no integration code. If you
want automatic capture/injection at the framework level (LangGraph middleware,
turn hooks), you write that layer -- see
docs/integration.md for recipes and for the
automatic-capture behaviour that this package deliberately leaves to you.
SDK
The same operations in-process, no MCP:
from qcdoc_mem.contract import get_memory_manager
from qcdoc_mem.service import MemoryService
from qcdoc_mem.settings import configure_defaults
server_settings = configure_defaults() # env + optional config file
service = MemoryService(get_memory_manager(), server_settings)
service.remember("prefers uv over pip", user_id="alice", category="preference")
print(service.context(user_id="alice")["context"])
print(service.search("uv", user_id="alice")["results"])Or talk to the backend contract directly, bypassing the facade:
from qcdoc_mem.contract import HostHooks, MemorySettings, build_memory_manager
manager = build_memory_manager(
MemorySettings(backend_config={"storage_path": "/var/lib/qcdoc-mem"}),
HostHooks(),
)
print(manager.get_context("alice"))Documentation
Start at docs/README.md, which maps every document and gives lookup tables by task ("store a fact now", "why is my read empty", "point it at DeepSeek", ...).
Document | What is in it |
The index: reading paths by role, and "I want to..." lookups. | |
Every MCP tool: parameters, returns, when to call it, which phase of the loop, worked examples, error handling. | |
Principles, data model, the write and read pipelines step by step, gates, dedup, eviction, staleness, consolidation, concurrency, isolation, observability. | |
Putting it in an agent loop: phases, recipes, multi-tenant identity, and the automatic-capture layer this package does not ship. | |
Full config reference: precedence, every environment variable, every CLI flag, every backend field with defaults and bounds. | |
Storage layout, backup and recovery, migration, concurrency limits, troubleshooting, known limitations. | |
Swapping the backend, the storage class, the retrieval adapter, the prompts, and the signal patterns. | |
Five runnable examples: in-process SDK, agent loop, multi-tenant isolation, a real MCP client, and live LLM extraction. |
Where memory lives
<data-dir>/
├── .retrieval/memory-fts5.sqlite3 derived FTS5 index (rebuildable)
└── users/{user_id}/
├── memory.json six summary sections + revision
├── .memory.lock cross-process lock
└── agents/{agent_name}/
├── facts/{ab}/{fact_id}.md one Markdown file per fact
└── .metadata/ access counters, eviction auditData root resolution: memory.backend_config.storage_path >
$QCDOC_MEM_DATA_DIR > ~/.qcdoc-mem. Details, including what is safe to delete,
are in docs/operations.md.
Development
uv run pytest # 58 tests
uv run pytest tests/test_mcp_server.py -q
uv run python examples/run_all.py # every offline example, ~5s
uv run python scripts/check_doc_links.py # docs links and anchorsThe MCP tests drive the real tool-dispatch path over FastMCP's in-memory
transport, so nothing binds a port. 04_mcp_client.py is the exception: it
starts a real server on a free port and drives it over HTTP, then shuts it down.
Credits
The memory backend under src/qcdoc_mem/backends/qcdoc_mem/ is derived from the
memory subsystem of deer-flow, at
backend/packages/harness/deerflow/agents/memory/, adapted into this standalone
service. The adaptation is mechanical: module paths, class names, the
environment-variable prefix, the configuration filename and the default storage
root were renamed, and the host-coupled layers were replaced by this package's
own contract/, service.py, settings.py and mcp/ packages. The storage,
extraction, retrieval and lifecycle logic itself originates upstream.
That project is MIT licensed. Its copyright notice is reproduced in THIRD-PARTY-NOTICES.md, which ships with the package.
License
MIT -- see LICENSE. Third-party copyright notices are in THIRD-PARTY-NOTICES.md.
Available Tools
10 toolsmemory_contextMemory ContextA
Load the user's memory as text ready to put in your context.
Call this once near the start of a task. The returned context string
is the backend's own injection format and should be treated as opaque
text -- prepend it to the conversation rather than parsing it.
Inputs: query, user_id, thread_id, agent_name. Returns: object
memory_delete_factMemory Delete FactA
Delete a single fact by id.
Use when the user says a stored fact is wrong or no longer applies.
Inputs: fact_id (required), user_id, agent_name. Returns: object
memory_flushMemory FlushA
Force pending memory extractions to run now, within a time budget.
Useful before shutting down, or when a client wants the memory written before it reports success.
Inputs: timeout. Returns: object
memory_forgetMemory ForgetA
Erase stored memory for a user (or for one agent bucket).
This is destructive and irreversible. Pending extractions for the same
scope are cancelled as part of the call, so a queued update cannot
resurrect the memory afterwards. Use it when the user asks to be
forgotten, not to tidy up individual facts -- use memory_delete_fact
for that.
Inputs: user_id, agent_name. Returns: object
memory_getMemory GetA
Return the complete stored memory document for a user.
Prefer memory_search or memory_context for normal use; this returns
everything (summaries plus the full fact list) and is intended for
inspection, export or debugging.
Inputs: user_id, agent_name. Returns: object
memory_rememberMemory RememberA
Store one durable fact about the user.
Use this when the user states a preference, corrects you, or shares
context worth carrying into future sessions. Do NOT use it for
transient details of the current task, and do not re-save something
you already saved -- an identical fact is detected and returned as
status="duplicate" instead of being stored twice.
Inputs: content (required), user_id, category, agent_name, +1 more. Returns: object
memory_remember_conversationMemory Remember ConversationA
Hand a conversation to the backend to extract facts from automatically.
This is the hands-off write path: instead of deciding fact-by-fact what to save, send the turns and let the backend's LLM extraction decide. Requires an LLM to be configured on the server; without one this returns an error rather than silently storing nothing.
Inputs: messages (required), thread_id (required), user_id, immediate, +1 more. Returns: object
memory_searchMemory SearchA
Search long-term memory for facts matching a natural-language query.
Use this before asking the user to repeat themselves. Searches fact content (keyword and, when a retrieval index exists, ranked matching) and returns the best matches with their category and confidence.
Inputs: query (required), limit, user_id, category, +1 more. Returns: object
memory_statusMemory StatusA
Report the memory backend's configuration and health.
Use to check whether a model is configured (extraction needs one), where data is stored, and which identity the defaults resolve to.
Inputs: user_id, agent_name. Returns: object
memory_update_factMemory Update FactA
Edit an existing fact by id; omitted fields keep their value.
Use this instead of saving a new fact when something changed -- for
example when the user switches tooling. Get the fact_id from
memory_search first.
Inputs: fact_id (required), content, user_id, category, +2 more. Returns: object
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 10 tools
Each tool targets a distinct operation: read whole memory, search, context injection, manual write, automatic extraction, update, delete, bulk forget, flush, and status. The only near-overlap (memory_get vs memory_context) is explicitly disambiguated in descriptions, and memory_remember vs memory_remember_conversation clearly separates manual from backend-extracted storage.
All tools share the memory_ prefix and use snake_case, mostly following a memory_<verb> pattern. memory_context is a noun-style endpoint and memory_status/remember_conversation vary slightly in structure, but the overall pattern remains predictable.
10 tools is well-scoped for a memory backend: read, search, context load, manual write, automatic extraction, update, delete, full erase, flush, and status. Each tool earns its place with no redundant bloat.
Covers the full lifecycle of persistent facts: create (remember/remember_conversation), read (get/search/context), update, delete, plus admin operations (flush/status) and destructive forget. No obvious dead ends for the stated purpose.
Maintenance
Related MCP Connectors
Persistent memory for AI agents to retain, retrieve, and recall conversation context through MCP.
Persistent memory for AI agents across Claude, ChatGPT and any MCP client.
Hosted agent memory: store, search, and recall facts across sessions from any MCP client.
Persistent memory, knowledge graph, task management and more for AI agents via MCP.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceEnables AI agents to maintain persistent memory across sessions by capturing conversations, extracting durable knowledge, and injecting relevant context, supporting various MCP-compatible platforms.13MIT
- AlicenseCqualityBmaintenanceProvides persistent, local-first AI memory across sessions via MCP tools for storing, searching, and retrieving context from past interactions.3175 PyPI1MIT
- AlicenseAqualityDmaintenanceProvides persistent memory for AI assistants via MCP, enabling them to store and recall facts, preferences, and tasks across conversations using either local file storage or a cloud backend with semantic search.57 npmMIT
- AlicenseAqualityDmaintenanceProvides persistent memory with semantic search for MCP-based AI agents, enabling them to store and recall information across sessions using vector embeddings.41MIT