Skip to content

STM Overview

memtomem-stm is a short-term memory (STM) proxy that sits between your AI agent and your existing MCP servers. Without agent-side code changes, it adds response compression, proactive memory injection, and exposed-tool curation to calls routed through the proxy. Token savings depend on response shape, chosen budgets, and workload.

  • MCP tool responses keep blowing your context window — STM applies content-aware character or token budgets to routed filesystem, GitHub, and other MCP responses.
  • You want memories auto-injected without the agent having to ask — with LTM alone, the agent calls a search tool. With STM in front, eligible routed responses can carry relevant memories without a separate agent query.
  • You want to curate the tool list your agent sees — STM drops unresponsive servers, credential-leaking descriptions, and duplicate-named tools from the advertised list at exposure time.
  • You want to try the proxy without committing — STM imports your existing MCP servers and proxies them in front, and the move is reversible. mms eject restores an imported server to its original host config, returning you to the pre-STM state.
Terminal window
uv tool install memtomem-stm # 1. install
mms init --demo --client auto # 2. create a runnable demo + register a detected client
mms doctor # 3. diagnose the complete setup

mms init --demo creates a deterministic demo upstream. --client auto registers a supported detected host; use mms register --client claude, --client codex, or --client auto later to change registration. The completed call, metrics, prune, and rollback workflow is in Add STM to an MCP Server.

  • Proactive Surfacing — Every tool call runs candidate memories through 5 relevance checks (context extraction → query suitability → LTM search → score threshold → dedup window) before anything is injected. Surfacing toggles per upstream (mms surfacing <server> on|off), so you can exclude a single server’s responses from surfacing. See Proactive Surfacing.
  • Response Compression — 10 strategies, auto-selected by content type (JSON, Markdown, API docs, free text, …), with query-aware ranking and safer JSON output tiers. See Compression Strategies.
  • Exposed-Tool Curation — STM does not just relay every upstream tool as-is; it curates the advertised tool list at exposure time. Tools from unresponsive servers, descriptions that leak credentials, and duplicate or overflowing names are withheld from the agent. A tool whose name falls outside the MCP tool-name grammar ([A-Za-z0-9._-], 1–128 characters) is not proxied at all. Tune the policy with exposure.profile (strict default / review / explore); stm_admin(action="proxy_health") reports “N discovered / M advertised”.
  • Reversible Import — Imported upstreams record their origin, so mms list distinguishes directly-registered servers from imported ones in an ORIGIN column (* marks a pruned host original). mms eject verifies the restore before it removes the STM entry.
How a tool call passes through memtomem-stm The AI agent sends a tool call to the memtomem-stm proxy, which forwards it to the upstream MCP server. A text response usually comes back through three stages: CLEAN, COMPRESS, and SURFACE; the responses described after the list skip COMPRESS and SURFACE. SURFACE searches memtomem (LTM) and adds the memories that pass its relevance checks, if any. The agent receives the response with those memories. AI agent Claude Code · Codex CLI · any MCP client tool call response + memories, if relevant memtomem-stm optional proxy forwards the call SURFACE COMPRESS CLEAN response Upstream MCP servers filesystem, GitHub, … memtomem (LTM) search over MCP
The usual path for a text response. Some responses skip COMPRESS and SURFACE, as described below.

STM runs every MCP tool call through this pipeline:

  1. CLEAN — clean the upstream response (strip noise, unify format)
  2. COMPRESS — shrink the response (auto-select from 10 strategies)
  3. SURFACE — pull relevant memories from LTM and inject them (5-level gating)

A successful response with more than one text block, where any text block carries annotations or _meta, is cleaned per block and cut to its budget instead, without COMPRESS or SURFACE. Under the experimental structured delivery, so is any successful response that carries upstream structuredContent or non-text content; see Compression Strategies.

The bundled mms runtime does not write memories back to LTM. Its active response pipeline is CLEAN → COMPRESS → SURFACE, and surfacing reads from LTM over MCP.

STM and LTM are independent packages — no Python dependency between them. They communicate only via MCP protocol, and each can be deployed and upgraded separately.

LTM (memtomem)STM (memtomem-stm)
RolePersistent storage & searchReal-time proxy & compression
Required?Yes (core)Optional
CommunicationDirect MCP serverMCP proxy → queries LTM
PyPImemtomem-stm
Latest release0.7.10
CLImms
LicenseApache 2.0
GitHubmemtomem/memtomem-stm

The default proxy.max_upstream_bytes limit is 40 MiB (41,943,040 bytes) of decoded compact JSON, including metadata, non-text blocks and error content. It is not a wire-byte or peak-memory guarantee.

A timed-out or disconnected call can have executed upstream. Retrying an ambiguous failure requires a replay-safe policy and remaining retry/deadline budget; an unannotated tool is not automatically safe. Restarting a session does not roll back side effects. Shutdown watchdog and parent-liveness settings are listed in the configuration reference.