Skip to content

Add Margaret to OpenCode

Margaret's local MCP server measures Rust source files in the OpenCode workspace and writes the same Markdown report as the CLI.

Build Margaret

From the Margaret repository:

cargo build --release

Use the resulting executable at target/release/marg. OpenCode should be given an absolute executable path unless marg is installed somewhere on its PATH.

Configure the local MCP server

Add this entry to the OpenCode configuration for your project (opencode.json or opencode.jsonc):

{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "servers": {
      "marg": {
        "type": "local",
        "command": ["/absolute/path/to/marg/target/release/marg", "mcp"],
        "cwd": "."
      }
    }
  }
}

Replace /absolute/path/to/marg with the directory containing the Margaret checkout. The cwd value is relative to the OpenCode workspace, so "." measures the currently opened project. If marg is on OpenCode's PATH, the command can instead be ["marg", "mcp"].

Start or reload OpenCode, then list configured MCP servers with opencode mcp list. OpenCode normalizes the tool name to marg_audit_project; with default Code Mode, it is available as tools.marg.audit_project.

Measurements

The audit_project tool takes no arguments. Each call discovers Rust source files again and rewrites the day's report at:

docs/reports/report-marge-YYYY-MM-DD.md

Its structured result contains per-file paths, byte sizes, and physical-line counts; totals; read warnings; and the generated Markdown. Byte size is measured from raw file contents. Physical lines count LF-terminated lines plus a nonempty final line without LF. .git and target directories are excluded, and symlinks are not followed. If a file cannot be read, the result includes a warning and sets verification_complete to false.