# Working with an agent fast-decomp's main user is an AI agent reverse-engineering a program for hours: it searches, reads functions, forms hypotheses, records names and types, and reads again. There are three ways to give an agent the tool, from simplest to fastest: 1. **Files.** `fast-decomp export BIN --out DIR` writes one file per function and index files; any agent with file tools can `grep` and read them. Nothing to configure, but the files do not change when the agent records something until the next export. 2. **The command line.** The agent runs `fast-decomp decompile`, `xrefs`, `annotate` ... as shell commands. Every command applies the project, but each one loads the binary again: well under a second for most programs; on the Godot editor about 1.5 s for `annotate`, 2.7 s for `decompile` and 11 s for `xrefs` or `strings`, which analyse every function. 3. **A session.** `fast-decomp serve BIN` (JSON lines) or `fast-decomp mcp BIN` (Model Context Protocol) analyses the whole program once and answers from memory in milliseconds, with exactly the text a full export would write, kept up to date as the agent annotates. In every case, start with `fast-decomp project init BIN` and give the agent the generated `BIN.fdproj/AGENTS.md` as its instructions: it explains the project format, the commands and the session with examples taken from that binary. The examples below use the demo program of [getting started](getting-started.md). ```sh cc -O2 -o demo crates/fd-cli/tests/project_fixture.c fast-decomp project init demo ``` ## The session protocol (`serve`) `fast-decomp serve demo` reads one JSON request per line on standard input and writes one JSON answer per line on standard output, in order; progress goes to standard error. A request has an `id` (echoed), an `op` and the operation's parameters: ```jsonl {"id":1,"op":"functions","name":"list","limit":3} {"id":2,"op":"callers","function":"list_sum","depth":2} {"id":3,"op":"strings","grep":"%d"} {"id":4,"op":"decompile","function":"list_sum","facts":false} {"id":5,"op":"annotate","record":{"func":"0x1280","name":"count_items","note":"counts nodes, flag bit 0 counts twice"}} {"id":6,"op":"changes_since","token":0} {"id":7,"op":"decompile","function":"nope"} ``` Answers (cut): ```jsonl {"id":2,"ok":true,"token":0,"result":{"root":"0x12c0","root_name":"list_sum","callers":[{"address":"0x1090","name":"main","depth":1,"kind":"call","from":"0x12c0"},{"address":"0x13c0","name":"player_score","depth":1,"kind":"call","from":"0x12c0"}],"truncated":false}} ... {"id":6,"ok":true,"token":1,"result":{"since":0,"functions":[{"address":"0x1090","name":"main","changed_in":1},{"address":"0x1280","name":"count_items","changed_in":1}],"total":2,"next":null}} {"id":7,"ok":false,"token":1,"error":{"code":"not-found","message":"no function is named `nope` (functions with `name` or `regex` searches names)","exit":2,"candidates":[]}} ``` Every answer carries a `token`, the session's change counter. After annotating, `changes_since` with the token of your earlier reads lists exactly the functions whose text changed (here the renamed function and its caller `main`). Errors have a stable `code` and the session goes on. `{"op":"help"}` lists every operation and parameter; the [session reference](../reference/SERVE.md) has the full protocol, the limits (paging with `limit` and `cursor`, texts in windows of `max_bytes`) and the measured latencies. The session watches the project's files: records written by one-shot `annotate` commands or by hand are applied at the next request. ## MCP `fast-decomp mcp BIN` serves the same operations as MCP tools over standard input and output (protocol revisions 2024-11-05 to 2025-11-25 by handshake, and the per-request revision 2026-07-28). The tools are `info`, `functions`, `decompile`, `disasm`, `xrefs`, `strings`, `globals`, `classes`, `class`, `vtables`, `callers`, `callees`, `common_refs`, `annotate`, `project_init`, `project_check`, `project_status` and `changes_since`; all but `annotate` and `project_init` are marked read-only. A tool's text answer puts the C first and the JSON after it. An MCP client is configured with the command line. For Claude Code, from the directory that holds the binary: ```sh claude mcp add --scope project fast-decomp -- fast-decomp mcp ./demo ``` which writes this `.mcp.json` (the format other MCP clients use as well; give the binary's absolute path if the client starts servers elsewhere): ```json { "mcpServers": { "fast-decomp": { "type": "stdio", "command": "fast-decomp", "args": ["mcp", "./demo"], "env": {} } } } ``` The server analyses the binary when the client starts it (0.4 s for SQLite, about 23 s for the Godot editor), then answers each tool call from memory. One server serves one binary; add one entry per binary. ## An agent loop What works well, as instructions to give an agent together with `AGENTS.md`: 1. **Orient.** `info`; `functions` with `name` or `regex` for what is named; `strings` with `grep` for messages (error texts, file formats, UI strings) and the functions that use them; `classes` for a C++ program. 2. **Read.** `decompile` a function; follow `callers` and `callees` (to a depth); use `xrefs` on a global or a string to find the other users; `common_refs` finds the functions that use several things at once. 3. **Record** what is established, with the evidence in `note`: a name (`func` + `name`), a prototype with structure types (`sig`), the structure itself in `types.h` (`annotate` with `types`), comments. Record many at once with `records`. 4. **Re-read** what `changes_since` lists: names and types now show in every function that shares them, and new structure accesses become readable. 5. **Check** with `project_check` from time to time: records that no longer apply, names another function took, structures nothing anchors. Treat `likely` facts as leads to confirm, not as findings: they are heuristics (a result that may be `void`, a name derived from an error message, an inferred base class). A `__clobbered_*` read, an `__unknown(...)` effect or a `goto` is not an error of the agent's reading; the [reading guide](reading-output.md) says what each means. The same loop works over the command line (`decompile --json`, `xrefs`, `annotate --batch -`), one process per step; on a binary of a few thousand functions the difference is small, on a game it is a second or two per step against milliseconds.