Skip to main content
Glama
review-memory-mcp
by iboruch
README.md
# review-memory-mcp

[![CI](https://github.com/iboruch/review-memory-mcp/actions/workflows/ci.yml/badge.svg)](https://github.com/iboruch/review-memory-mcp/actions/workflows/ci.yml)
[![npm](https://img.shields.io/npm/v/review-memory-mcp)](https://www.npmjs.com/package/review-memory-mcp)

An MCP server that gives coding agents (Claude Code, Cursor, Codex, Copilot…) a **searchable library of bug patterns for code review**. It comes with an **eval suite** that measures whether retrieval actually surfaces the right patterns, including on a held-out set the retrieval was never tuned on.

```bash
claude mcp add review-memory -- npx -y review-memory-mcp
```

**Why it exists.** I run a builder agent and an adversarial reviewer agent on a production codebase. Every bug that slips past review becomes a written lesson the reviewer must check next time. Past ~180 lessons, the reviewer started missing lessons that were clearly in its notes: a flat, append-only file doesn't scale as agent memory. Filing lessons by failure mode, with an index and a short always-check list, fixed it. This project rebuilds that idea as a reusable server, with general patterns written from scratch, and measures it.

## What the agent gets

| Tool | What it does |
|---|---|
| `search_lessons` | Top-k bug patterns for a diff and/or a description, each with a concrete *where to look* action |
| `lessons_for_files` | Patterns that apply to the kinds of files a change touches (migrations, tests, webhooks…) |
| `add_lesson` | Files a new pattern; enforces the filing rule. **Off by default.** |

Resources: `lessons://checklist` (the short always-check list), `lessons://index` (every lesson by failure mode, plus loaded packs).

**46 lessons in 13 failure modes:** money and idempotency, concurrency, auth and permissions, migrations and data, untrusted input, error handling, tests that pin nothing, stale verification, alerts and observability, time and dates, performance, secrets and config, API contracts.

Each lesson is a general pattern, not an incident: what goes wrong, why, and the concrete check a reviewer should run.

## Evals

`npm run eval` scores four retrieval strategies (k = 3):

- **flat**: word overlap with the lesson text, i.e. how an agent rereading a big notes file behaves
- **indexed**: each lesson's declared trigger keywords and file globs
- **bm25**: BM25 over lesson text and keywords
- **hybrid** (default): reciprocal-rank fusion of indexed and bm25

![Recall@3 on the held-out set: flat notes file 51%, declared triggers 64%, BM25 73%, hybrid 80%](docs/eval-card.png)

**Held-out set:** 40 cases (35 positive, 10 of them with two bugs; 5 harmless changes). It was written by a separate agent that saw only lesson titles and descriptions, never the trigger keywords, and was told not to reuse the lessons' wording. Retrieval wasn't tuned on it.

| strategy | recall@3 | MRR | precision@3 | quiet on harmless changes |
|---|---|---|---|---|
| flat | 51% | 0.55 | 22% | 0% |
| indexed | 64% | 0.65 | 33% | 60% |
| bm25 | 73% | 0.75 | 34% | 60% |
| **hybrid** | **80%** | 0.71 | 35% | 60% |

**Dev set:** 49 cases written alongside the lessons and used for tuning. Hybrid scores 98% recall@3 and is quiet on 4/4 harmless changes. It's reported for completeness; the held-out row is the honest number.

What this shows: structure beats a flat file by about 30 points of recall, and combining declared triggers with BM25 beats either one alone. What it doesn't show yet: the harmless-change false-positive rate is still too high (2 of 5 held-out harmless changes get a lesson), and precision@3 is capped near 33–50% because most cases have one or two correct answers. The misses are listed with `npm run eval -- --misses` and deliberately left unfixed, so the held-out number stays honest. The next step is a fresh held-out set.

CI runs `npm run eval:gate` on every push. It fails if hybrid drops below 90% recall on dev or 75% on held-out, or gets noisier on harmless changes, so a new lesson or a retrieval tweak can't silently make the agent worse.

Roadmap: an embedding strategy (optional dependency), and an end-to-end eval where an agent reviews diffs with seeded bugs, with vs without this server.

## Install

**Claude Code**
```bash
claude mcp add review-memory -- npx -y review-memory-mcp
```

**Cursor / Windsurf / Claude Desktop / others**: add to the MCP config:
```json
{ "mcpServers": { "review-memory": { "command": "npx", "args": ["-y", "review-memory-mcp"] } } }
```

**Agent skill**: [`skill/SKILL.md`](skill/SKILL.md) tells the agent when to call the server and how to turn results into a review (each lesson checked, with findings tied to file:line). Copy it into `.claude/skills/review-memory/SKILL.md` or your agent's equivalent.

## Configuration

| Env var | Effect |
|---|---|
| `REVIEW_MEMORY_PACKS` | Extra lesson packs to load, separated by `:` (macOS/Linux) or `;` (Windows). A later pack overrides an earlier lesson with the same id. |
| `REVIEW_MEMORY_NO_CORE=1` | Don't load the built-in 46 lessons. |
| `REVIEW_MEMORY_LESSONS` | Your team's own lessons file, loaded last. `add_lesson` writes here. |
| `REVIEW_MEMORY_ALLOW_WRITES=1` | Enables `add_lesson`. Without `REVIEW_MEMORY_LESSONS`, writes go to `./.review-memory/lessons.json`, so team memory lives in the repo and changes to it are reviewed in PRs. |

A pack is a JSON file `{ "name": "...", "lessons": [ ... ] }` using the same schema as [`data/lessons.json`](data/lessons.json). Invalid packs are rejected at startup with the failing field.

## Guardrails
- Read-only unless writes are explicitly enabled: an agent shouldn't grow its own memory unsupervised.
- Every tool input is schema-validated (zod). Lessons that break the filing rule are rejected: a general pattern of 40+ characters, a concrete where-to-look action, a known category, and trigger keywords.
- Writes go only to the team file, never to the core pack, and each one is appended to `audit.log`.
- stdout is reserved for the protocol; logs go to stderr.

## Develop

```bash
npm install
npm test                    # unit + in-memory MCP client tests
npm run eval -- --misses    # eval tables, with every miss listed
npm run dev                 # run the server over stdio
```

Contributions of lessons are welcome via PR; CI runs the eval on every change. A good lesson is one you've seen escape a real review, written so it applies beyond the bug that taught it.

MIT © Igor Boruch