MCP server

shmem-mcp exposes the same memory system to MCP clients. Sixteen tools split into core operations, project management, and multi-user group/sharing primitives.

recall_memory

Use when you need raw facts from past conversations — e.g. scanning recent entries, finding specific decisions, or building context for a task. Returns timestamped facts ranked by relevance.

Parameter Type Required Description
query string yes Natural language search query
max_facts int no Maximum facts to return
token_budget int no Maximum tokens to return; uses greedy packing (default: 8000)
max_fact_tokens int no Maximum tokens per fact before truncation (default: 500)
since string no Only include facts after this time (RFC3339 or relative: 1h, 30m, 7d, 2w)
before string no Only include facts before this time (RFC3339 or relative)
caller_user string no Filter by user (e.g. "alice@macbook")
caller_agent string no Filter by agent (e.g. "claude-code")
project string no Project name or cross-user reference like "alice/my-app". When omitted, uses the effective-project default (see below).
metadata object no Only include facts whose metadata matches, e.g. {"branch": "dev", "thread": ["t1", "t2"]} (see Metadata filters)

Effective project defaulting (matches shmem ask / shmem query): when project is omitted, shmem-mcp resolves the effective project in this order — .shmem/project marker walking up from the server's cwd → SHMEM_DEFAULT_PROJECT env → none. If retrieval scoped to the resolved project returns zero facts, it auto-broadens to all projects and prepends (no facts in project=<X> — broadened to all projects) to the response so the calling agent can surface that to its user. Set SHMEM_DEFAULT_PROJECT=ALL in the server's env to disable the auto-default entirely. Any project scope, explicit or resolved, also includes your account-wide memory: your own memories with no project, such as what the Claude app saves (see Projects). Reading another user's project never includes theirs.

Uses multi-index retrieval (keyword BM25 + temporal recency, plus an opt-in dense-embedding index).

ask_memory

Use when the user asks about past work, decisions, or conversations. Retrieves relevant facts and generates a grounded answer. Preferred over recall_memory for most questions.

Parameter Type Required Description
question string yes Natural language question
now string no Override current time for temporal reasoning (RFC3339 or YYYY/MM/DD)
caller_user string no Filter context by user
caller_agent string no Filter context by agent
project string no Project name or cross-user reference. When omitted, uses the effective-project default — same shape as recall_memory.
metadata object no Only draw the answer from facts whose metadata matches — same shape as recall_memory.

The pipeline classifies the question type, extracts time filters, retrieves via multi-index search, formats context with timestamps and session grouping, runs a type-specific prompt, and returns a clean answer.

The answer cites the facts it relies on with inline markers like [1], and the text result ends with a Sources list giving each cited fact's title, date, project, repository (or the teammate it came from) and full fact id, so an agent can preview one with share_show (client code can fetch it with get_facts). The structured result carries the same as {"answer", "citations": [{"n", "fact_id", "title", "created", "project", "repo", "from"}]}. No Sources list is added when nothing is cited.

With no LLM configured on a local server, ask_memory answers through the default remote's QA when one is configured, and otherwise returns an error with setup instructions — never unsynthesized facts.

Metadata filters

Facts can carry metadata: string key/value pairs set when they are written (the metadata field of add_memory and add_memory_batch), such as a branch or thread id. Only keys named under shared. (such as shared.branch) go with a fact shared to another account; the rest stay with the writer (see Sharing). recall_memory, ask_memory, list_facts_since, shmem query and shmem ask can restrict a read to facts whose metadata matches:

  • Each key's value is one string, or a list of strings of which any may match. On the command line, repeat --meta with the same key for "any of".
  • Different keys must all match. A fact that lacks a key does not match it.
  • Keys you leave out don't constrain anything, so {"branch": "dev"} reads every thread on that branch.

Provenance stamps work as filter keys, which narrows a read to where facts were captured:

shmem ask "why did we cap retries?" --meta stamp_repo=github.com/acme/billing
shmem query "migration" --meta stamp_branch=fix/retries
shmem query "flaky test" --meta stamp_cloud=claude-code-cloud

The MCP equivalent is {"stamp_repo": "github.com/acme/billing"} in the metadata argument of recall_memory, ask_memory or list_facts_since. Stamps are private to their owner, so these filters match your own facts only: facts you received from a teammate carry no stamps, and in another user's project a filter on a stamp_* key matches nothing.

