Skip to main content
Glama
mcp-review-gate-example

mcp-review-gate-example

by BindaasDavid
README.md
# mcp-review-gate-example

A small [Model Context Protocol](https://modelcontextprotocol.io) server in TypeScript that shows one pattern I use in production: the model can **propose** an outgoing email, SMS or post, but it can't send or approve anything. Drafts wait in a queue until a person reviews them.

![Terminal session: the client proposes a draft, then a reviewer approves it](docs/screenshot.png)

## Why

When an agent can send messages on someone's behalf, one bad tool call goes straight to a customer. Keeping the approve step out of the model's tool list is a simple fix. The model gets a tool that writes a draft, and the approval lives somewhere only a person can reach (here, a CLI; in a real app, an admin screen or a chat approval card).

```mermaid
flowchart LR
    A[AI client<br/>Claude, Cursor, etc.] -- propose_message --> S[MCP server]
    S -- saves draft<br/>status: pending_review --> Q[(drafts.json)]
    R[Person running<br/>npm run review] -- approve / reject --> Q
    Q -- approved drafts only --> X[Your sender<br/>not included]
```

## Tools

| Tool | What it does | Side effects |
| --- | --- | --- |
| `text_stats` | Counts characters, words and sentences and estimates reading time | None |
| `propose_message` | Saves an email, SMS or post as a draft with status `pending_review` | Writes one draft. Sends nothing. |
| `list_drafts` | Lists drafts, optionally filtered by status | None |

There is no `approve` or `send` tool on purpose. Approval is in [`src/review-cli.ts`](src/review-cli.ts), which the model can't call.

## Run it

Requires Node 20 or later.

```bash
npm install
npm run build
npm test                    # 4 tests, using the SDK's in-memory transport
node examples/client.mjs    # starts the server over stdio and proposes a draft
npm run review              # list drafts waiting for review
npm run review -- approve <id> "optional note"
npm run review -- reject <id> "optional note"
```

Drafts are stored in `drafts.json` in the current folder. Set `DRAFTS_FILE` to use another path.

### Use it from an MCP client

Add it to your client's MCP config (Claude Desktop, Cursor and others use this shape):

```json
{
  "mcpServers": {
    "review-gate": {
      "command": "node",
      "args": ["/absolute/path/to/mcp-review-gate-example/dist/src/index.js"],
      "env": { "DRAFTS_FILE": "/absolute/path/to/drafts.json" }
    }
  }
}
```

Then ask the assistant to draft a follow-up email. It will call `propose_message`, tell you the draft id, and stop there.

## Files

```
src/drafts.ts      JSON-file draft store (swap for a database table in real use)
src/server.ts      MCP server and its three tools
src/index.ts       stdio entry point
src/review-cli.ts  the human side: list, approve, reject
test/              node:test tests against the server through an in-memory client
examples/client.mjs  a minimal stdio client
```

## Taking it further

- Store drafts in a database with row-level security so only reviewers can change status.
- Send approved drafts from a separate worker that checks the status again right before sending.
- Record who approved what and when (the store already keeps `reviewer` and `reviewedAt`).

## License

MIT

TDQS

B3.4/5.0

Scored across 3 tools

Disambiguation4/5

Each tool targets a clearly different operation: text analysis, draft creation, and draft listing. The only mild wrinkle is text_stats, which is a generic utility that sits oddly beside the review-gate workflow, but it is not confusable with the other two.

Naming Consistency4/5

All names use consistent snake_case, which is good. However, propose_message and list_drafts follow a verb_noun pattern while text_stats is noun-first, a minor deviation from the otherwise predictable convention.

Tool Count3/5

Three tools is on the thin side for a review-gate server, and one of them (text_stats) is a peripheral utility rather than core functionality. The set is small enough to be scoped but borders on under-specified.

Completeness2/5

The draft lifecycle is incomplete: agents can create and list drafts but cannot approve, reject, retrieve a single draft, or delete/withdraw one—approval is only possible via an external CLI. This is a significant gap for the stated review-gate purpose and will cause dead ends for an agent trying to complete the workflow.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues