Transports

shmem-mcp --transport <mode> selects one of three transports.

stdio (default)

Spawned as a subprocess by the MCP client. No auth — process-level isolation. Used by Claude Code, Claude Desktop, Cursor when running locally.

{
  "mcpServers": {
    "shmem": {
      "command": "shmem-mcp",
      "env": {
        "SHMEM_PROJECT": "my-project",
        "SHMEM_QA_PROVIDER": "anthropic",
        "SHMEM_CALLER_AGENT": "claude-code"
      }
    }
  }
}

API keys go in ~/.shmem/.env, not in .mcp.json (which may be committed to git). Caller identity belongs there too: shmem init writes SHMEM_CALLER_USER to ~/.shmem/.env, and values in a committed .mcp.json env block take precedence over it — so hardcoding one would stamp a single developer's identity on every collaborator's facts.

sse / streamable-http

Long-lived HTTP. Used for shared team servers and remote/hosted deploys.

# HTTP with per-key bearer tokens
shmem-mcp --transport streamable-http --port 8705
#   reads keys.json from the root: ~/.shmem/keys.json, or $SHMEM_ROOT/keys.json
Flag Description Default
--transport stdio, sse, or streamable-http stdio
--host Bind address (HTTP transports) 127.0.0.1
--port Bind port (HTTP transports) 8705

keys.json (one entry is enough for a single user):

{
  "keys": {
    "sk-alice-abc123": { "user": "alice@macbook", "agent": "claude-code" },
    "sk-bob-def456":   { "user": "bob@workstation", "agent": "claude-code" }
  }
}

The server stamps facts with the authenticated caller — callers cannot impersonate each other.

The keys file is always keys.json in the root; SHMEM_KEYS_FILE is no longer read. A leftover SHMEM_KEYS_FILE naming any other file stops the server at startup, rather than leaving it to run without the keys it was pointed at.

Once a root has been served with authentication (keys.json, an identity provider, or SHMEM_API_KEY), the server leaves a .auth-required file in it, and a later start of that root with no authentication configured stops instead of running open. If keys.json goes missing, restore it. To serve the root without authentication on purpose, delete .auth-required.

Accounts need streamable-http. The sse transport can't pass the signed-in account to the server's tools, so a server with accounts (keys.json or an identity provider) refuses to start on sse. A single-user server, open or behind one shared SHMEM_API_KEY, can still use sse.

Migrating off SHMEM_API_KEY. The single shared SHMEM_API_KEY is deprecated and will be removed; the end state is keys.json alone. The server reads the variable only when no keys.json loads, so the two never need to coexist: once keys.json loads, the variable is ignored, and the server logs a warning at startup if it is still set. To move over, add the old token to keys.json as an entry with the identity it should map to, restart, then unset the variable.

  • Uptime and health probes need no token: GET /health is served without auth and returns {"status":"ok","version":...}.
  • A service that does need to call MCP (a script, a CI job) gets its own keys.json entry rather than sharing a person's token. Give it the same user (and root, if the existing entry sets one) and it reads and writes the same memory. It can be revoked on its own by deleting its entry; keys.json hot-reloads, so no restart is needed. A reload that fails (invalid JSON, such as a trailing comma left behind, or no keys left) keeps the previous keys in force, revoked one included, so confirm the server logged keys.json reloaded rather than keys.json auto-reload failed before treating the token as gone.

If any auth is configured but none of it loads (for example, an unreadable keys.json and no other provider), the server refuses every request rather than run unauthenticated.

Behind a reverse proxy on the same host (TLS termination forwarding to 127.0.0.1:8705), requests reach shmem-mcp on loopback carrying your public Host header. With auth configured that is accepted. A server running without auth refuses such requests (403, invalid Host header), as protection against DNS rebinding: put auth on it, or have the proxy send Host: 127.0.0.1:8705 upstream.

Per-user login (OIDC): set SHMEM_OAUTH_ISSUER and shmem-mcp also accepts OAuth access tokens from that OpenID Connect provider, so MCP clients that support OAuth (such as Claude Desktop connectors) can log each person in as themselves. The provider runs the login; shmem-mcp validates the token's signature, issuer, audience, and expiry, and takes the caller's verified email from the token or the provider's userinfo endpoint. SAML identity providers work through any OIDC broker in front of them.