The filter is applied inside each index, before results are ranked and cut, so a narrow filter returns the best matching facts rather than whatever matching facts happened to make the overall top results. It is a filter the caller chooses, not an access control: a caller that omits it reads everything its permissions allow. In another account's project a filter can only use keys readers there can see (see Sharing); a filter on any other key matches nothing, so it can't reveal values kept private.

Auto-broaden also applies: a question that returns zero facts under the auto-default project triggers a second pipeline run against all projects, with the broaden note prepended to the answer.

list_facts_since

Returns the facts written after a timestamp, oldest first, as structured content for client code: a time-ordered feed rather than a search. Hosted sync pulls other machines' writes with it. To answer a question, use ask_memory or recall_memory.

Parameter Type Required Description
since string yes RFC3339 timestamp; returns facts strictly after it
limit int no Maximum facts per page (default 1000, max 5000)
project string no Only facts in this project; empty means all of the caller's projects
metadata object no Only facts whose metadata matches — same shape as recall_memory (see Metadata filters)

The response holds facts, has_more, and next_since. Pass next_since as the next call's since to read the following page. Filters apply before limit, so each page and its cursor cover matching facts only.

On an authenticated server, an account that holds no memory at all gets, from ask_memory and recall_memory: "This shmem account has no memory yet. Memory comes from your coding agents: install shmem on your computer (<install URL>) and sign in with this same email." The install URL is SHMEM_INSTALL_URL, or the published install guide.

add_memory

Preserve information across sessions. Usually saved automatically by hooks; call directly only when the user explicitly asks to remember something.

Facts are atomic: store one self-contained statement per call, with the names and keywords it should be found by. Retrieval is keyword-based (BM25), so an entity buried mid-paragraph in a multi-fact blob becomes unfindable — the write succeeds, but reads quietly miss. Never concatenate several facts into one write; split them into separate calls, or use add_memory_batch with one fact per entry.

Parameter Type Required Description
content string yes One atomic fact — a single self-contained statement (max 1MB)
source string no Origin: "user", "llm", or "tool" (default: "user")
project string no Project name or cross-user reference
app_project string no The Claude app project the conversation belongs to, when the agent is working inside one; recorded as stamp_app_project

Caller identity is stamped automatically from the auth token (HTTP) or environment variables (stdio), along with the provenance stamps the server can vouch for. Content is filtered through .shmemignore rules before storage.

delete_memory

Use when the user asks to forget something or correct stored information. Find fact IDs with recall_memory first.

For a local agent, a fact in a shared space is first retracted from every space you can write to, so its readers drop their copies on their next sync. A fact still held by a space you can only read is kept, and the space's owner has to remove it. Retraction removes the fact itself, not what readers already learned from it. On an authenticated hosted server, the server retracts the fact from every shared project of yours that holds it, and a grantee's delete retracts it from the one space their grant reaches.

Parameter Type Required Description
fact_ids string[] yes List of fact IDs to delete
project string no Project name

get_stats

Fact count, index sizes, storage details, operation counts. No parameters.

list_sources

Breakdown by source type (user, llm, tool). No parameters.

list_projects

Available projects with fact counts, descriptions, and a marker for the current project. No parameters.

current_project

The active project name and path for this session. No parameters.

login

Signs this machine in to a shmem account: the agent's way to run shmem login. Local (stdio) server only; the hosted server doesn't list it, since a connector signs in through its own OAuth. Call it only when the user asks to sign in or agrees to it.

Parameter Type Required Description
server string no This machine's server; any other server needs shmem login --remote <url> typed by the user
code string no The sign-in code the user pasted back, when signing in without a browser on this machine (SSH)
switch_account bool no The user's answer to switching accounts: true to switch, false to stay (ends the new sign-in)

