Expand description
MCP (Model Context Protocol) server for ai-memory. Exposes memory operations as tools for any MCP-compatible AI client over stdio JSON-RPC.
Modules§
- jsonrpc
- JSON-RPC 2.0 wire-layer constants (#1558 batch 3).
- param_
names - server_
identity - Daemon-side Ed25519-signed
serverInfoblock published in the MCP initialize handshake response. - share
- MCP
memory_sharehandler — minimal v0.8-pulled-forward implementation for issues #224 (Phase 3 Memory Sharing & Sync RFC) and #311 (targeted point-to-point memory share). - tools
- v0.7.0 WT-1-C — test-only re-export bundle for the
memory_atomiseMCP handler. Mirrors [dispatch_handle_link_for_test]’s rationale: the integration suite attests/wt1c_mcp_atomise.rsdrives the handler directly without spinning up the stdio loop, so the handler symbol and the handler bundle struct need a stableai_memory::mcp::tools::path. The production wire path remains the JSON-RPC dispatch inhandle_request.
Structs§
- Ingest
Multistep Handler - Handler bundle. Keeps the dispatch implementation behind an
Arc<dyn LlmDispatch>so the daemon-runtime side can construct it once at MCP boot and re-use across calls. The dispatch isNoneuntil the daemon wires an LLM client (semantic-tier and below); the tier gate inhandle_ingest_multistepshort-circuits before consulting the dispatch in that case. - Memory
Capture Turn Request memory_capture_turnrequest body per RFC-0001 §“Tool input schema”.
Enums§
- Capabilities
Accept - Capabilities schema selector (v0.6.3.1 P1 honesty patch; extended through v0.7.0 A1–A5).
Constants§
- DEFAULT_
EMBED_ BACKFILL_ BATCH_ SIZE - v0.7.0 Wave-2 A5 (issue #853) — default batch size for the boot embedding-backfill loop. Tuned to balance two effects:
- MCP_
MAX_ DRAIN_ BYTES - #1249 — hard ceiling on the post-overrun drain so a peer that
streams a never-ending sequence of non-newline bytes cannot keep
the daemon’s drain loop spinning forever. When this ceiling fires
the daemon emits a final
-32700and exits cleanly so an operator process supervisor can restart it. - MCP_
MAX_ LINE_ BYTES - Run the MCP server over stdio. Blocks until stdin closes. Initializes components based on the requested feature tier.
Functions§
- build_
agent_ permitted_ families - v0.7.0 A4 — compute the optional
agent_permitted_familiesfield for a v3 capabilities response. - build_
capabilities_ describe_ to_ user - v0.7.0 A2 — build the capabilities-v3
to_describe_to_userstring. - build_
capabilities_ summary - v0.7.0 A1 — build the capabilities-v3
summarystring from the liveProfilestate. - build_
capabilities_ tools - v0.7.0 A3 — build the per-tool array carried in the
capabilities-v3
toolsfield. - decorate_
memory_ many - FX-4 / PERF-2 (2026-05-26) — batched front-end for
[
decorate_memory] used by the HTTP recall handler. Resolves the verbose-decoration link-attestation lookup for every memory in one SQL round-trip via [latest_link_attest_level_many] instead of N round-trips. Returns oneValueper(mem, score)in input order so the caller can splice it straight into the response payload. - effective_
tier_ label - Round-2 F13 — derive the runtime-effective tier label from the
presence of the LLM, embedder, and reranker handles. Mirrors the
boot banner string emitted by
serve_mcpso thememory_capabilitiesresponse and the daemon log agree on what the daemon is actually doing — independent oftier_config.tier, which only reflects the configured (build-time) tier and can lag the runtime when an embedder/LLM fails to load. - format_
rule_ summary - v0.7.0 K5 — format a single [
GovernancePolicy] as a one-line human-readable summary, prefixed with the namespace it governs. - handle_
calibrate_ confidence - Wire shape:
- handle_
capabilities_ family - v0.6.4-006 — Handle
memory_capabilitiesinvocations that pass afamily=<name>parameter. Wheninclude_schema=false(default), returns the canonical tool-name list. Wheninclude_schema=true, returns the full MCP-style tool definitions for each tool — the caller (an NHI agent or a host like Claude Code’s deferred-tools path) can register them at runtime without restarting the server. - handle_
capabilities_ with_ conn - v0.6.3 (capabilities schema v2 / P1 honesty patch): the canonical capabilities entry point.
- handle_
capabilities_ with_ conn_ v3 - v0.7.0 A1 — the v3-shaped capabilities entry point.
- handle_
capture_ turn - Handler entrypoint dispatched from
crate::mcp::handle_request. - handle_
check_ agent_ action - Handler for
memory_check_agent_action. Expectsarguments: - handle_
check_ duplicate - handle_
dependents_ of_ invalidated - MCP
memory_dependents_of_invalidatedhandler. - handle_
entity_ get_ by_ alias - handle_
entity_ register - handle_
expand_ query - handle_
export_ reflection - Wire shape:
- handle_
find_ paths - v0.7 J7 —
memory_find_pathshandler. Enumerates up tomax_resultspaths through the KG between two memories using BFS with cycle detection. Backend dispatch lives in the SAL — the SQLite path goes throughdb::find_paths(recursive CTE); a Postgres deployment would route throughPostgresStore::find_pathswhich dispatches on the resolved [crate::store::KgBackend] (Cypher when AGE is installed, recursive CTE otherwise). The wire shape is identical across backends:pathsis a list of id chains where each chain hassource_idfirst andtarget_idlast. - handle_
inbox - handle_
ingest_ multistep - Handle a
memory_ingest_multistepMCP tool call. - handle_
kg_ invalidate - SEC-2 / COV-8 (Cluster D, issue #767) —
pubso the integration test fleet can drive the handler directly. The function is still only registered as the MCPmemory_kg_invalidatetool; visibility is the only thing that changed. - handle_
kg_ query - handle_
kg_ timeline - handle_
list_ subscriptions - handle_
load_ family - v0.7 B1 —
memory_load_family(family, namespace?, k?). - handle_
namespace_ get_ standard - handle_
namespace_ set_ standard - handle_
notify - handle_
pending_ approve - handle_
pending_ reject - handle_
quota_ status - v0.7 K8 — MCP handler for
memory_quota_status. Reports per-agent quota usage (memories/day, storage bytes, links/day) for the operator-facing surface. - handle_
recall - #967 — JSON-bag entry kept as a thin wrapper around
[
handle_recall_dto]. The pre-#967 surface continues to accept the&Valueparams bag so existing call sites (tests + the MCP dispatcher) compile unchanged; field extraction is delegated toRecallRequest::from_mcp_params. - handle_
recall_ caller - v0.7.0 #1468 — caller-scoped MCP recall entry. Identical to
handle_recallbut threads a visibilitycaller(resolved by the dispatch layer viacrate::identity::resolve_read_visibility_caller) into [handle_recall_dto], which post-filters every retrieval branch by the canonicalcrate::visibility::is_visible_to_callerpredicate.Nonepreserves the single-tenant trust-all read posture. - handle_
recall_ observations - MCP handler. Filters compose with AND. Returns the ledger rows
most-recent-first, JSON-shaped via
observations::Observation. - handle_
recall_ with_ pre_ recall_ hook - Build the standards-inheritance chain for a namespace, most-general
first. Task 1.6 extends this from the historical 3-level scheme
(global → parent → namespace) to N levels by walking the
/-derived ancestors fromcrate::models::namespace_ancestorsplus anynamespace_metaexplicit-parent chain rooted at the top of the hierarchical path (which keeps legacy flat-namespace setups working). - handle_
reflect - handle_
reflection_ origin - MCP
memory_reflection_originhandler. Returns the structured origin record for a memory id, or a clean “this memory is not a reflection” envelope when the id exists butreflection_depth == 0. - handle_
replay - v0.7.0 I4 + L2-4 —
memory_replay(memory_id, verbose=false, depth=null). - handle_
rule_ list - Handler for
memory_rule_list. Accepts: - handle_
skill_ compositional_ context - MCP
memory_skill_compositional_contextsubstrate handler. - handle_
skill_ export - handle_
skill_ get - MCP
memory_skill_getsubstrate handler. - handle_
skill_ list - MCP
memory_skill_listsubstrate handler. - handle_
skill_ promote_ from_ reflection - MCP handler for
memory_skill_promote_from_reflection. - handle_
skill_ register - handle_
skill_ resource - MCP
memory_skill_resourcesubstrate handler. - handle_
smart_ load - v0.7 B2 —
memory_smart_load(intent, namespace?, k?). - handle_
subscribe - handle_
subscription_ dlq_ list - v0.7 K7 — MCP handler for
memory_subscription_dlq_list. Wrapscrate::subscriptions::list_dlqand applies the optionallimitcap (default 100, max 1000) so an operator inspecting a runaway DLQ can’t blow the response size budget. Family:Power. - handle_
subscription_ replay - v0.7 K7 — MCP handler for
memory_subscription_replay. Thin wrapper aroundcrate::subscriptions::memory_subscription_replaythat exposes the operator/governance reliability tool over the MCP wire. Family:Power(operator-scoped, not data-plane). - handle_
unsubscribe - handle_
verify - v0.7 H4 —
memory_verifyMCP tool handler. - overlay_
tool_ payloads - Round-2 F13 — overlay per-tool
inputSchemaand/ordocstringonto the top-leveltools[]array of a v2/v3 capabilities response. Called on the no-family path wheninclude_schema=trueand/orverbose=trueis set on the top-levelmemory_capabilitiesinvocation. Without an overlay, those flags were inert at the top level (only the family drilldown honoured them). - persona_
generate_ call - Wire shape (write):
- prompt_
definitions - Return the list of available prompts.
- run_
embedding_ backfill - v0.7.0 Wave-2 A5 (issue #853) — chunked boot embedding backfill.
- run_
embedding_ backfill_ with_ batch_ size - v0.7.0 issue #1260 — explicit-batch-size variant of
run_embedding_backfill. Honors the canonical #1146 precedence ladder by accepting a pre-resolved batch size fromcrate::config::AppConfig::resolve_embeddings. - run_
mcp_ server - tool_
definitions - v0.7 C2 — canonical tool catalog. Each tool entry carries a short
one-sentence
description(≤ 50 cl100k_base tokens) and a long-formdocsfield with the full prose + examples. The always-ontools/listpayload stripsdocsviatool_definitions_for_profile; callers wanting the verbose form invokememory_capabilities { family=<f>, verbose: true }which preservesdocsso an NHI can drill in without reloading the full-fat catalog into context. - tool_
definitions_ for_ profile - v0.6.4-002 — Filter
tool_definitions()down to the tools loaded underprofile. Tools whose family is not in the profile’s family list are dropped fromtools[].memory_capabilitiesand any othercrate::profile::ALWAYS_ON_TOOLSare kept regardless of profile so the runtime-discovery dance still works on--profile core. - tool_
definitions_ for_ profile_ verbose - v0.7 C4 — full-SCHEMA-SHAPE (verbose) variant of
tool_definitions_for_profile. Returns every optional param and every default (type,enum,default,minimum,maximum,required,items) — but NOT the natural-language prose: the body calls [strip_docs_from_tools], so the top-leveldocsfield AND every per-propertydescriptionstring underinputSchema.properties.*are stripped here too (#1648 doc truth-fix; the pre-#1648 claim of “every per-property description” was false). Used by thememory_capabilities { verbose=true }opt-in path so power users / NHI agents can still set the long-tail knobs (confidence,priority,tier,metadata,agent_id, …) without restarting the MCP server with a different profile. - tools_
check_ agent_ action_ mutation_ disabled_ error - v0.7.0 (issue #691) — accessor for the stable
governance.not_available_over_mcperror string. Consumed bytests/governance_immutability.rsto pin the wire vocabulary across versions. A future PR that wires the mutation refusal dispatch can re-use this constant directly rather than copy- pasting the message.