MCP Server
The contract of @aburi/mcp: a Model Context Protocol server that answers an AI coding agent's questions about a workspace — what a change did, what a component exposes and which effects it reaches, what one Symbol is — from the runs of the aburi CLI it makes.
See: cli-spec.md §5 (aburi scan), §6 (aburi diff), §7 (aburi explain), §9 (exit codes); slice-view.md (the clusters diff can narrow to) Implementation: packages/mcp
1. Purpose
Without the server an agent that wants Aburi's facts runs the CLI, finds the output directory, and parses the IR or the Markdown itself. The server puts those facts behind tools an agent can call by name with typed arguments, so that the agent asks "what did this branch change" and gets the report a reviewer would read.
It changes nothing about what Aburi is. The server holds no model and calls none: it returns what the CLI computed, and the reading belongs to the agent. Nothing is added to the IR for it either — no free-text field written for a model — since every byte of the IR is a fact the scan can reproduce.
2. Running it
aburi-mcp [--cwd <path>] [--config <path>]The server speaks MCP over stdio: requests on stdin, answers on stdout, one JSON-RPC message per line. It serves the workspace of the directory it is started in, or of --cwd; --config is passed to every run it makes, as --config is to the CLI (cli-spec.md §13). --help and --version print and exit 0; any other argument exits 2 with the reason on stderr.
The server exits 0 once stdin closes: the calls then in flight are cancelled (MC-3), and it ends when their runs have, removing its directory (MC-4). SIGINT or SIGTERM closes the connection, waits for the runs to end and removes the directory, then ends the process on that signal; a second one ends it at once, the directory removed but the runs not waited for. Windows has no such signal for one process to send another: one ended from outside, Ctrl-C aside, ends at once, and its directory stays in the system's temporary directory.
An agent is configured with the command, for instance:
{ "mcpServers": { "aburi": { "command": "npx", "args": ["-y", "@aburi/mcp"] } } }Rule MC-1: every answer comes from runs of the aburi CLI, each in a process of its own, started in the directory the server serves with the server's environment. A call naming a scan reads what that scan's run wrote and makes no run of its own; explain naming none makes two, the scan and then aburi explain. What a call answers is what its runs wrote: their stdout, their stderr, their exit codes and the files they wrote. A plugin that writes to stdout, calls process.exit() or leaks memory does so in that process, so it neither corrupts the protocol nor outlives the call, and an answer is the CLI's own by construction, not a second rendering of the same IR that could drift from it.
Rule MC-2: the CLI a run starts is the workspace's own @aburi/cli, the one Node resolves from the directory the server serves upward, at the time of the run. Only where none resolves does the server run the @aburi/cli it was installed with; one that is there but does not load, a package.json that does not parse for instance, fails the call instead. A plugin aburi.json names by package is imported from where the CLI is installed, so the workspace's CLI loads the plugins the workspace installed, and a server fetched by npx answers about the workspace as aburi scan there would. The CLI of its own loads only the plugins aburi.json names by path. Each run in the structured result names the bin it started.
Rule MC-3: calls are run one at a time, in the order they arrive. A run sizes its work as the only one on the machine, aburi diff running its two scans at once (cli-spec.md §14.1), and the scans' ids follow the order of the calls. A call the client cancels ends its run with SIGTERM, and with SIGKILL if it is still running five seconds later, since a plugin can hold SIGTERM. On POSIX SIGTERM lets an interrupted aburi diff remove what it was building (cli-spec.md §6.4 step 8); on Windows the process is ended at once, as after SIGKILL anywhere, and the server removes what the run left (MC-4). The next call starts only once that run has exited and that is done.
Rule MC-4: the server writes only in a directory of its own under the system's temporary directory, never in the workspace: no .aburi/, no aburi.ir.json an aburi explain would later read. Each run is given a directory inside it as its system temp dir (TMPDIR, TEMP and TMP), so the base worktree of an aburi diff is made there too. When the run ends, whatever it left there is removed, a worktree unregistered from the repository first. The server's directory is removed when the connection closes, and with it every scan the server made; a scan that wrote no answer is removed at once. What the server cannot remove is reported on its stderr, and never replaces the answer.
3. Tools
| Tool | Input | Runs | Answers with |
|---|---|---|---|
scan | — | aburi scan --output-dir <a directory of its own> | The run's stdout (the census lines, §5.5 of cli-spec), the id of the scan, and its Components' ids |
workspace | scan? | A scan, when no scan is named | That scan's workspace.md |
component | id, scan? | Likewise | That scan's components/<id>.md: the Component's public API, its Symbols and the effects they reach |
explain | target, scan? | Likewise, then aburi explain <target> --ir <that scan's IR> | The run's stdout: the Symbol's, or the file's, Markdown, or the candidates an ambiguous target matches |
diff | refspec, or base and head; format?, failOn?, failOnScope?, maxBytes?, symbol? | aburi diff with them and --output-dir <a directory of its own> --format both | diff.md, or diff.json under format: "json", or the Slice holding symbol |
scannames a scan an earlier call made,scan-1and so on in the order they were made, so that several questions are asked of one scan. Without it,workspace,componentandexplainscan first and answer from that scan, whose id their answer carries for the next call. A scan is never reused unasked: an agent edits the tree between calls, and a stale answer would read as a fresh one.refspecis<base>..<head>asaburi difftakes it. The head is scanned from the working tree, soHEAD..HEADis what the uncommitted edits did.baseandheadare each a scan's id or the path of an IR file, sodiffwithbase: "scan-1"andhead: "scan-2"is what changed between two scans of the tree, committed or not.failOnis a list of--fail-onvalues (cli-spec.md§6.7),failOnScopeis--fail-on-scope, andmaxBytesis--max-bytes, cappingdiff.md. The uncappeddiff.full.mda capped report points to is not returned, since the server removes the run's output: the call withoutmaxBytes, or withformat: "json", has every change.targetandrefspecfollow--on the command line, so a value that reads as an option is still the target or the refspec.symbolis a Symbol id. The answer is then JSON: the Slice whose members hold it (slice-view.md) and the change of each member, fromdiff.json.
Every answer carries, beside its text, a structured result with each run's bin, arguments, exit code and stderr, and the scan it read when there is one, failures included. The stderr is the second text block of the answer when it is not empty, headed aburi <command> wrote on stderr (exit <code>):, since what a scan warns about — a file it withdrew, a value it could not classify — qualifies the answer. Each run is started with FORCE_COLOR=0, so that stderr holds no colour whatever the server's environment says: the client gets it as text.
Rule MC-5: a call fails (isError) when its run gave no answer: a scan or a diff that ended on a signal or with a code other than 0 and 3, or wrote no IR, diff.json, diff.md or page, or one that does not parse; an explain that ended on a signal or printed nothing. A scan the client cancelled gives no answer either, even with its IR written, and no scan it wrote is named. The text's first line says how the run ended and what it lacks, the rest is the run's stderr, which says why, and the exit code is the CLI's (§9 of cli-spec). A run that answered and also exited non-zero answers: a scan that withdrew a file (3), a diff whose failOn tripped (3), an explain with several candidates (2). A scan or a component the call names that does not exist fails too, listing the ones that do; a diff symbol no Slice holds fails naming that Symbol alone.
4. Verifiable Properties
| ID | Input | Expected |
|---|---|---|
| MC1 | tools/list | The five tools of §3, each with an input and an output schema |
| MC2 | scan over a TypeScript workspace, then workspace and component naming that scan | The census lines of aburi scan over the same tree; workspace.md and every components/<id>.md that run writes, byte for byte |
| MC3 | explain of a full Symbol id, of a file, and of a pattern several Symbols match | The stdout of aburi explain <target> --ir <the scan's IR>, with exit 0, 0 and 2; a target nothing matches fails with No matches |
| MC4 | workspace, component or explain naming no scan, twice | Each scans afresh and says which scan it read, scan-1 then scan-2 |
| MC5 | diff with refspec: "HEAD..HEAD" over an uncommitted edit, as Markdown and as JSON | diff.md and diff.json of aburi diff HEAD..HEAD; nothing written in the workspace |
| MC6 | diff with base and head naming two scans, before and after an edit | The report of aburi diff --base <first IR> --head <second IR> |
| MC7 | diff with a failOn that trips, with and without FORCE_COLOR=1 in the server's environment | Not a failure: the report, exit 3, and the tripped clause on stderr, uncoloured |
| MC8 | diff with symbol naming a changed Symbol, and one naming no changed Symbol | The Slice holding it and its members' changes; the second fails, naming the Symbol |
| MC9 | component or scan naming one that does not exist | Fails, listing the ids that do |
| MC10 | A workspace whose language plugin cannot be loaded | scan fails with the CLI's message and exit 3 |
| MC11 | Two diff calls sent at once | The second run starts once the first has exited |
| MC12 | aburi-mcp over stdio, then stdin closed | The tools listed and a scan answered; the process exits and its directory is gone |
| MC13 | aburi-mcp --bogus | exit 2, the argument named on stderr |
| MC14 | A scan the client cancels while a plugin that holds SIGTERM is loading, then another call | The run's process has exited before the next call is answered, and the cancelled scan is given no id |
| MC15 | A workspace whose node_modules holds an @aburi/cli, and one whose @aburi/cli has a package.json that does not parse | Every run starts that CLI, and each run names its bin; the second fails, naming the package.json |
| MC16 | explain with a target of --output, --config or -x; diff with a refspec of --config=<path> | Each read as the target or the refspec: no matches, and not a valid ref spec; nothing written in the workspace |
| MC17 | explain naming a scan after the tree was edited | That scan's answer, from one run |
| MC18 | A scan that exits 1 after writing its IR, one that writes an IR cut short, and one that writes no workspace.md | Each call fails saying what the run lacks; the first two are given no id |
| MC19 | --config given to the server, maxBytes or failOnScope given to diff | The run is given --config, --max-bytes or --fail-on-scope with the value |
| MC20 | A diff of HEAD..HEAD the client cancels while a plugin that takes away the CLI's SIGTERM handling is loading | The base worktree is unregistered and removed once the run is killed, and the server's directory holds no run's temp dir |
| MC21 | A diff, or the server closing, where the directory cannot be removed | The report answered, or the server closed, and the directory named on stderr |
| MC22 | The server closing, or aburi-mcp's stdin closing, while a run is going | The run's process ends, and the server's directory is removed |
5. Design Decisions
5.1 Why a package of its own, not aburi mcp
The protocol SDK and its schema library would ride along with every @aburi/cli install, the GitHub Action's included, to serve a use most installs never have. A package that depends on the CLI keeps the CLI's dependencies what they are, and its version is the CLI's it was released with.
5.2 Why a process per call, not the CLI's functions in the server
The CLI's functions would answer faster by the cost of starting Node, a fraction of a second against the seconds of a scan. In exchange the server would share its process with every plugin the workspace loads: a console.log in a plugin would write into the protocol stream, a process.exit() would end the server, and module state a plugin keeps would carry from one call to the next where the CLI starts clean. A process per call also makes every answer the CLI's own output rather than a second rendering of it.
5.3 Why every question scans, unless it names a scan
An IR on disk says nothing of the edits made since it was written, and an agent is the one making them. Answering from the newest scan the server made would be as stale. A scan the call names is reused, because then the agent chose it; one it does not name is made, because then the agent asked about the tree.
5.4 Why the workspace's CLI before the server's own
A bare plugin name in aburi.json is imported by the CLI from its own install location, so the CLI decides which plugins a scan can load. The workspace's CLI was installed beside the workspace's plugins and is the one its CI runs; the server's own, fetched by npx into a cache of its own, reaches none of them. Running the workspace's also keeps an answer the same as the aburi scan a reviewer runs there, at the version the workspace pinned.
5.5 Why stdio only
The server answers about the files of the machine it runs on, for the agent that started it. A network transport would add a listener, and the authentication it then needs, to serve a client that is already its parent process.