SHMEM_OAUTH_ISSUER=https://auth.example.com \
SHMEM_SERVER_DOMAIN=shmem.example.com \
shmem-mcp --transport streamable-http --port 8705
  • A caller's first login creates an account in auth.db under the server root: the account id is the email, and a new data root is made under users/. Roots never move and are never shared between accounts. If the email is already an account id in keys.json, the login is bound to that account and its root instead, so existing users keep their memory when they start signing in. A login that matches an account it can't adopt (ids differing only in case, or one already bound) is refused until the operator binds it. Only emails the provider marks verified (email_verified, in the token or from userinfo) are accepted. The binding is recorded in auth.db, so removing the key from keys.json afterwards doesn't end that person's sign-in access; offboard them at the provider.
  • SHMEM_SERVER_DOMAIN is the server's public host. MCP clients are given https://<host>/mcp, and a token is accepted only if it was issued for that URL (its aud), so tokens the same provider issues for other applications are refused.
  • SHMEM_OAUTH_ALLOWED_DOMAINS (e.g. example.com,example.org) limits sign-in to verified emails at those domains. Set it whenever the provider can vouch for people the server isn't meant for: one shared by several organizations, or one with open sign-up. Matching is exact, so list subdomains separately; wildcards aren't accepted, except * on its own, which allows any domain explicitly (the same as unset, for builds that require the variable). A value that names no domain stops the server at startup rather than lifting the limit, and the startup log shows the domains in force. It applies to OIDC sign-in only; keys.json accounts are unaffected.
  • keys.json keeps working alongside OIDC, and is tried first.
  • Moving keys.json users to sign-in. shmem-mcp accounts lists every account and how it will sign in. An account whose id is its owner's email is adopted at that person's first sign-in, keeping its root. Any other account needs binding first: shmem-mcp accounts bind <email> <account> makes the first sign-in with that email use the existing account and its memory, instead of creating a new, empty one. Run it as the server's user, with the same SHMEM_ROOT; it is safe while the server runs.
  • The CLI's OAuth client needs no registration: unless the server says otherwise, its client ID is the URL of a client metadata document this server publishes at /oauth/shmem-cli.json, which the provider fetches. shmem login signs in through the browser with a loopback redirect, and stays signed in by refreshing. /auth/cli tells the CLI which client ID to use and where to log out; POST /auth/logout asks the identity provider to end the caller's session, where it can.
  • Unauthenticated requests get a 401 whose WWW-Authenticate header points at the Protected Resource Metadata (RFC 9728), served without auth at /.well-known/oauth-protected-resource and its path-suffixed form (.../oauth-protected-resource/mcp). A reverse proxy in front of shmem-mcp must pass those, /oauth/shmem-cli.json, /auth/cli, /auth/logout and /auth/callback through without adding auth of its own.
  • /auth/callback is the page a browser lands on when shmem login runs where no browser can reach the machine (over SSH, or with --no-browser): it shows a sign-in code to paste back into the terminal. Its address carries a live authorization code, so keep this path's query string out of proxy and load-balancer access logs; shmem-mcp keeps no access log of its own. A provider with its own CLI client ID (rather than the metadata document) must list https://<host>/auth/callback as a redirect URI and set SHMEM_AUTH_CALLBACK_REGISTERED=1 before the CLI uses the page.
  • A request whose token the server can't verify, because its account database or the identity provider's userinfo endpoint is unreachable, times out, or answers 5xx or 429, gets a 503 with Retry-After and no WWW-Authenticate challenge, so clients don't send the user to sign in again. The cause is in the server log (auth: could not verify a token: ...), not the response. Signatures are checked against the provider's signing keys, which the server caches; a token signed with a key it can't fetch, or any OIDC token when the provider was unreachable at startup, is still answered 401.
  • Identity providers that depart from these standards are adapted by an oidcauth.Provider (accepted tokens, the CLI's client ID, ending sessions, and optionally refusing tokens by their claims, such as the organization signed in to), set by a build of shmem-mcp that wraps servermain.Main. The standard build follows the standards.

Client side (.mcp.json):

{
  "mcpServers": {
    "shmem": {
      "type": "streamable-http",
      "url": "https://shmem.example.com/mcp",
      "headers": { "Authorization": "Bearer sk-alice-abc123" }
    }
  }
}