The first call starts sign-in, opens the browser where there is one, and waits up to 45 seconds: it returns the result lines, or the link to show the user before calling again. Over SSH it returns the link at once; ask the user for the code the page shows and call again with code. A question the user must answer (switching account, or which of the machine's projects sync at a first sign-in) comes back as text to ask, never as a default yes. None of the machine's projects sync until the user answers. With no arguments on a machine already signed in, it says who you're signed in as. The upload of the projects the user chose and the catch-up run in the background, so they finish even if the agent session ends.

whoami

The account identity your token authenticates as on this server. No parameters.

This is the canonical identity that owns your facts and that every share is authorized against. It is not necessarily the same string as your local SHMEM_CALLER_USER author stamp — see Author stamp vs. account identity.

Group & sharing tools (multi-user HTTP only)

These tools are available on multi-user HTTP servers (authenticated via bearer tokens). They enable unix-style project sharing: create groups, invite collaborators, grant read or read-write access to projects. A local shmem-mcp relays the group and project-grant tools, create_group through list_shared_projects, to your remote, so they work from an agent's local server once you've run shmem login. It relays create_project too, and keeps a local copy of the project; with no remote, create_project creates the project locally.

Tool Purpose
create_group Create a new group (you become the owner; created as <your-user>/name)
delete_group Delete a group you own
invite_to_group Invite a user to a group you own
accept_invitation Accept a pending invitation
list_groups List groups you own, belong to, and pending invitations
members_of_group List members of a group you own or belong to; names: true returns JSON with display names
people Display names of you and the people in your groups (JSON)
share_project Grant a group r or rw access to one of your projects
unshare_project Revoke group access from a project; its readers drop their copies on their next sync
list_shared_projects List projects others have shared with you
create_project Register a project tag in your data root (config dir for per-tag .shmemignore), e.g. before sharing it
delete_project Permanently delete every fact tagged with the project from your data (irreversible). A deleted fact that is also in another of your shared projects is retracted from it first
rename_project Rename a project tag — UPDATEs every matching fact in your data
project_info Show fact count and sharing info for one of your projects
get_share_rules Read your share rules as text, with a version for editing
set_share_rules Replace your share rules; refused if they changed since the version you read
get_ignore_rules Read your account's .shmemignore files (global and per project), each with a version. Hosted servers, for accounts with their own data root
set_ignore_rules Replace one of your account's .shmemignore files; refused if it changed since the version you read. Hosted servers, for accounts with their own data root
share_updates What your share scans produced since you last checked: auto-shares to announce and new nominations to offer. Each is returned once
discard_nomination Turn a nomination down for good: recorded privately, and the same facts are never nominated again
forget_nomination Clear nominations without deciding on them (nomination_ids, or all, with include_discarded to clear discards too; dry_run to count first). Nothing is shared or unshared, and a later scan that reads those facts may nominate them again. See Clearing nominations
set_sharing Turn sharing on or off for your account, when the server's operator offers it (SHMEM_SHARING=on on the server). With it on, the agent sharing tools (share_facts, scan_shares and the rest) work on your account's sharing workspace on the server; with it off, share_status, share_log, share_show, discard_nomination, forget_nomination and unshare_facts still do, so what was shared can be reviewed and pulled back. With if_unset, it sets nothing if the account already has a setting; the CLI uses this to carry over the setting from a machine where sharing was on
set_telemetry Local server only. Record your answer to whether shmem may send anonymous usage statistics from this machine; your agent asks you once, after an ask_memory answer, and calls it only with your explicit answer. See Telemetry

Read access allows recall_memory, ask_memory, get_stats, list_sources. Read-write additionally allows add_memory and delete_memory.

Cross-user project references: once a project is shared with you, access it by prefixing the owner's username:

recall_memory(query="auth decisions", project="alice/my-app")

The server resolves alice/my-app to Alice's project directory, checks your group membership and permissions, then executes against her project.

Author stamp vs. account identity

shmem tracks two identities per fact, and they answer different questions.

Field Question Where it comes from Typical value
caller_user Who wrote this? SHMEM_CALLER_USER on the writing machine alice@laptop
owner_user Whose is it? the account your token authenticates as alice

The author stamp is commonly device-qualified, because knowing which machine produced a fact is useful provenance. The account identity is the one the server can verify, so it is what authorization — including every share — is checked against.

On a single machine with no remote the two are the same: shmem applies a "writer is owner" default. Once you add a hosted remote whose account name is spelled differently, they diverge, and two things follow:

  • Shares still work. The author is canonicalized to your account on push, and the original stamp is preserved in the shared copy under an author_stamp metadata key. Nothing is re-attributed — it names the same person by the identity the server knows. This applies only to facts this machine authored: a fact someone else wrote (a replica pulled from a shared project) is pushed with its author untouched, so re-sharing it can never restate its authorship as yours.
  • Local owner filters will disagree. --mine matches on owner_user, so facts still owned by the device-qualified spelling won't match your account. Fix that with shmem admin migrate-owner-identity, which rewrites owner_user and leaves authorship alone.

Run shmem whoami to see both identities and whether they agree. Note that the two cannot be reconciled automatically: an account identity may itself contain @ (an email address), so there is no safe rule for splitting a device suffix off a name.