English
AI agents (MCP)
This guide covers the MCP server for coding agents:
- Install
- The tools
- The docs corpus
- Migration writes
- Errors
- Architecture
- Generating code
@c9up/ream-mcp is Ream's Model Context Protocol server. It turns a project into an agent-readable workspace: an LLM queries grounded documentation, introspects the live project, scaffolds code and navigates traceability, instead of loading hundreds of files into its context.
Install
sh
npx --no @c9up/ream-mcp # launches the stdio serverThe server finds the project root by walking up from the working directory, checking in order:
reamrc.ts— the canonical config nameream.config.ts— the legacy alias- a
package.jsonnaming@c9up/reamin its dependencies
REAM_PROJECT_ROOT=/path/to/project overrides it.
A root found above the working directory must belong to you: the server refuses a directory that another user owns, or that group or others can write to, and stops with E_REAM_MCP_PROJECT_ROOT_NOT_FOUND. This is git's safe.directory rule. Without it, a reamrc.ts that someone else drops into a shared directory such as /tmp would become your project root, and the generators would run that directory's node_modules/.bin/ream. The working directory itself and REAM_PROJECT_ROOT are not checked: you chose them. A server registered for your user and started through npx has the same exposure at the npx level, so register it per project, as below.
ream mcp install registers it in the project's .mcp.json, a file meant to be committed, so the entry is the same on every machine: npx --no @c9up/ream-mcp, with no absolute path. --no runs the version the project's lockfile pins and never downloads one, so add the server as a dependency first:
sh
ream add -D @c9up/ream-mcp
ream mcp installThe tools
Call tools/list for the authoritative descriptors — they track the package. The current categories:
| Category | What it exposes |
|---|---|
docs | grounded documentation + hybrid search over the project's docs (see below) |
introspect | routes, providers, decorated services |
generate | controllers, entities, providers, modules… |
migrations | status, run, rollback |
security | security-surface checks |
doctor | environment health checks |
inker | template-engine helpers |
station | admin-panel tooling |
scheduler | scheduled-task inspection |
bmad | BMAD workflow helpers |
The docs corpus
The docs tools index a fixed set of files and nothing else: the root README.md, docs/**/*.md, packages/<name>/README.md and packages/<name>/CORRECTIONS.md, and _bmad-output/planning-artifacts/**/*.md. Markdown anywhere else — what an app's users upload under storage/, a note in tmp/ — never reaches the agent as documentation.
Migration writes
migration.run and migration.rollback preview by default. Running one for real (dryRun: false, confirm: true) is refused unless the user enabled it when launching the server — the model calling a tool writes all of its arguments, so no argument can:
| Launch env | Allows |
|---|---|
REAM_MCP_ALLOW_MIGRATIONS=1 | writes to a local database: a sqlite file inside the project, or a loopback / unix-socket server, judged on the address the driver dials (the URL's host and hostaddr, PGHOST, PGHOSTADDR) |
REAM_MCP_ALLOW_PRODUCTION_MIGRATIONS=1, with the above | writes to production: REAM_ENV / NODE_ENV is production, or the database URL is anything not provably local |
Set them in the env block of the server's .mcp.json entry:
json
{
"mcpServers": {
"ream": {
"command": "npx",
"args": ["--no", "@c9up/ream-mcp"],
"env": { "REAM_MCP_ALLOW_MIGRATIONS": "1" }
}
}
}A preview is not side-effect free either: to collect the SQL it imports each migration module and runs its up() / down() inside the server, so it executes the project's code.
A preview, like migration.status, changes no schema: it never creates the migrations tracking table. Where that table does not exist nothing has been migrated, so a rollback (preview or real) returns an empty list and says so in knownGaps.
Errors
An unknown tool name is a JSON-RPC error (-32602). A tool that runs and fails — including every structured refusal ({ error, hint }) — returns a result with isError: true. Messages carry no stack trace and no absolute path; the full detail goes to the server's stderr.
Each tool also declares MCP annotations (readOnlyHint, destructiveHint), so a client can ask before the calls that write and let the read-only ones through. The two inker tools are not read-only: they import the project's own @c9up/inker and run it inside the server (and a render runs the template's expressions), so they carry destructiveHint: true. Use them on a project you trust.
Architecture
TypeScript + Rust through NAPI, like Atom and the core's events:
packages/ream-mcp/
├── src/ TS server + utilities
├── crates/
│ ├── ream-mcp-core/ pure Rust business logic
│ └── ream-mcp-napi/ thin #[napi] bindings
└── scripts/copy-napi.mjs cargo cdylib → .node copyA stdio MCP server must never write to stdout — that would corrupt the JSON-RPC stream. All observability goes through stderr, and any tool added here inherits that constraint.
Generating code
The generate tools delegate to ream-cli and hand back its JSON output verbatim. They propose first (plannedFiles) and write only after confirmation, so an agent can show what it is about to do before doing it.