Skip to main content
Glama
README.md
# `rsym-mcp`

**A model-independent progressive-disclosure memory layer (`rsym_context` → `rsym_expand` → `rsym_store`) for MCP-compatible LLMs.**

`rsym-mcp` is **not** another chatbot or agent framework. It sits between any external LLM (Claude, ChatGPT Business/Enterprise/Responses API, Cursor, or local Ollama/VOID.NET agents) and your stored records so the LLM reasons over compact, verifiable symbolic cards first and pulls full canonical evidence only when needed.

```text
External LLM (Claude / ChatGPT / Cursor / Ollama)
        │  MCP (stdio or Streamable HTTP)
        ▼
   rsym-mcp server
   ├── rsym_context  (compact symbolic cards + SHA-256 drift check)
   ├── rsym_expand   (on-demand verbatim canonical recovery)
   └── rsym_store    (PII scrub + durable/volatile tier enforcement)
        │
        ├── Durable Canonical + Symbolic Store (SQLite WAL + FTS5)
        └── Volatile RAM Store (strictly in-memory for biometric/ephemeral data)
```

---

## Why Two-Layer Memory?

Ordinary summarization silently loses evidence and drops caveats. Standard RAG chunks often retrieve a finding while leaving behind the warning two paragraphs away.

`rsym-mcp` separates:
- **Canonical Memory**: verbatim original records, provenance IDs, and SHA-256 digests.
- **Symbolic Memory**: concise, **plain structured English** cards linked back to canonical records—preserving explicit `CONSTRAINT:` lines verbatim (e.g., `electrical activity != proof of awareness`).

---

## Honest Engineering Risks (and How `rsym-mcp` Addresses Them)

| Production Risk | How `rsym-mcp` Mitigates It |
| :--- | :--- |
| **1. The Two-Hop Tax** — Calling `rsym_expand` every turn adds tool latency and erodes savings. | Cards target ~180–280 tokens so 70–85% of turns finish in 1 hop. Optional `auto_expand_if_under_tokens` returns canonical text in 1 hop when a single small record matches. Benchmarks explicitly track `expand_rate`. |
| **2. Write-Time Extraction & Drift** — Turning raw 50k-token chats into clean summaries is hard, and summaries drift from edited records. | `rsym_store` is schema-first (deterministic zero-LLM extraction by default, plus an optional swappable `OllamaExtractor`). Every read verifies `sha256(canonical_text)` and flags `STALE_DRIFT` immediately on mismatch. |
| **3. BPE Tokenization & Persistence Reality** — Invented shorthand fragments in BPE tokenizers, and sensitive telemetry should never hit disk. | Uses plain structured English (`PROJECT:`, `CONSTRAINT:`) benchmarked with `js-tiktoken` (`o200k_base`). Enforces a hard `durable` (SQLite FTS5) vs. `volatile` (zeroable RAM) tier boundary—`SqliteStorageAdapter` rejects `biometric`/`volatile` writes. |

---

## Quick Start (Requires Node 22.5+ — Zero Native C++ Build)

```bash
git clone https://github.com/OmnisMutus/rsym-mcp.git
cd rsym-mcp
npm install
npm run build
npm test
npm run bench
```

### Compress Any Local File or Folder into an AI Handoff Pack (`rsym-pack`)

Compress a large Markdown file or repository folder locally (auto-skipping `.git`, `node_modules`, lockfiles, and binaries) into a compact, SHA-256-verified `RSYM_LLM_HANDOFF_PACK` you can paste into any LLM chat:

```bash
npm run pack -- ./docs/big-spec.md --out rsym-pack.md
npm run pack -- ./my-project-folder --max-clusters 8
```

### Connect to Claude Desktop / Cursor (`mcpServers`)

```json
{
  "mcpServers": {
    "rsym": {
      "command": "node",
      "args": [
        "/ABSOLUTE/PATH/TO/rsym-mcp/dist/server/cli.js",
        "--storage",
        "sqlite",
        "--db",
        "/ABSOLUTE/PATH/TO/.rsym/memory.db"
      ]
    }
  }
}
```

For strictly zero-persistence sessions (no SQLite file written):
```bash
node dist/server/cli.js --storage ram
```

For optional local LLM write-time extraction on unstructured transcripts (via Ollama):
```bash
RSYM_EXTRACTOR_MODEL=qwen2.5:7b node dist/server/cli.js --extractor ollama
```

---

## Reproducible Benchmark (`npm run bench`)

Tested on David H. Wolpert (2025), *"What computer science has to say about the simulation hypothesis"* (*J. Phys. Complex.* 6, 045010 — **37 pages, 33,983 words, 45,277 BPE tokens**):

- **Top-1 retrieval accuracy**: `5 / 5` (`100%`)
- **Constraint retention**: `100%` across all 5 queries (`0%` under opaque shorthand anti-pattern)
- **5-turn session (naive full PDF every turn)**: `226,385` tokens
- **5-turn session (`rsym_context` + 40% `rsym_expand` rate)**: **`1,221` tokens (`-99.46%` heuristic / `>99.1%` o200k_base)**

---

## Protocol Specification & Contributions

See [`SPEC.md`](./SPEC.md) for the language-independent 3-tool contract (compatible with TypeScript, Rust, or Python servers). Licensed under [MIT](./LICENSE).

TDQS

A3.7/5.0

Scored across 3 tools

Disambiguation5/5

The three tools map cleanly to distinct actions in a retrieve-expand-store triad: rsym_context fetches compact symbol references, rsym_expand materializes a full record from an ID, and rsym_store writes new validated information. Each description explicitly cross-references the others (context returns symbol_refs for expand), leaving no realistic chance of tool misselection.

Naming Consistency4/5

All tools share a uniform rsym_ prefix with lowercase snake_case suffixes, which is highly predictable. The only minor deviation is that rsym_context is a noun-style operation while rsym_expand and rsym_store are verbs, but the underlying pattern is still readable and consistent.

Tool Count4/5

Three tools is a lean, well-scoped set for a memory/context service, and each tool clearly earns its place with no redundancy or bloat. It sits at the low end of the typical 3-15 range, so it is slightly thin but not inappropriately so.

Completeness3/5

The core lifecycle of storing, retrieving context, and expanding a symbol is covered, but there is no operation to update, delete, expire, or list/search stored symbols. An agent that needs to manage or audit Canonical Memory beyond write-and-read will hit a dead end, which is a notable gap for the stated domain.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues