diff --git a/docs/assets/clients/claude.svg b/docs/assets/clients/claude.svg new file mode 100644 index 00000000..a57de590 --- /dev/null +++ b/docs/assets/clients/claude.svg @@ -0,0 +1 @@ +Claude \ No newline at end of file diff --git a/docs/assets/clients/cursor.svg b/docs/assets/clients/cursor.svg new file mode 100644 index 00000000..3f7cf60c --- /dev/null +++ b/docs/assets/clients/cursor.svg @@ -0,0 +1 @@ +Cursor \ No newline at end of file diff --git a/docs/assets/clients/githubcopilot.svg b/docs/assets/clients/githubcopilot.svg new file mode 100644 index 00000000..e0db5a53 --- /dev/null +++ b/docs/assets/clients/githubcopilot.svg @@ -0,0 +1 @@ +GitHub Copilot \ No newline at end of file diff --git a/docs/assets/clients/googlegemini.svg b/docs/assets/clients/googlegemini.svg new file mode 100644 index 00000000..4c5e55e5 --- /dev/null +++ b/docs/assets/clients/googlegemini.svg @@ -0,0 +1 @@ +Google Gemini \ No newline at end of file diff --git a/docs/assets/clients/mcp.svg b/docs/assets/clients/mcp.svg new file mode 100644 index 00000000..7e7eafe7 --- /dev/null +++ b/docs/assets/clients/mcp.svg @@ -0,0 +1 @@ +Model Context Protocol \ No newline at end of file diff --git a/docs/assets/clients/openai.svg b/docs/assets/clients/openai.svg new file mode 100644 index 00000000..5104a1e5 --- /dev/null +++ b/docs/assets/clients/openai.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/docs/assets/clients/windsurf.svg b/docs/assets/clients/windsurf.svg new file mode 100644 index 00000000..7913377e --- /dev/null +++ b/docs/assets/clients/windsurf.svg @@ -0,0 +1 @@ +Windsurf \ No newline at end of file diff --git a/docs/concepts/safety-model.mdx b/docs/concepts/safety-model.mdx index ec64af5e..8a9b31c2 100644 --- a/docs/concepts/safety-model.mdx +++ b/docs/concepts/safety-model.mdx @@ -19,7 +19,7 @@ Nothing in the gate path reads or writes your real working tree. Refactron build /> -For [`verify-diff`](/verification/verify-diff) and the [MCP `verify_change` tool](/verification/mcp-server), this is the whole story: the shadow tree is built, the gates run, the verdict is returned, and the copy is cleaned up. **Your repo is never mutated.** Landing the change is the caller's decision. +For [`verify-diff`](/verification/verify-diff) and the [MCP `verify_change` tool](/mcp/index), this is the whole story: the shadow tree is built, the gates run, the verdict is returned, and the copy is cleaned up. **Your repo is never mutated.** Landing the change is the caller's decision. ## The three gates diff --git a/docs/docs.json b/docs/docs.json index 4725826f..1f54d43b 100644 --- a/docs/docs.json +++ b/docs/docs.json @@ -31,61 +31,97 @@ "dark": "/logo/refactron-symbol-dark.svg" }, "navigation": { - "groups": [ + "tabs": [ { - "group": "Getting Started", - "pages": ["overview", "quickstart", "faq"] - }, - { - "group": "Verification", - "pages": [ - "verification/verify-diff", - "verification/mcp-server", - "verification/verdicts", - "verification/preflight" + "tab": "Documentation", + "icon": "book-open", + "groups": [ + { + "group": "Getting Started", + "pages": ["overview", "quickstart", "faq"] + }, + { + "group": "Verification", + "pages": [ + "verification/verify-diff", + "verification/mcp-server", + "verification/verdicts", + "verification/preflight" + ] + }, + { + "group": "Concepts", + "pages": ["concepts/safety-model", "concepts/why-no-llm"] + }, + { + "group": "CLI", + "pages": ["cli/reference"] + }, + { + "group": "Configuration", + "pages": ["configuration", "configuration/refactronrc"] + }, + { + "group": "Migration mode", + "pages": [ + "transforms/index", + "transforms/callback-to-async-await", + "transforms/format-to-fstring", + "transforms/manual-typecheck-to-hints", + "transforms/deprecated-api-requests-to-httpx", + "transforms/class-to-dataclass", + "transforms/var-to-const-let", + "transforms/promise-chains-to-async", + "transforms/implicit-any", + "transforms/commonjs-to-esm", + "transforms/promise-constructor-to-async", + "transforms/super-no-args", + "transforms/lru-cache-to-cache", + "transforms/pep585-generics", + "transforms/pep604-optional-union", + "transforms/datetime-utc-alias", + "transforms/yield-from-for-loop", + "transforms/indexof-to-includes", + "transforms/object-assign-to-spread", + "transforms/string-concat-to-template-literal", + "transforms/vue-set-delete-to-assignment" + ] + }, + { + "group": "Reference", + "pages": ["changelog", "reference/performance", "reference/citations"] + } ] }, { - "group": "Concepts", - "pages": ["concepts/safety-model", "concepts/why-no-llm"] - }, - { - "group": "CLI", - "pages": ["cli/reference"] - }, - { - "group": "Configuration", - "pages": ["configuration", "configuration/refactronrc"] - }, - { - "group": "Migration mode", - "pages": [ - "transforms/index", - "transforms/callback-to-async-await", - "transforms/format-to-fstring", - "transforms/manual-typecheck-to-hints", - "transforms/deprecated-api-requests-to-httpx", - "transforms/class-to-dataclass", - "transforms/var-to-const-let", - "transforms/promise-chains-to-async", - "transforms/implicit-any", - "transforms/commonjs-to-esm", - "transforms/promise-constructor-to-async", - "transforms/super-no-args", - "transforms/lru-cache-to-cache", - "transforms/pep585-generics", - "transforms/pep604-optional-union", - "transforms/datetime-utc-alias", - "transforms/yield-from-for-loop", - "transforms/indexof-to-includes", - "transforms/object-assign-to-spread", - "transforms/string-concat-to-template-literal", - "transforms/vue-set-delete-to-assignment" + "tab": "MCP", + "icon": "/assets/clients/mcp.svg", + "groups": [ + { + "group": "Get started", + "pages": ["mcp/index", "mcp/quickstart"] + }, + { + "group": "Connect your client", + "pages": [ + { + "group": "Claude", + "icon": "/assets/clients/claude.svg", + "pages": ["mcp/claude-code", "mcp/claude-desktop"] + }, + "mcp/codex", + "mcp/cursor", + "mcp/vscode", + "mcp/gemini-cli", + "mcp/windsurf", + "mcp/other-clients" + ] + }, + { + "group": "Reference", + "pages": ["mcp/tool-reference"] + } ] - }, - { - "group": "Reference", - "pages": ["changelog", "reference/performance", "reference/citations"] } ] }, diff --git a/docs/faq.mdx b/docs/faq.mdx index 8cf4af9c..210bc3ab 100644 --- a/docs/faq.mdx +++ b/docs/faq.mdx @@ -20,7 +20,7 @@ It's the honest verdict, and the reason to trust the other two. `UNPROVEN` means ## Does it work with my AI agent? -Yes, that's the point. Refactron ships an [MCP server](/verification/mcp-server) with a `verify_change` tool. Your agent proposes an edit, calls `verify_change`, and gets back the `SAFE` / `UNSAFE` / `UNPROVEN` report before it lands anything. Refactron doesn't replace Cursor, Claude Code, Copilot, or Codex; it's the deterministic gate they call to check their own work. +Yes, that's the point. Refactron ships an [MCP server](/mcp/index) with a `verify_change` tool. Your agent proposes an edit, calls `verify_change`, and gets back the `SAFE` / `UNSAFE` / `UNPROVEN` report before it lands anything. Refactron doesn't replace Cursor, Claude Code, Copilot, or Codex; it's the deterministic gate they call to check their own work. --- diff --git a/docs/mcp/claude-code.mdx b/docs/mcp/claude-code.mdx new file mode 100644 index 00000000..82ec64e1 --- /dev/null +++ b/docs/mcp/claude-code.mdx @@ -0,0 +1,209 @@ +--- +title: Claude Code +icon: /assets/clients/claude.svg +description: Register the Refactron MCP server with Claude Code using the claude mcp add command or a project .mcp.json. +--- + +Claude Code has a built-in command for this, so you do not have to edit a file by hand. + +## Set it up with your agent + +One prompt, written for Claude Code to read rather than you. It installs the +server, registers it, reloads, and proves the tool works with a real +verification. + +
+ +```text +Set up the Refactron MCP server for yourself in this repository and prove it +works before you tell me it is done. Do the steps in order. + +You are running in Claude Code. + +STEP 1 - Check the prerequisites. + +Run `node --version`. Refactron needs Node.js 18 or newer. If it is older or +missing, stop and tell me. + +Run `python3 --version`, then check that `pytest` and `coverage` are +importable. Coverage attestation is Python-only, and it is what makes a +coverage-backed SAFE verdict possible. Without it the server still runs and +still gates the change, but every verdict caps at UNPROVEN. + +STEP 2 - Install the server. + +Run `which refactron-mcp`, or `where refactron-mcp` on Windows. If it prints a +path, go to step 3. Otherwise install it: + + npm install -g refactron@0.3.0 + +That puts two binaries on PATH: `refactron` (the CLI) and `refactron-mcp` (the +MCP server). If you cannot install globally, install nothing and use the npx +form in step 3 instead. + +Do not use `pip install refactron` for this. The PyPI wrapper provides the +`refactron` command only. It does not ship `refactron-mcp`. + +STEP 3 - Register the server. + +Run: + + claude mcp add refactron -- refactron-mcp + +The `--` separator is required. Use `--scope project` instead if I asked for a +config the whole team gets; that writes `.mcp.json` in the repository root. + +Without a global install, use this instead. The `-p` flag is required, because +`refactron-mcp` is a second binary of the `refactron` package and not a package +of its own: + + claude mcp add refactron -- npx -y -p refactron@0.3.0 refactron-mcp + +STEP 4 - Reload. + +Claude Code picks the server up on the next session. If you are mid-session and +it does not appear in step 5, tell me to restart `claude`. + +A project-scoped `.mcp.json` also needs a one-time approval. If step 5 shows +"Pending approval", tell me to start `claude` in this directory and approve the +server once. + +STEP 5 - Confirm the tool is exposed. + +Run: + + claude mcp list + +`refactron` should show as Connected. `claude mcp get refactron` prints the +full record, including scope and resolved command. Inside a session, `/mcp` +lists connected servers and their tools. + +You are looking for a server named `refactron`, version 0.3.0, exposing exactly +ONE tool: `verify_change`. + +If the server is connected but no tool appears, the handshake failed. Prove the +binary itself works by sending it one initialize request: + + echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"probe","version":"1.0"}}}' | refactron-mcp + +A working server replies on one line with serverInfo.name "refactron". If that +works and the client still shows nothing, the fault is the config: check the +root key and check that the file parses. + +STEP 6 - Prove it works with one real verification. + +Do not skip this. A connected server is not a working server. + +Pick one small source file that this project's test suite exercises. Propose a +real but behaviour-preserving edit to it: reorder the operands of a commutative +expression, rename a local variable, that kind of thing. One or two lines. + +Do NOT write that edit to disk. Call verify_change with the proposal instead: + + repoRoot the ABSOLUTE path to this repository + edits [{ "path": "", + "newContent": "" }] + testCmd the project's test command, if it is not obvious. For a Python + project installed into the environment (an editable + `pip install -e .` included), prefix it with PYTHONPATH=. so the + tests import the copy being verified rather than the installed + one. Use PYTHONPATH=src for a src layout. + +Verify the change BEFORE it exists on disk. The shadow tree is a copy of the +working tree, so if you write the change first and then pass a `git diff` of +it, the diff no longer applies and you get "diff did not apply (stale base?)" +back instead of a verdict. + +Verification runs the whole test suite in a shadow copy, so it can take minutes +on a real project. That is the work, not a hang. + +STEP 7 - Report, then stop. + +Tell me: + - which file you wrote, or which command you ran + - the exact `verdict` and the exact `reason` from the response + - the value of `coverage.tool`: "coverage.py" means coverage was measured, + "none" means it was not + +Apply nothing. The step 6 edit was a probe. Confirm with `git status` that the +working tree is exactly as dirty as you found it, and no more. + +Do not describe a SAFE verdict as "correct", "proven", or "guaranteed". SAFE +means the project's own tests ran the changed code and stayed green. It +inherits exactly what those tests check, and a weak suite yields a weak SAFE. +``` + +
+ +Prefer to do it yourself? The rest of this page is the same setup by hand. + +## Config location + +| Scope | Where it is written | Who sees it | +| --------- | -------------------------------------------------------------- | -------------------------------- | +| `local` | `~/.claude.json`, under the current project path (the default) | You, in this project only | +| `user` | `~/.claude.json`, at the top level | You, in every project | +| `project` | `.mcp.json` in the repository root | Everyone who checks out the repo | + +## Add it + +```bash +claude mcp add refactron -- refactron-mcp +``` + +```text +Added stdio MCP server refactron with command: refactron-mcp to local config +``` + +To share the server with your team, commit it at project scope: + +```bash +claude mcp add --scope project refactron -- refactron-mcp +``` + +That writes `.mcp.json` in the repository root: + +```json +{ + "mcpServers": { + "refactron": { + "type": "stdio", + "command": "refactron-mcp", + "args": [], + "env": {} + } + } +} +``` + +To pin the version without a global install, register the `npx` form instead: + +```bash +claude mcp add refactron -- npx -y -p refactron@0.3.0 refactron-mcp +``` + +## Verify the connection + +```bash +claude mcp list +``` + +```text +refactron: refactron-mcp - ✔ Connected +``` + +For the full record, including scope and resolved command: + +```bash +claude mcp get refactron +``` + +Inside a session, `/mcp` lists connected servers and their tools. You are looking for one tool, `verify_change`, under `refactron`. + +## Troubleshooting + +- **`⏸ Pending approval (run 'claude' to approve)`**: a project-scoped `.mcp.json` needs your approval before it runs. Start `claude` in that directory and approve the server once. +- **`✘ Failed to connect`**: the command is not on your `PATH`. Run `which refactron-mcp`. If it prints nothing, run `npm install -g refactron@0.3.0`, or re-register with the `npx` form above. +- **The server connects but no tool appears**: the handshake failed. Send one `initialize` request straight to the binary as in the [MCP quickstart](/mcp/quickstart#2-smoke-test-the-server-without-a-client) to see whether the server or the client is at fault. +- **Registered in the wrong project**: local scope is keyed to the directory you ran `claude mcp add` in. Run `claude mcp list` from the project you meant, and re-add there or use `--scope user`. +- **Removing it**: `claude mcp remove refactron`, adding `-s project` or `-s user` if you did not use the default scope. diff --git a/docs/mcp/claude-desktop.mdx b/docs/mcp/claude-desktop.mdx new file mode 100644 index 00000000..bafe637f --- /dev/null +++ b/docs/mcp/claude-desktop.mdx @@ -0,0 +1,206 @@ +--- +title: Claude Desktop +icon: /assets/clients/claude.svg +description: Add the Refactron MCP server to Claude Desktop by editing claude_desktop_config.json, then restart the app. +--- + +Claude Desktop reads one JSON file at launch. There is no CLI, and changes take effect only after a full restart. + +## Set it up with your agent + +One prompt, written for Claude Desktop to read rather than you. It installs the +server, registers it, reloads, and proves the tool works with a real +verification. + +
+ +```text +Set up the Refactron MCP server for yourself in this repository and prove it +works before you tell me it is done. Do the steps in order. + +You are running in Claude Desktop. + +STEP 1 - Check the prerequisites. + +Run `node --version`. Refactron needs Node.js 18 or newer. If it is older or +missing, stop and tell me. + +Run `python3 --version`, then check that `pytest` and `coverage` are +importable. Coverage attestation is Python-only, and it is what makes a +coverage-backed SAFE verdict possible. Without it the server still runs and +still gates the change, but every verdict caps at UNPROVEN. + +STEP 2 - Install the server. + +Run `which refactron-mcp`, or `where refactron-mcp` on Windows. If it prints a +path, go to step 3. Otherwise install it: + + npm install -g refactron@0.3.0 + +That puts two binaries on PATH: `refactron` (the CLI) and `refactron-mcp` (the +MCP server). If you cannot install globally, install nothing and use the npx +form in step 3 instead. + +Do not use `pip install refactron` for this. The PyPI wrapper provides the +`refactron` command only. It does not ship `refactron-mcp`. + +STEP 3 - Register the server. + +Claude Desktop has no CLI. Edit its config file, root key "mcpServers": + + macOS ~/Library/Application Support/Claude/claude_desktop_config.json + Windows %APPDATA%\Claude\claude_desktop_config.json + Linux ~/.config/Claude/claude_desktop_config.json + +Create the file if it is missing. If it already has servers, add "refactron" as +another key inside the existing "mcpServers" object rather than adding a second +"mcpServers" block: + + { "mcpServers": { "refactron": { "command": "refactron-mcp" } } } + +Without a global install, use this instead. The `-p` flag is required, because +`refactron-mcp` is a second binary of the `refactron` package and not a package +of its own: + + { "mcpServers": { "refactron": { "command": "npx", + "args": ["-y", "-p", "refactron@0.3.0", "refactron-mcp"] } } } + +Validate the JSON before you finish. Claude Desktop skips a malformed config +silently, so a trailing comma looks exactly like a broken install. + +Claude Desktop launches from the desktop environment, not from your shell, so +it does not inherit PATH additions made in .zshrc or .bashrc. If step 5 reports +`spawn refactron-mcp ENOENT`, put the absolute path from `which refactron-mcp` +in "command" instead. + +STEP 4 - Reload. + +Claude Desktop reads that file once at launch, and it needs a FULL quit and +reopen. Closing the window is not enough on macOS. + +You cannot do this yourself. Tell me to press Cmd+Q, or quit from the Claude +menu, and reopen the app. Wait for me before you continue. + +STEP 5 - Confirm the tool is exposed. + +Ask me to open Settings, then Developer, and read you the server list. +`refactron` should be listed with a `running` status. In a chat, the tools +control below the message box lists the connected servers. + +If it failed to start, the logs are per-server: on macOS +~/Library/Logs/Claude/mcp-server-refactron.log, on Windows +%APPDATA%\Claude\logs\. + +You are looking for a server named `refactron`, version 0.3.0, exposing exactly +ONE tool: `verify_change`. + +If the server is connected but no tool appears, the handshake failed. Prove the +binary itself works by sending it one initialize request: + + echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"probe","version":"1.0"}}}' | refactron-mcp + +A working server replies on one line with serverInfo.name "refactron". If that +works and the client still shows nothing, the fault is the config: check the +root key and check that the file parses. + +STEP 6 - Prove it works with one real verification. + +Do not skip this. A connected server is not a working server. + +Pick one small source file that this project's test suite exercises. Propose a +real but behaviour-preserving edit to it: reorder the operands of a commutative +expression, rename a local variable, that kind of thing. One or two lines. + +Do NOT write that edit to disk. Call verify_change with the proposal instead: + + repoRoot the ABSOLUTE path to this repository + edits [{ "path": "", + "newContent": "" }] + testCmd the project's test command, if it is not obvious. For a Python + project installed into the environment (an editable + `pip install -e .` included), prefix it with PYTHONPATH=. so the + tests import the copy being verified rather than the installed + one. Use PYTHONPATH=src for a src layout. + +Verify the change BEFORE it exists on disk. The shadow tree is a copy of the +working tree, so if you write the change first and then pass a `git diff` of +it, the diff no longer applies and you get "diff did not apply (stale base?)" +back instead of a verdict. + +Verification runs the whole test suite in a shadow copy, so it can take minutes +on a real project. That is the work, not a hang. + +STEP 7 - Report, then stop. + +Tell me: + - which file you wrote, or which command you ran + - the exact `verdict` and the exact `reason` from the response + - the value of `coverage.tool`: "coverage.py" means coverage was measured, + "none" means it was not + +Apply nothing. The step 6 edit was a probe. Confirm with `git status` that the +working tree is exactly as dirty as you found it, and no more. + +Do not describe a SAFE verdict as "correct", "proven", or "guaranteed". SAFE +means the project's own tests ran the changed code and stayed green. It +inherits exactly what those tests check, and a weak suite yields a weak SAFE. +``` + +
+ +Prefer to do it yourself? The rest of this page is the same setup by hand. + +## Config location + +| OS | Path | +| ------- | ----------------------------------------------------------------- | +| macOS | `~/Library/Application Support/Claude/claude_desktop_config.json` | +| Windows | `%APPDATA%\Claude\claude_desktop_config.json` | +| Linux | `~/.config/Claude/claude_desktop_config.json` | + +The app opens this file for you: **Settings** then **Developer** then **Edit Config**. If the file does not exist yet, create it with the contents below. + +## Add it + +```json +{ + "mcpServers": { + "refactron": { + "command": "refactron-mcp" + } + } +} +``` + +If you already have servers configured, add `refactron` as another key inside the existing `mcpServers` object rather than adding a second `mcpServers` block. + +To pin the version and skip the global install: + +```json +{ + "mcpServers": { + "refactron": { + "command": "npx", + "args": ["-y", "-p", "refactron@0.3.0", "refactron-mcp"] + } + } +} +``` + +The `-p` flag is required. `refactron-mcp` is a second binary of the `refactron` package, not a package of its own. + +Quit Claude Desktop completely and reopen it. Closing the window is not enough on macOS: use **Claude** then **Quit**, or `Cmd+Q`. + +## Verify the connection + +Open **Settings** then **Developer**. `refactron` appears in the server list with a `running` status. + +In a chat, the tools control below the message box lists the connected servers. Under `refactron` you should see exactly one tool: `verify_change`. + +## Troubleshooting + +- **The server does not appear at all**: the JSON is invalid. Claude Desktop skips a malformed config silently. Check it with `node -e "JSON.parse(require('fs').readFileSync('','utf8'))"` and look for a trailing comma. +- **`spawn refactron-mcp ENOENT` in the logs**: Claude Desktop launches from the desktop environment, not your shell, so it does not inherit `PATH` additions made in `.zshrc` or `.bashrc`. Use the absolute path from `which refactron-mcp` as the `command` value. +- **Reading the logs**: macOS writes them to `~/Library/Logs/Claude/`, one `mcp-server-refactron.log` per server. Windows uses `%APPDATA%\Claude\logs\`. +- **Edits appear to do nothing**: the config is read once at launch. Quit the app fully and reopen. +- **A verification times out**: `verify_change` runs your whole test suite, which can take minutes. That is the work, not a hang. diff --git a/docs/mcp/codex.mdx b/docs/mcp/codex.mdx new file mode 100644 index 00000000..869bf156 --- /dev/null +++ b/docs/mcp/codex.mdx @@ -0,0 +1,237 @@ +--- +title: Codex CLI +icon: /assets/clients/openai.svg +description: 'Add the Refactron MCP server to OpenAI Codex CLI. Note the format: Codex reads TOML, not JSON.' +--- + +Codex CLI is the one client on this list that does not use JSON. Its MCP servers live in `~/.codex/config.toml`, under a `[mcp_servers.]` table. A config block copied from Claude Desktop or Cursor is not valid here. + +## Set it up with your agent + +One prompt, written for Codex CLI to read rather than you. It installs the +server, registers it, reloads, and proves the tool works with a real +verification. + +
+ +```text +Set up the Refactron MCP server for yourself in this repository and prove it +works before you tell me it is done. Do the steps in order. + +You are running in Codex CLI. + +STEP 1 - Check the prerequisites. + +Run `node --version`. Refactron needs Node.js 18 or newer. If it is older or +missing, stop and tell me. + +Run `python3 --version`, then check that `pytest` and `coverage` are +importable. Coverage attestation is Python-only, and it is what makes a +coverage-backed SAFE verdict possible. Without it the server still runs and +still gates the change, but every verdict caps at UNPROVEN. + +STEP 2 - Install the server. + +Run `which refactron-mcp`, or `where refactron-mcp` on Windows. If it prints a +path, go to step 3. Otherwise install it: + + npm install -g refactron@0.3.0 + +That puts two binaries on PATH: `refactron` (the CLI) and `refactron-mcp` (the +MCP server). If you cannot install globally, install nothing and use the npx +form in step 3 instead. + +Do not use `pip install refactron` for this. The PyPI wrapper provides the +`refactron` command only. It does not ship `refactron-mcp`. + +STEP 3 - Register the server. + +Run: + + codex mcp add refactron -- refactron-mcp + +The `--` separator is required. Everything after it is the command Codex +launches; everything before it is Codex's own flags. + +Codex uses TOML, not JSON. If you edit ~/.codex/config.toml by hand, the entry +is a table, and the prefix is `mcp_servers` with an underscore, not +`mcpServers`: + + [mcp_servers.refactron] + command = "refactron-mcp" + args = [] + tool_timeout_sec = 900 + +Set `tool_timeout_sec` either way, editing the table afterwards if you used +`codex mcp add`. Codex's default per-tool timeout has changed between releases, +and either value can be shorter than a real suite run. When it fires you get a +tool failure rather than the verdict you already paid for. + +Without a global install, use this instead. The `-p` flag is required, because +`refactron-mcp` is a second binary of the `refactron` package and not a package +of its own: + + [mcp_servers.refactron] + command = "npx" + args = ["-y", "-p", "refactron@0.3.0", "refactron-mcp"] + tool_timeout_sec = 900 + +Check for a duplicate [mcp_servers.refactron] table before you finish. Two of +them is a parse error, and Codex rejects the whole config. + +STEP 4 - Reload. + +Codex CLI picks the server up on the next session. If it does not appear in +step 5, tell me to restart `codex`. + +STEP 5 - Confirm the tool is exposed. + +Run: + + codex mcp list + +`refactron` appears with its launch command. `codex mcp get refactron` prints +the resolved entry, and both accept --json. Then start a session and ask for +the tool list. + +If it is configured but never starts, check for `enabled = false` on the table. +That key disables a server without removing it. + +You are looking for a server named `refactron`, version 0.3.0, exposing exactly +ONE tool: `verify_change`. + +If the server is connected but no tool appears, the handshake failed. Prove the +binary itself works by sending it one initialize request: + + echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"probe","version":"1.0"}}}' | refactron-mcp + +A working server replies on one line with serverInfo.name "refactron". If that +works and the client still shows nothing, the fault is the config: check the +root key and check that the file parses. + +STEP 6 - Prove it works with one real verification. + +Do not skip this. A connected server is not a working server. + +Pick one small source file that this project's test suite exercises. Propose a +real but behaviour-preserving edit to it: reorder the operands of a commutative +expression, rename a local variable, that kind of thing. One or two lines. + +Do NOT write that edit to disk. Call verify_change with the proposal instead: + + repoRoot the ABSOLUTE path to this repository + edits [{ "path": "", + "newContent": "" }] + testCmd the project's test command, if it is not obvious. For a Python + project installed into the environment (an editable + `pip install -e .` included), prefix it with PYTHONPATH=. so the + tests import the copy being verified rather than the installed + one. Use PYTHONPATH=src for a src layout. + +Verify the change BEFORE it exists on disk. The shadow tree is a copy of the +working tree, so if you write the change first and then pass a `git diff` of +it, the diff no longer applies and you get "diff did not apply (stale base?)" +back instead of a verdict. + +Verification runs the whole test suite in a shadow copy, so it can take minutes +on a real project. That is the work, not a hang. + +STEP 7 - Report, then stop. + +Tell me: + - which file you wrote, or which command you ran + - the exact `verdict` and the exact `reason` from the response + - the value of `coverage.tool`: "coverage.py" means coverage was measured, + "none" means it was not + +Apply nothing. The step 6 edit was a probe. Confirm with `git status` that the +working tree is exactly as dirty as you found it, and no more. + +Do not describe a SAFE verdict as "correct", "proven", or "guaranteed". SAFE +means the project's own tests ran the changed code and stayed green. It +inherits exactly what those tests check, and a weak suite yields a weak SAFE. +``` + +
+ +Prefer to do it yourself? The rest of this page is the same setup by hand. + +## The format is TOML, not JSON + +Every other client on this list takes a JSON object keyed by server name. Codex takes a TOML table per server, and the table prefix is `mcp_servers` with an underscore, not `mcpServers`. + +## Config location + +| Scope | Path | Applies to | +| ------- | ------------------------------------------- | ------------------------------- | +| User | `~/.codex/config.toml` | Every project | +| Project | `.codex/config.toml` in the repository root | That project, once you trust it | + +## Add it + +The `codex mcp add` subcommand writes the entry for you and gets the TOML shape right: + +```bash +codex mcp add refactron -- refactron-mcp +``` + +The `--` separator is required. Everything after it is the command Codex launches; everything before it is Codex's own flags. + +To write it by hand, add this table to `~/.codex/config.toml`: + +```toml +[mcp_servers.refactron] +command = "refactron-mcp" +args = [] +tool_timeout_sec = 900 +``` + +To pin the version and skip the global install: + +```toml +[mcp_servers.refactron] +command = "npx" +args = ["-y", "-p", "refactron@0.3.0", "refactron-mcp"] +tool_timeout_sec = 900 +``` + +The `-p` flag is required. `refactron-mcp` is a second binary of the `refactron` package, not a package of its own. + +## Set `tool_timeout_sec` yourself + +Codex applies a per-tool timeout, and its default has changed between releases: the published config reference documents 60 seconds, while current builds use a longer one. Either number can be shorter than a real test suite, and `verify_change` runs your whole suite. + +Set `tool_timeout_sec` explicitly to comfortably more than a full suite run. Without it, a slow project reports a tool failure that is really a client-side timeout, and you lose a verdict you had already paid for. + +`startup_timeout_sec` is a separate key covering only process launch and the MCP handshake. The default is fine for this server, which starts in well under a second. + +## Verify the connection + +```bash +codex mcp list +``` + +`refactron` appears in the list with its launch command. For the single entry, including the resolved config: + +```bash +codex mcp get refactron +``` + +Both accept `--json` if you want to read the entry from a script. + +Then start a session and ask for the tool list. You are looking for one tool, `verify_change`, under `refactron`. + +## Troubleshooting + +- **The table name is wrong**: it is `[mcp_servers.refactron]`. A `[mcpServers.refactron]` table is silently a different, unused key. Codex does not warn you. +- **The server is configured but never starts**: check for `enabled = false` on the table. That key disables a server without removing it, and it is easy to leave behind. +- **`command not found` on launch**: run `which refactron-mcp`. If it prints nothing, run `npm install -g refactron@0.3.0`, or switch to the `npx` form above. +- **A project-scoped `.codex/config.toml` is ignored**: Codex reads project config only for a trusted project. Trust the directory, or move the entry to `~/.codex/config.toml`. +- **A verification fails after about a minute on a suite that takes longer**: that is `tool_timeout_sec`, not a verdict. Raise it. +- **Duplicate TOML tables**: two `[mcp_servers.refactron]` tables in one file is a parse error, and Codex rejects the whole config. If you ran `codex mcp add` after hand-editing, check for both. + +## Remove it + +```bash +codex mcp remove refactron +``` diff --git a/docs/mcp/cursor.mdx b/docs/mcp/cursor.mdx new file mode 100644 index 00000000..8d4fb52e --- /dev/null +++ b/docs/mcp/cursor.mdx @@ -0,0 +1,197 @@ +--- +title: Cursor +icon: /assets/clients/cursor.svg +description: Add the Refactron MCP server to Cursor with a project .cursor/mcp.json or the global ~/.cursor/mcp.json. +--- + +Cursor reads MCP servers from a project file or a global one. The project file is the better default: it travels with the repository, so everyone on the team gets the same gate. + +## Set it up with your agent + +One prompt, written for Cursor to read rather than you. It installs the +server, registers it, reloads, and proves the tool works with a real +verification. + +
+ +```text +Set up the Refactron MCP server for yourself in this repository and prove it +works before you tell me it is done. Do the steps in order. + +You are running in Cursor. + +STEP 1 - Check the prerequisites. + +Run `node --version`. Refactron needs Node.js 18 or newer. If it is older or +missing, stop and tell me. + +Run `python3 --version`, then check that `pytest` and `coverage` are +importable. Coverage attestation is Python-only, and it is what makes a +coverage-backed SAFE verdict possible. Without it the server still runs and +still gates the change, but every verdict caps at UNPROVEN. + +STEP 2 - Install the server. + +Run `which refactron-mcp`, or `where refactron-mcp` on Windows. If it prints a +path, go to step 3. Otherwise install it: + + npm install -g refactron@0.3.0 + +That puts two binaries on PATH: `refactron` (the CLI) and `refactron-mcp` (the +MCP server). If you cannot install globally, install nothing and use the npx +form in step 3 instead. + +Do not use `pip install refactron` for this. The PyPI wrapper provides the +`refactron` command only. It does not ship `refactron-mcp`. + +STEP 3 - Register the server. + +Create `.cursor/mcp.json` in the repository root, root key "mcpServers". The +project file is the better default: it travels with the repository, so the +whole team gets the same gate. The global file is ~/.cursor/mcp.json. + + { "mcpServers": { "refactron": { "command": "refactron-mcp" } } } + +Merge into the existing "mcpServers" object if the file already has servers. + +Without a global install, use this instead. The `-p` flag is required, because +`refactron-mcp` is a second binary of the `refactron` package and not a package +of its own: + + { "mcpServers": { "refactron": { "command": "npx", + "args": ["-y", "-p", "refactron@0.3.0", "refactron-mcp"] } } } + +STEP 4 - Reload. + +Cursor reloads MCP servers on a toggle, not on file save. + +You cannot do this yourself. Tell me to open Cursor Settings, then Tools & +Integrations, called MCP in older builds, and switch the `refactron` toggle off +and back on. Wait for me before you continue. + +STEP 5 - Confirm the tool is exposed. + +Ask me to confirm that `refactron` shows a green indicator in Cursor Settings +under Tools & Integrations, with one tool beneath it. + +Tools are only available in Agent mode. Ask mode does not call tools at all, so +if you cannot see the tool, check the mode before you suspect the config. + +You are looking for a server named `refactron`, version 0.3.0, exposing exactly +ONE tool: `verify_change`. + +If the server is connected but no tool appears, the handshake failed. Prove the +binary itself works by sending it one initialize request: + + echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"probe","version":"1.0"}}}' | refactron-mcp + +A working server replies on one line with serverInfo.name "refactron". If that +works and the client still shows nothing, the fault is the config: check the +root key and check that the file parses. + +STEP 6 - Prove it works with one real verification. + +Do not skip this. A connected server is not a working server. + +Pick one small source file that this project's test suite exercises. Propose a +real but behaviour-preserving edit to it: reorder the operands of a commutative +expression, rename a local variable, that kind of thing. One or two lines. + +Do NOT write that edit to disk. Call verify_change with the proposal instead: + + repoRoot the ABSOLUTE path to this repository + edits [{ "path": "", + "newContent": "" }] + testCmd the project's test command, if it is not obvious. For a Python + project installed into the environment (an editable + `pip install -e .` included), prefix it with PYTHONPATH=. so the + tests import the copy being verified rather than the installed + one. Use PYTHONPATH=src for a src layout. + +Verify the change BEFORE it exists on disk. The shadow tree is a copy of the +working tree, so if you write the change first and then pass a `git diff` of +it, the diff no longer applies and you get "diff did not apply (stale base?)" +back instead of a verdict. + +Verification runs the whole test suite in a shadow copy, so it can take minutes +on a real project. That is the work, not a hang. + +STEP 7 - Report, then stop. + +Tell me: + - which file you wrote, or which command you ran + - the exact `verdict` and the exact `reason` from the response + - the value of `coverage.tool`: "coverage.py" means coverage was measured, + "none" means it was not + +Apply nothing. The step 6 edit was a probe. Confirm with `git status` that the +working tree is exactly as dirty as you found it, and no more. + +Do not describe a SAFE verdict as "correct", "proven", or "guaranteed". SAFE +means the project's own tests ran the changed code and stayed green. It +inherits exactly what those tests check, and a weak suite yields a weak SAFE. +``` + +
+ +Prefer to do it yourself? The rest of this page is the same setup by hand. + +## Config location + +| Scope | Path | Applies to | +| ------- | ------------------------------------------------------- | ---------------------- | +| Project | `.cursor/mcp.json` in the repository root | This project only | +| Global | `~/.cursor/mcp.json` (`%USERPROFILE%\.cursor\mcp.json`) | Every project you open | + +## Add it + +Create the file if it does not exist: + +```bash +mkdir -p .cursor +``` + +```json +{ + "mcpServers": { + "refactron": { + "command": "refactron-mcp" + } + } +} +``` + +To pin the version and skip the global install: + +```json +{ + "mcpServers": { + "refactron": { + "command": "npx", + "args": ["-y", "-p", "refactron@0.3.0", "refactron-mcp"] + } + } +} +``` + +The `-p` flag is required. `refactron-mcp` is a second binary of the `refactron` package, not a package of its own. + +## Verify the connection + +Open **Cursor Settings** then **Tools & Integrations** (called **MCP** in older builds). `refactron` appears in the list with a green indicator and one tool beneath it: `verify_change`. + +Then ask the agent in a Chat pane, with Agent mode selected: + +```text +List the tools you have from the refactron MCP server. +``` + +It should name `verify_change` and nothing else. + +## Troubleshooting + +- **The server shows red or `Client closed`**: Cursor could not launch the command. Run `which refactron-mcp`. If it prints nothing, run `npm install -g refactron@0.3.0`, or switch to the `npx` form above. +- **Nothing appears after saving**: Cursor reloads servers on a toggle, not on file save. Switch the `refactron` toggle off and on in the settings pane. +- **The tool exists but the agent never calls it**: tools are only available in Agent mode. Ask mode does not call tools. See [Make it verify, not just connect](/mcp/index#make-it-verify-not-just-connect) for a rule that makes the agent verify on its own. +- **`repoRoot` errors**: the tool needs an absolute path. Tell the agent to pass the project's absolute path, not `.` and not a path relative to anything. +- **A verification takes minutes**: `verify_change` runs your real test suite in a shadow copy. Long is expected on a large suite. diff --git a/docs/mcp/gemini-cli.mdx b/docs/mcp/gemini-cli.mdx new file mode 100644 index 00000000..0155b479 --- /dev/null +++ b/docs/mcp/gemini-cli.mdx @@ -0,0 +1,225 @@ +--- +title: Gemini CLI +icon: /assets/clients/googlegemini.svg +description: Add the Refactron MCP server to Gemini CLI with the gemini mcp add command or ~/.gemini/settings.json. +--- + +Gemini CLI reads MCP servers from `settings.json` under the root key `mcpServers`, the same shape Claude Desktop and Cursor use. There is a subcommand that writes the entry for you. + +## Set it up with your agent + +One prompt, written for Gemini CLI to read rather than you. It installs the +server, registers it, reloads, and proves the tool works with a real +verification. + +
+ +```text +Set up the Refactron MCP server for yourself in this repository and prove it +works before you tell me it is done. Do the steps in order. + +You are running in Gemini CLI. + +STEP 1 - Check the prerequisites. + +Run `node --version`. Refactron needs Node.js 18 or newer. If it is older or +missing, stop and tell me. + +Run `python3 --version`, then check that `pytest` and `coverage` are +importable. Coverage attestation is Python-only, and it is what makes a +coverage-backed SAFE verdict possible. Without it the server still runs and +still gates the change, but every verdict caps at UNPROVEN. + +STEP 2 - Install the server. + +Run `which refactron-mcp`, or `where refactron-mcp` on Windows. If it prints a +path, go to step 3. Otherwise install it: + + npm install -g refactron@0.3.0 + +That puts two binaries on PATH: `refactron` (the CLI) and `refactron-mcp` (the +MCP server). If you cannot install globally, install nothing and use the npx +form in step 3 instead. + +Do not use `pip install refactron` for this. The PyPI wrapper provides the +`refactron` command only. It does not ship `refactron-mcp`. + +STEP 3 - Register the server. + +Run: + + gemini mcp add refactron refactron-mcp + +That defaults to PROJECT scope and writes `.gemini/settings.json` in whatever +directory you run it from. Add `--scope user` for ~/.gemini/settings.json +instead. + +By hand, the root key is "mcpServers" and `timeout` is in MILLISECONDS: + + { "mcpServers": { "refactron": { "command": "refactron-mcp", + "timeout": 900000 } } } + +900 would mean 0.9 seconds and every call would fail instantly. Gemini CLI +defaults to 600000, the same order as Refactron's own 600 second test gate, so +set it above the slowest full run of this suite. + +Without a global install, use this instead. The `-p` flag is required, because +`refactron-mcp` is a second binary of the `refactron` package and not a package +of its own: + + { "mcpServers": { "refactron": { "command": "npx", + "args": ["-y", "-p", "refactron@0.3.0", "refactron-mcp"], + "timeout": 900000 } } } + +STEP 4 - Reload. + +Gemini CLI picks the server up on the next session. If it does not appear in +step 5, tell me to restart `gemini`. + +STEP 5 - Confirm the tool is exposed. + +Run: + + gemini mcp list + +`refactron` should show as Connected. Inside a session, `/mcp` shows connected +servers with their tools expanded. + +If it shows Disconnected and the command is right, the folder is not trusted. A +stdio server only starts in a trusted folder, so tell me to run `gemini trust` +here. This is the failure that looks like a broken install and is not one. + +If it is configured but never connects, check the top-level `mcp` object for an +`allowed` list that does not name `refactron`. + +You are looking for a server named `refactron`, version 0.3.0, exposing exactly +ONE tool: `verify_change`. + +If the server is connected but no tool appears, the handshake failed. Prove the +binary itself works by sending it one initialize request: + + echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"probe","version":"1.0"}}}' | refactron-mcp + +A working server replies on one line with serverInfo.name "refactron". If that +works and the client still shows nothing, the fault is the config: check the +root key and check that the file parses. + +STEP 6 - Prove it works with one real verification. + +Do not skip this. A connected server is not a working server. + +Pick one small source file that this project's test suite exercises. Propose a +real but behaviour-preserving edit to it: reorder the operands of a commutative +expression, rename a local variable, that kind of thing. One or two lines. + +Do NOT write that edit to disk. Call verify_change with the proposal instead: + + repoRoot the ABSOLUTE path to this repository + edits [{ "path": "", + "newContent": "" }] + testCmd the project's test command, if it is not obvious. For a Python + project installed into the environment (an editable + `pip install -e .` included), prefix it with PYTHONPATH=. so the + tests import the copy being verified rather than the installed + one. Use PYTHONPATH=src for a src layout. + +Verify the change BEFORE it exists on disk. The shadow tree is a copy of the +working tree, so if you write the change first and then pass a `git diff` of +it, the diff no longer applies and you get "diff did not apply (stale base?)" +back instead of a verdict. + +Verification runs the whole test suite in a shadow copy, so it can take minutes +on a real project. That is the work, not a hang. + +STEP 7 - Report, then stop. + +Tell me: + - which file you wrote, or which command you ran + - the exact `verdict` and the exact `reason` from the response + - the value of `coverage.tool`: "coverage.py" means coverage was measured, + "none" means it was not + +Apply nothing. The step 6 edit was a probe. Confirm with `git status` that the +working tree is exactly as dirty as you found it, and no more. + +Do not describe a SAFE verdict as "correct", "proven", or "guaranteed". SAFE +means the project's own tests ran the changed code and stayed green. It +inherits exactly what those tests check, and a weak suite yields a weak SAFE. +``` + +
+ +Prefer to do it yourself? The rest of this page is the same setup by hand. + +## Config location + +| Scope | Path | Applies to | +| ------- | ---------------------------------------------- | ----------------- | +| User | `~/.gemini/settings.json` | Every project | +| Project | `.gemini/settings.json` in the repository root | This project only | + +`gemini mcp add` defaults to **project** scope, so it writes `.gemini/settings.json` unless you ask otherwise. + +## Add it + +```bash +gemini mcp add refactron refactron-mcp +``` + +That writes the project file. For every project on the machine, use user scope: + +```bash +gemini mcp add --scope user refactron refactron-mcp +``` + +By hand, add this to `settings.json` alongside the objects already there: + +```json +{ + "mcpServers": { + "refactron": { + "command": "refactron-mcp", + "timeout": 900000 + } + } +} +``` + +`timeout` is in **milliseconds** here, not seconds. Gemini CLI defaults to 600000 (10 minutes), which is the same order as Refactron's own 600 second test-gate default, so a suite that runs long enough to hit one will be near the other. Set it above your slowest full suite run. + +To pin the version and skip the global install: + +```json +{ + "mcpServers": { + "refactron": { + "command": "npx", + "args": ["-y", "-p", "refactron@0.3.0", "refactron-mcp"], + "timeout": 900000 + } + } +} +``` + +The `-p` flag is required. `refactron-mcp` is a second binary of the `refactron` package, not a package of its own. + +## Verify the connection + +```bash +gemini mcp list +``` + +```text +✓ refactron: command: refactron-mcp (stdio) - Connected +``` + +Inside a session, the `/mcp` slash command shows connected servers with their tools expanded. You are looking for one tool, `verify_change`, under `refactron`. + +## Troubleshooting + +- **The server shows `Disconnected` and the command is right**: Gemini CLI only starts a stdio server in a trusted folder. Run `gemini trust` in the project directory, then list again. This is the failure that looks like a broken install and is not one. +- **`gemini mcp add` put it somewhere unexpected**: the default scope is project, so the entry landed in `.gemini/settings.json` in whatever directory you ran it from. Re-run with `--scope user` for a machine-wide entry. +- **`command not found` on launch**: run `which refactron-mcp`. If it prints nothing, run `npm install -g refactron@0.3.0`, or switch to the `npx` form above. +- **A verification is cut off partway**: `timeout` is milliseconds. `900` means 0.9 seconds, not 15 minutes, and every call fails instantly. +- **Confirmation prompts on every call**: set `"trust": true` on the `refactron` entry to skip them. The server reads your repository and writes only to a temporary shadow copy, so this is a reasonable server to trust. It is a per-server setting, so it does not loosen anything else. +- **The server is configured but excluded**: check the top-level `mcp` object for an `allowed` list. If `mcp.allowed` is set and does not name `refactron`, the CLI never connects to it. diff --git a/docs/mcp/index.mdx b/docs/mcp/index.mdx new file mode 100644 index 00000000..f69ceae2 --- /dev/null +++ b/docs/mcp/index.mdx @@ -0,0 +1,251 @@ +--- +title: MCP server +icon: /assets/clients/mcp.svg +description: 'Refactron over the Model Context Protocol: one tool, verify_change, that returns SAFE, UNSAFE, or UNPROVEN on a proposed change before an agent lands it.' +--- + +Refactron ships an [MCP](https://modelcontextprotocol.io) server that exposes exactly one tool: **`verify_change`**. An agent hands it a repository root and a proposed change, and gets back a verdict backed by your real test suite, run in an isolated shadow tree. + +The server speaks **stdio**, identifies itself as `refactron` version `0.3.0`, and runs entirely on your machine. It never writes to your repository: applying the change stays the agent's job, after a verdict the agent trusts. + +The fastest way in is to let your agent do the setup. Every client page below opens with a copy-only prompt that installs the server, registers it, reloads the client, and gets a first real verdict, written for that client specifically. + +Prefer to do it by hand? Pick your client below, or follow the [MCP quickstart](/mcp/quickstart). + + + An AI agent calling Refactron's verify_change MCP tool and receiving a SAFE, UNSAFE, or UNPROVEN verdict before landing the change + + +## Why an agent calls it + +A coding agent has no independent way to tell a change that works from a change that only looks right. `verify_change` gives it one: run the project's own tests against the proposal, in a copy, and report what that run actually proved. + +- **`SAFE`**: every gate passed and your tests exercised the changed code. Suite-approved, not proven correct: the verdict inherits exactly what your tests check. +- **`UNSAFE`**: a gate failed. The change broke something. +- **`UNPROVEN`**: the gates passed, but the evidence for `SAFE` is missing. A warning, not a rejection. + +The full model, including how coverage fuses with the gates and what `SAFE` does not claim, is in [Verdicts](/verification/verdicts). + +## Install + +Requires Node.js 18 or newer. For a coverage-backed `SAFE` verdict you also need Python 3.8+ with `pytest` and `coverage.py`. + +Install globally and get both binaries on your `PATH`: + +```bash +npm install -g refactron@0.3.0 +``` + +That gives you `refactron` (the CLI) and `refactron-mcp` (this server). + +To skip the install and let the client fetch the package on demand: + +```bash +npx -y -p refactron@0.3.0 refactron-mcp +``` + +The `-p` flag is required. `refactron-mcp` is a second binary of the `refactron` package, not a package of its own, so `npx refactron-mcp` on a machine without the global install looks for a package named `refactron-mcp` and fails with a registry 404. + + + `pip install refactron==0.3.0` installs a wrapper that still requires Node.js 18+, and it provides + the `refactron` command only. + + +The PyPI wrapper does not ship `refactron-mcp`. If you found Refactron through PyPI and want the MCP server, install the npm package as well. + +## Connect your client + + + + One `claude mcp add` command, or a project `.mcp.json`. + + + Edit `claude_desktop_config.json` and restart the app. + + + `~/.codex/config.toml`, in TOML, under `[mcp_servers.refactron]`. + + + Project `.cursor/mcp.json` or the global `~/.cursor/mcp.json`. + + + `.vscode/mcp.json`, whose root key is `servers`, not `mcpServers`. + + + One `gemini mcp add` command, or `~/.gemini/settings.json`. + + + Cascade reads `~/.codeium/windsurf/mcp_config.json`. + + + Anything that can launch a stdio MCP server can run this one, Zed and Cline included. + + + +## Make it verify, not just connect + +Registering the server only adds a tool the agent may never reach for. These two prompts are what turn it into a habit. Both are written for the agent, not for you. + +### Verify before you apply + +Defines the loop: propose, verify, then act on the verdict. Lasts the current conversation. + +
+ +```text +From now on, in this repository, verify every code change with the Refactron +verify_change MCP tool BEFORE you write it to disk. + +The loop: + +1. Work out the change you want to make. Do not apply it yet. + +2. Call verify_change with: + repoRoot the ABSOLUTE path to this repository + edits [{ path, newContent }] with the full proposed contents of each + file you want to change, OR unifiedDiff, a unified diff of the + change against the CURRENT working tree + testCmd the project's test command, if it is not obvious. For a Python + project installed into the environment (an editable + `pip install -e .` included), prefix it with PYTHONPATH=. so the + tests import the copy being verified. Use PYTHONPATH=src for a + src layout. + +3. Read the `verdict` field and act on it. + + SAFE Apply the change. Report the verdict and quote the `reason`. Also + say what SAFE does not cover: every changed FILE had at least one + changed statement executed, not every changed statement. If + coverage.changedStatements shows a low covered/total ratio, say so + rather than presenting SAFE as full coverage. + + UNSAFE Do NOT apply anything. A gate failed, which means your change broke + something. Read `reason` and the failing entry in `gates`, fix YOUR + change, and call verify_change again. Repeat until it is not UNSAFE. + Never work around this by weakening or deleting a test. If you touch + a test file, the report lists it in testFilesChanged and I will check. + + UNPROVEN Do NOT apply yet. Read `reason` to find out which kind this is: + + "the changed code is not exercised by any test" means the suite ran + and nothing executed your lines. Write the tests named in the + `missingTests` array, add them to the same verify_change call, and + re-verify. Aim to turn this into SAFE. If a missingTests hint says a + line is excluded from coverage (`# pragma: no cover`, `if + TYPE_CHECKING:`), do NOT try to write a test for it. No test can + reach it. Flag it for human review. + + "coverage of the changed code could not be determined" means no + measurement happened at all. Coverage is Python-only today, so a + TypeScript, JavaScript, or mixed-language change always lands here + and no test you write moves it. The gates still passed. Report this + plainly and let me decide. Do not present it as SAFE. + + "no test runner detected" or "baseline tests already fail" means + nothing could be proven either way. Stop and tell me. + +4. Never describe a SAFE verdict as "verified correct", "proven correct", or + "guaranteed safe". It means the project's own tests ran the changed code and + stayed green. It inherits exactly what those tests check. + +5. If the tool returns an error instead of a verdict, read the message. "no + edits provided" means you passed neither `edits` nor `unifiedDiff`. "diff did + not apply (stale base?)" means you already wrote the change to disk, so the + diff no longer applies to the tree being copied: pass `edits` instead, or + revert first. A message about deletions, renames, copies, or binary files + means the change uses an operation the tool refuses to verify, so tell me and + verify that part by hand. +``` + +
+ +### Make it stick across sessions + +Writes that rule into the project, so every session and every teammate inherits it. + +
+ +```text +Add a Refactron verification rule to this project's agent rules file, so the +behavior persists across sessions. + +Pick the right file for this repo, and create it if it is missing: + - AGENTS.md at the repo root, the cross-tool convention + - CLAUDE.md at the repo root, for Claude Code + - .cursor/rules/refactron.mdc, or .cursorrules on older Cursor, for Cursor + - .windsurfrules for Windsurf + - .github/copilot-instructions.md for GitHub Copilot + - GEMINI.md at the repo root, for Gemini CLI + +Append this section verbatim. Do not remove anything already in the file. + +## Verification (required) + +Verify every code change with the Refactron `verify_change` MCP tool before +writing it to disk. Pass `repoRoot` as an absolute path and the change as +`edits` or `unifiedDiff`. Verify before the change exists on disk: the shadow +tree copies the working tree, so a diff of an already-written change will not +apply. + +- `SAFE`: apply it, and report the verdict. `SAFE` means the project's tests ran + the changed code and stayed green. It is suite-approved, not proven correct, + and it is a per-file check: every changed file had at least one changed + statement executed, not every changed statement. +- `UNSAFE`: do not apply. Fix the change and re-verify. Never weaken a test to + turn a verdict green. +- `UNPROVEN`: do not apply yet. If the reason names uncovered code, write the + tests listed in `missingTests` and re-verify. If the reason is that coverage + could not be determined, say so and ask a human. Coverage is Python-only, so a + non-Python change cannot reach `SAFE` today. +``` + +
+ +### Why the wording in these prompts matters + +Every prompt tells the agent, more than once, not to report `SAFE` as "correct". That is deliberate. + +`SAFE` means the gates passed and your suite exercised the changed code. It does not mean the change is right. A real example from Refactron's own hardening runs: changing `<=` to `<` in Jinja2's `truncate` filter genuinely changes behavior at the boundary, all 911 tests still pass, the changed line is covered, and the verdict is `SAFE`. The verdict is correct about what it claims and is still not a proof of correctness. + +An agent that reports `SAFE` as "verified correct" has laundered a test-suite result into a guarantee. That is the one failure mode this tool exists to prevent, so the prompts spend words on it. + +## Then use it + + + + Install, register, confirm the tool is listed, and get a first real verdict. + + + The standing rule that makes your agent verify instead of guess. + + + Every `verify_change` argument, the response shape, and the error shape. + + + What each verdict is allowed to claim, and what it is not. + + + +## What the server does and does not do + +- **It runs entirely local.** Verification happens on your machine, in a shadow tree. Nothing about your code leaves it, and the handler makes no network calls. +- **It never mutates your repository.** `verify_change` reads your tree and applies the change in an isolated copy. Landing the change is the agent's job, after a verdict it trusts. +- **It is deterministic.** The same repository state and the same change produce the same verdict every time. +- **It needs no login.** The `verify-diff` CLI is auth-gated, but the MCP handler calls the local engine directly. + +## Limits worth knowing before you start + +Coverage attestation runs through `coverage.py`, so it is Python-only today. A TypeScript, JavaScript, or mixed-language change passes through the same three gates but caps at `UNPROVEN` with `coverage.tool` set to `none`, because Refactron cannot measure whether the changed statements ran. It will not guess, and a guess here would be a false `SAFE`. + +Coverage also cannot see code that only runs in a subprocess. A change exercised solely through `subprocess.run` or a `multiprocessing` worker reads as `UNPROVEN` unless you wire up subprocess coverage yourself. + +Diffs that delete, rename, or copy a file, or that change a binary file, are refused rather than partially verified. See [Unsupported operations](/verification/verify-diff#unsupported-operations). + +There is no hosted CI gate. Refactron runs where you run it: your machine, or your own CI job. diff --git a/docs/mcp/other-clients.mdx b/docs/mcp/other-clients.mdx new file mode 100644 index 00000000..05c013cd --- /dev/null +++ b/docs/mcp/other-clients.mdx @@ -0,0 +1,301 @@ +--- +title: Any other client +icon: /assets/clients/mcp.svg +description: Connect Refactron to any MCP client that can launch a stdio server, plus the root keys and config shapes each client family expects. +--- + +Refactron is an ordinary stdio MCP server. Any client that can launch a subprocess and speak JSON-RPC over its standard streams can run it. + +## Set it up with your agent + +One prompt, written for an MCP client that this documentation does not cover by name to read rather than you. It installs the +server, registers it, reloads, and proves the tool works with a real +verification. + +
+ +```text +Set up the Refactron MCP server for yourself in this repository and prove it +works before you tell me it is done. Do the steps in order. + +You are running in an MCP client that this documentation does not cover by name. + +STEP 1 - Check the prerequisites. + +Run `node --version`. Refactron needs Node.js 18 or newer. If it is older or +missing, stop and tell me. + +Run `python3 --version`, then check that `pytest` and `coverage` are +importable. Coverage attestation is Python-only, and it is what makes a +coverage-backed SAFE verdict possible. Without it the server still runs and +still gates the change, but every verdict caps at UNPROVEN. + +STEP 2 - Install the server. + +Run `which refactron-mcp`, or `where refactron-mcp` on Windows. If it prints a +path, go to step 3. Otherwise install it: + + npm install -g refactron@0.3.0 + +That puts two binaries on PATH: `refactron` (the CLI) and `refactron-mcp` (the +MCP server). If you cannot install globally, install nothing and use the npx +form in step 3 instead. + +Do not use `pip install refactron` for this. The PyPI wrapper provides the +`refactron` command only. It does not ship `refactron-mcp`. + +STEP 3 - Register the server. + +First work out which client you are running in, from your own runtime, not +from anything in this repository. If you genuinely cannot tell, ask me before +you write any file. + +Refactron is an ordinary stdio MCP server: command `refactron-mcp`, no +arguments, no environment, no API key. Only the root key differs by client: + + Claude Code, Claude Desktop, Cursor, Windsurf, Gemini CLI, Cline + JSON, root key "mcpServers" + VS Code with Copilot JSON, root key "servers", plus "type": "stdio" + Zed JSON, top-level key "context_servers" + Codex CLI TOML, table [mcp_servers.refactron] + +The server object, for every client that takes JSON: + + { "refactron": { "command": "refactron-mcp" } } + +Without a global install, use this instead. The `-p` flag is required, because +`refactron-mcp` is a second binary of the `refactron` package and not a package +of its own: + + { "refactron": { "command": "npx", + "args": ["-y", "-p", "refactron@0.3.0", "refactron-mcp"] } } + +Merge into any existing config rather than overwriting it. + +Set a tool timeout if your client has one, and check the unit: Cline and Codex +CLI count seconds, Gemini CLI counts milliseconds. A verification runs the whole +test suite, so any default under a minute cuts it off and reports a failure +that is really a timeout. + +STEP 4 - Reload. + +Reload however your client requires: a new session, a full application restart, +a settings toggle, or a refresh button. + +If you cannot trigger it yourself, say so plainly and tell me exactly what to +click. Do not claim the setup is done before the server is connected. + +STEP 5 - Confirm the tool is exposed. + +Use your client's own command or panel where one exists: `claude mcp list`, +`codex mcp list`, `gemini mcp list`, or the MCP panel in an editor. + +You are looking for a server named `refactron`, version 0.3.0, exposing exactly +ONE tool: `verify_change`. + +If the server is connected but no tool appears, the handshake failed. Prove the +binary itself works by sending it one initialize request: + + echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"probe","version":"1.0"}}}' | refactron-mcp + +A working server replies on one line with serverInfo.name "refactron". If that +works and the client still shows nothing, the fault is the config: check the +root key and check that the file parses. + +STEP 6 - Prove it works with one real verification. + +Do not skip this. A connected server is not a working server. + +Pick one small source file that this project's test suite exercises. Propose a +real but behaviour-preserving edit to it: reorder the operands of a commutative +expression, rename a local variable, that kind of thing. One or two lines. + +Do NOT write that edit to disk. Call verify_change with the proposal instead: + + repoRoot the ABSOLUTE path to this repository + edits [{ "path": "", + "newContent": "" }] + testCmd the project's test command, if it is not obvious. For a Python + project installed into the environment (an editable + `pip install -e .` included), prefix it with PYTHONPATH=. so the + tests import the copy being verified rather than the installed + one. Use PYTHONPATH=src for a src layout. + +Verify the change BEFORE it exists on disk. The shadow tree is a copy of the +working tree, so if you write the change first and then pass a `git diff` of +it, the diff no longer applies and you get "diff did not apply (stale base?)" +back instead of a verdict. + +Verification runs the whole test suite in a shadow copy, so it can take minutes +on a real project. That is the work, not a hang. + +STEP 7 - Report, then stop. + +Tell me: + - which file you wrote, or which command you ran + - the exact `verdict` and the exact `reason` from the response + - the value of `coverage.tool`: "coverage.py" means coverage was measured, + "none" means it was not + +Apply nothing. The step 6 edit was a probe. Confirm with `git status` that the +working tree is exactly as dirty as you found it, and no more. + +Do not describe a SAFE verdict as "correct", "proven", or "guaranteed". SAFE +means the project's own tests ran the changed code and stayed green. It +inherits exactly what those tests check, and a weak suite yields a weak SAFE. +``` + +
+ +Prefer to do it yourself? The rest of this page is the same setup by hand. + +## What every client needs to know + +| Setting | Value | +| ----------- | -------------------- | +| Transport | stdio | +| Command | `refactron-mcp` | +| Arguments | none | +| Environment | none required | +| Server name | `refactron` | +| Version | `0.3.0` | +| Tools | one, `verify_change` | + +There is no HTTP or SSE endpoint, no API key, and no network call. The server reads your repository, runs your tests in a temporary shadow copy, and writes the verdict back over stdout. + +## The root key differs by client + +This is where most setups fail. The block is otherwise identical. + +| Client family | Format | Root key | +| ---------------------------------------------------------------- | ------ | ----------------- | +| Claude Code, Claude Desktop, Cursor, Windsurf, Gemini CLI, Cline | JSON | `mcpServers` | +| VS Code with GitHub Copilot | JSON | `servers` | +| Zed | JSON | `context_servers` | +| Codex CLI | TOML | `[mcp_servers.*]` | + +The `mcpServers` form, which most clients accept: + +```json +{ + "mcpServers": { + "refactron": { + "command": "refactron-mcp" + } + } +} +``` + +## Without a global install + +```json +{ + "mcpServers": { + "refactron": { + "command": "npx", + "args": ["-y", "-p", "refactron@0.3.0", "refactron-mcp"] + } + } +} +``` + +The `-p` flag is required. `refactron-mcp` is a second binary of the `refactron` package, not a package of its own, so `npx refactron-mcp` looks up a package by that name and fails with a registry 404 unless a global install already put the binary on your `PATH`. + +## Clients without a page of their own + +### Zed + +Zed calls MCP servers "context servers" and configures them in its main `settings.json`, at the top-level key `context_servers`. A block copied from Claude Desktop or Cursor does nothing here, with no error. + +| OS | Path | +| ------------ | ----------------------------- | +| macOS, Linux | `~/.config/zed/settings.json` | +| Windows | `%APPDATA%\Zed\settings.json` | + +```json +{ + "context_servers": { + "refactron": { + "command": "refactron-mcp", + "args": [], + "env": {} + } + } +} +``` + +Zed restarts the context server process when you save `settings.json`, so no editor restart is needed. Some builds also expect `"source": "custom"` on a hand-written entry. If the server does not appear after saving, add it through **Agent Panel** then **Settings** then **Add Custom Server**, which writes the shape your build expects. + +### Cline + +Cline manages servers from its own panel inside VS Code, backed by `cline_mcp_settings.json` in the extension's storage directory. Open it with the **MCP Servers** icon at the top of the Cline pane, then **Configure MCP Servers**. + +| OS | Path | +| ------- | --------------------------------------------------------------------------------------------------------------- | +| macOS | `~/Library/Application Support/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json` | +| Windows | `%APPDATA%\Code\User\globalStorage\saoudrizwan.claude-dev\settings\cline_mcp_settings.json` | +| Linux | `~/.config/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json` | + +```json +{ + "mcpServers": { + "refactron": { + "command": "refactron-mcp", + "disabled": false, + "timeout": 900 + } + } +} +``` + +`timeout` is in seconds here and it matters. Cline defaults to 60, and `verify_change` runs your whole test suite, so a real project blows past that and Cline reports a failure that is really a timeout. Cline stores this file separately from VS Code's own `.vscode/mcp.json`: configuring one does not configure the other. + +## From a source checkout + +Contributors running an unpublished build point the client at the compiled server with an absolute path: + +```bash +git clone https://github.com/Refactron-ai/Refactron_Lib_TS +cd Refactron_Lib_TS +npm install +npm run build +``` + +```json +{ + "mcpServers": { + "refactron": { + "command": "node", + "args": ["/absolute/path/to/Refactron_Lib_TS/dist/mcp/server.js"] + } + } +} +``` + +## Confirm it works before blaming the client + +Send one `initialize` request straight to the binary: + +```bash +echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"probe","version":"1.0"}}}' | refactron-mcp +``` + +```json +{ + "result": { + "protocolVersion": "2024-11-05", + "capabilities": { "tools": { "listChanged": true } }, + "serverInfo": { "name": "refactron", "version": "0.3.0" } + }, + "jsonrpc": "2.0", + "id": 1 +} +``` + +If that works and your client still shows nothing, the problem is the client config: check the root key, the JSON or TOML validity, and whether the client inherits the `PATH` that holds `refactron-mcp`. + +## Client requirements that trip people up + +- **A test-suite run is the unit of work.** Clients with a default tool timeout under a minute will cut off a real verification. Raise the timeout where the client allows it, and check the unit: Cline and Codex CLI count seconds, Gemini CLI counts milliseconds. +- **Absolute paths only.** `repoRoot` must be an absolute path. Clients that pass a relative working directory will not help you here. +- **Tools need an agent mode.** Chat-only or ask-only modes in most editors do not call tools at all. diff --git a/docs/mcp/quickstart.mdx b/docs/mcp/quickstart.mdx new file mode 100644 index 00000000..451346de --- /dev/null +++ b/docs/mcp/quickstart.mdx @@ -0,0 +1,169 @@ +--- +title: MCP quickstart +icon: rocket +description: Install the Refactron MCP server, register it with one client, confirm the tool is listed, and get a first real verdict on a real change. +--- + +Ten minutes, end to end: install the server, register it with one client, confirm the client sees `verify_change`, then verify a change and read the verdict. + +## 1. Install + +Requires Node.js 18 or newer. + +```bash +npm install -g refactron@0.3.0 +``` + +Confirm both binaries landed: + +```bash +refactron --version +refactron-mcp --help 2>/dev/null || echo "refactron-mcp is on PATH" +``` + +`refactron-mcp` has no help output. It is an MCP server, not a CLI: it reads JSON-RPC on stdin and writes it on stdout, and it exits when stdin closes. + +For a coverage-backed `SAFE` verdict, you also need Python 3.8+ with `pytest` and `coverage.py` in the environment that runs your tests: + +```bash +pip install pytest coverage +``` + +## 2. Smoke test the server without a client + +Send one `initialize` request and read the identity back. This proves the binary runs before you blame a client config. + +```bash +echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"probe","version":"1.0"}}}' | refactron-mcp +``` + +```json +{ + "result": { + "protocolVersion": "2024-11-05", + "capabilities": { "tools": { "listChanged": true } }, + "serverInfo": { "name": "refactron", "version": "0.3.0" } + }, + "jsonrpc": "2.0", + "id": 1 +} +``` + +`serverInfo.name` is `refactron` and `serverInfo.version` matches the package you installed. If this prints nothing, the problem is the install, not the client. + +## 3. Register it with one client + +Pick the client you actually use. Claude Code is the shortest path: + +```bash +claude mcp add refactron -- refactron-mcp +``` + +Every other client is a small JSON file. The canonical block, which Claude Desktop, Cursor, Windsurf, and Cline all accept: + +```json +{ + "mcpServers": { + "refactron": { + "command": "refactron-mcp" + } + } +} +``` + +VS Code uses `servers` instead of `mcpServers`, and Codex CLI uses TOML rather than JSON. Per-client file paths and verification steps live on the client pages: [Claude Code](/mcp/claude-code), [Claude Desktop](/mcp/claude-desktop), [Codex CLI](/mcp/codex), [Cursor](/mcp/cursor), [GitHub Copilot in VS Code](/mcp/vscode), [Gemini CLI](/mcp/gemini-cli), [Windsurf](/mcp/windsurf), [anything else](/mcp/other-clients). + +Prefer not to do this by hand? Each [client page](/mcp/index#connect-your-client) opens with a copy-only prompt that has your agent install, register, reload, and verify for you. + +## 4. Confirm the tool is listed + +Whatever the client, you are looking for one tool named `verify_change` under a server named `refactron`. In Claude Code: + +```bash +claude mcp list +``` + +```text +refactron: refactron-mcp - ✔ Connected +``` + +Inside a session, `/mcp` shows the same thing with the tool list expanded. If the server is listed but the tool is not, the client connected and the handshake failed; re-run the smoke test in step 2. + +## 5. Get a first real verdict + +Make a change in a Python project with a passing test suite, then ask your agent to verify it instead of applying it: + +```text +Use the refactron verify_change tool on this repository before you apply anything. +Pass repoRoot as the absolute path to this project and testCmd as "python3 -m pytest -q". +Show me the verdict and the reason, and do not write any files yet. +``` + +A real response on a covered change: + +```json +{ + "verdict": "SAFE", + "reportVersion": 1, + "gates": { + "syntax": { "passed": true, "durationMs": 96 }, + "imports": { "passed": true, "durationMs": 47 }, + "tests": { "passed": true, "durationMs": 1370 } + }, + "changedFiles": ["calc.py"], + "testFilesChanged": [], + "coverage": { + "tool": "coverage.py", + "changedLinesCovered": true, + "uncovered": [], + "filesWithUncovered": 0, + "changedStatements": { "total": 1, "covered": 1 }, + "inertOnlyFiles": [] + }, + "reason": "Tests pass and the changed code is covered." +} +``` + +## What success looks like + +- `claude mcp list` (or the equivalent panel in your client) shows `refactron` connected. +- The tool list contains exactly one entry: `verify_change`. +- A call returns JSON with a `verdict` field and a `reportVersion` of `1`. +- Your working tree is unchanged. Check with `git status`: verification happens in a shadow copy. + +## If the verdict is not what you expected + +An `UNPROVEN` on an all-Python change usually means one of three things, and the `reason` field tells you which. + +| Reason text | What happened | +| ---------------------------------------------------------- | --------------------------------------------------------------------- | +| "the changed code is not exercised by any test" | The suite ran and passed, but nothing executed the lines you changed. | +| "coverage of the changed code could not be determined" | Coverage could not be measured at all. Different problem, see below. | +| "no test runner detected" or "baseline tests already fail" | Refactron cannot blame the change for anything, so it proves nothing. | + +Those first two are different sentences on purpose. "Not exercised by any test" means the measurement happened and found nothing running your lines: write the test named in `missingTests` and re-verify. "Could not be determined" means no measurement happened at all: the diff is not all Python, or `coverage.py` is missing, or the tests never loaded the copy under verification. + +That last case is the one that catches people. If your project is installed into the environment, an editable `pip install -e .` included, `import yourpackage` resolves to the installed copy and your tests exercise the original code rather than the change. Put the verified tree first on `sys.path` by passing it in the test command: + +```text +testCmd: "PYTHONPATH=. python3 -m pytest -q" +``` + +Use `PYTHONPATH=src` for a src layout. Relative paths resolve from the copy being verified, which is exactly what you want. Full detail in [Make sure the tests run the code being verified](/verification/verdicts#make-sure-the-tests-run-the-code-being-verified). + +A mixed-language or non-Python diff caps at `UNPROVEN` no matter what you do. Coverage is Python-only today, and no test you add moves that verdict. + +## Next + + + + Blocks you can paste so your agent verifies before it applies, every time. + + + Arguments, request and response examples, and the error shape. + + diff --git a/docs/mcp/tool-reference.mdx b/docs/mcp/tool-reference.mdx new file mode 100644 index 00000000..569a18c5 --- /dev/null +++ b/docs/mcp/tool-reference.mdx @@ -0,0 +1,178 @@ +--- +title: verify_change reference +icon: book +description: 'The verify_change MCP tool contract: arguments, request and response examples, the error shape, and how it maps to verify-diff exit codes.' +--- + +The Refactron MCP server exposes exactly one tool. Every example below was captured from a real stdio session against `refactron` 0.3.0. + +## Arguments + +| Argument | Type | Required | Description | +| ------------- | ------------------------ | -------- | --------------------------------------------------------------------------- | +| `repoRoot` | string | yes | Absolute path to the repository root. | +| `edits` | `[{ path, newContent }]` | see note | Proposed full-file contents. `path` is repo-relative. | +| `unifiedDiff` | string | see note | A unified (git) diff to apply and verify. | +| `testCmd` | string | no | Override the test command. Drives both the tests gate and the coverage run. | + +`repoRoot` is the only argument the schema marks required, but the handler needs a change to verify: supply **either** `edits` **or** `unifiedDiff`. Supplying neither returns an error result, not a verdict. + +## Request: the `edits` form + +Use this when the agent already holds the full new contents of each file. + +```json +{ + "method": "tools/call", + "params": { + "name": "verify_change", + "arguments": { + "repoRoot": "/Users/you/projects/demo", + "edits": [ + { + "path": "calc.py", + "newContent": "def add(a, b):\n return b + a\n\n\ndef scale(a, factor):\n return a * factor\n" + } + ], + "testCmd": "python3 -m pytest -q" + } + } +} +``` + +## Request: the `unifiedDiff` form + +Use this when the change already exists as a patch, for example from `git diff` or a codemod. + +```json +{ + "method": "tools/call", + "params": { + "name": "verify_change", + "arguments": { + "repoRoot": "/Users/you/projects/demo", + "unifiedDiff": "diff --git a/calc.py b/calc.py\n--- a/calc.py\n+++ b/calc.py\n@@ -3,4 +3,4 @@ def add(a, b):\n \n \n def scale(a, factor):\n- return a * factor\n+ return factor * a\n", + "testCmd": "python3 -m pytest -q" + } + } +} +``` + +## Response + +The tool returns the same report `verify-diff --json` prints, serialized as text content. A real `UNPROVEN` response: + +```json +{ + "verdict": "UNPROVEN", + "reportVersion": 1, + "gates": { + "syntax": { "passed": true, "durationMs": 108 }, + "imports": { "passed": true, "durationMs": 45 }, + "tests": { "passed": true, "durationMs": 1423 } + }, + "changedFiles": ["calc.py"], + "testFilesChanged": [], + "coverage": { + "tool": "coverage.py", + "changedLinesCovered": false, + "uncovered": [{ "file": "calc.py", "line": 6 }], + "filesWithUncovered": 1, + "changedStatements": { "total": 1, "covered": 0 }, + "inertOnlyFiles": [] + }, + "reason": "Tests pass, but the changed code is not exercised by any test.", + "missingTests": [{ "file": "calc.py", "hint": "add a test exercising calc.py:6" }] +} +``` + +### Field by field + +| Field | Meaning | +| ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------- | +| `verdict` | `SAFE`, `UNSAFE`, or `UNPROVEN`. See [Verdicts](/verification/verdicts). | +| `reportVersion` | Schema version, currently `1`. Read it before relying on any field below. | +| `gates` | `syntax`, `imports`, `tests`, each with `passed` and `durationMs`. A failed gate also carries `blockingReason`. | +| `changedFiles` | Repo-relative paths the change touches. | +| `testFilesChanged` | Subset of `changedFiles` matching test conventions. A note, never a verdict input. | +| `coverage.tool` | `coverage.py` when coverage was measured, `none` when it could not be. | +| `coverage.changedLinesCovered` | `true`, `false`, or `"unknown"`. The three states are distinct and must not be collapsed. | +| `coverage.uncovered` | One entry per unexercised statement, at the statement's first line. Populated on `SAFE` too. | +| `coverage.changedStatements` | `{ total, covered }` across the diff, so you can read the ratio rather than only the boolean. Advisory: it does not feed the verdict. | +| `coverage.filesWithUncovered` | Distinct files with at least one uncovered statement, counted before any cap. | +| `coverage.unknownReason` | Why coverage is `"unknown"`, when Refactron knows. | +| `reason` | One sentence explaining the verdict. Machine-stable enough to branch on by substring. | +| `missingTests` | Concrete hints for `UNPROVEN` by coverage. Capped at 50. | +| `flakyTests` | Tests that failed once then passed on retry. Present only when it happened. Disqualifies `SAFE`. | + +`coverage.removalOnlyFiles` and `coverage.inertOnlyFiles` list changed files with nothing for coverage to attest, because the change only removed lines or only touched comments and blank lines. + +`coverage.uncoveredTruncated` and `missingTestsTruncated` appear as `{ shown, total }` whenever a list was capped, so a truncated report never reads as a complete one. An agent must check for them before concluding a file is absent from the list because it is fine. + +### The two `UNPROVEN` reasons are not interchangeable + +`"Tests pass, but the changed code is not exercised by any test."` means the measurement ran and found nothing executing your lines. Writing the test named in `missingTests` moves the verdict. + +`"Tests pass, but coverage of the changed code could not be determined."` means no measurement happened. The diff was not all Python, `coverage.py` was unavailable, or the tests never loaded the copy under verification. No test you write moves this one. + +Treating those as the same sentence is how a reader talks themselves into trusting a verdict that proved nothing. They are reported separately on purpose. + +## Errors + +Failures come back as a normal tool result with `isError` set, so the server keeps running and the agent can read the message. + +```json +{ + "content": [ + { + "type": "text", + "text": "verify_change failed: verifyDiff: no edits provided (pass `edits` or `unifiedDiff`)" + } + ], + "isError": true +} +``` + +Real messages you will see: + +| Message | Cause | +| ----------------------------------------------------------------------------------------- | ---------------------------------------------- | +| `verifyDiff: no edits provided (pass \`edits\` or \`unifiedDiff\`)` | Neither change argument was supplied. | +| `ENOENT: no such file or directory, scandir '/nope/does/not/exist'` | `repoRoot` does not exist, or is not absolute. | +| `diff deletes calc.py; file deletions are not supported yet, verify that change manually` | The diff deletes a file. | +| `diff renames to ; renames are not supported yet` | The diff renames a file. | +| `diff copies to ; copies are not supported yet` | The diff copies a file. | +| `diff contains only binary changes; nothing verifiable` | Binary-only diff. | +| `diff contains binary changes alongside text edits; binary changes cannot be verified` | Mixed binary and text diff. | +| `diff did not apply to calc.py (stale base?)` | The diff does not apply to the current tree. | + +The stale-base error has one cause that surprises people. The shadow tree is a copy of your **working tree**, not of `HEAD`, so a change you have already written to disk is already in the copy. Passing `git diff` of that change asks Refactron to apply it a second time, and it will not apply. Verify before you write: pass the proposal as `edits`, or revert the file first and pass the diff. + +Deletions, renames, copies, and binary changes are refused rather than partially verified. A diff that removed a module while making one innocuous edit once verified as safe on the half that could be checked, and applying it broke every import in the package. A partial verdict must never read as a verdict on the whole change. + +## How it maps to the CLI + +`verify_change` and `verify-diff` run the same engine and produce the same report. MCP has no exit codes, so the equivalence is with the `verdict` field: + +| `verdict` | `verify-diff` exit code | +| ---------- | ----------------------- | +| `SAFE` | `0` | +| `UNPROVEN` | `0` | +| `UNSAFE` | `1` | + +`UNPROVEN` exiting `0` is deliberate. It is a warning that nothing was proven, not a finding that something is broken, so it never silently blocks a merge. An agent that wants stricter behavior branches on the `verdict` field itself. + +A tool result with `isError: true` corresponds to the CLI's exit `2`, bad input, which is an operational error rather than a verdict. + + + The `verify-diff` CLI is auth-gated and exits `7` when unauthenticated. The MCP handler calls the + local engine directly, so it needs no login and makes no network calls. + + +## Constraints + +Coverage runs through `coverage.py` and is Python-only. A diff touching any non-Python file returns `UNPROVEN` with `coverage.tool` set to `none`, and cannot reach `SAFE` today. The gates still run. + +Coverage cannot see subprocesses. Code exercised only inside `subprocess.run`, a `multiprocessing` worker, or a spawned server does not register as covered unless you wire up subprocess coverage yourself. + +If the project is installed into the environment, an editable `pip install -e .` included, the tests may import the installed copy rather than the tree under verification, and the run proves nothing about the change. Pass `PYTHONPATH=.` (or `PYTHONPATH=src` for a src layout) in `testCmd` so the verified copy wins on `sys.path`. diff --git a/docs/mcp/vscode.mdx b/docs/mcp/vscode.mdx new file mode 100644 index 00000000..56663722 --- /dev/null +++ b/docs/mcp/vscode.mdx @@ -0,0 +1,202 @@ +--- +title: VS Code +icon: /assets/clients/githubcopilot.svg +description: 'Add the Refactron MCP server to VS Code with GitHub Copilot. Note the root key: VS Code uses servers, not mcpServers.' +--- + +VS Code reads MCP servers for GitHub Copilot's agent mode. Its config shape differs from every other client on one point, and it is the mistake people make most often. + +## Set it up with your agent + +One prompt, written for GitHub Copilot in VS Code to read rather than you. It installs the +server, registers it, reloads, and proves the tool works with a real +verification. + +
+ +```text +Set up the Refactron MCP server for yourself in this repository and prove it +works before you tell me it is done. Do the steps in order. + +You are running in GitHub Copilot in VS Code. + +STEP 1 - Check the prerequisites. + +Run `node --version`. Refactron needs Node.js 18 or newer. If it is older or +missing, stop and tell me. + +Run `python3 --version`, then check that `pytest` and `coverage` are +importable. Coverage attestation is Python-only, and it is what makes a +coverage-backed SAFE verdict possible. Without it the server still runs and +still gates the change, but every verdict caps at UNPROVEN. + +STEP 2 - Install the server. + +Run `which refactron-mcp`, or `where refactron-mcp` on Windows. If it prints a +path, go to step 3. Otherwise install it: + + npm install -g refactron@0.3.0 + +That puts two binaries on PATH: `refactron` (the CLI) and `refactron-mcp` (the +MCP server). If you cannot install globally, install nothing and use the npx +form in step 3 instead. + +Do not use `pip install refactron` for this. The PyPI wrapper provides the +`refactron` command only. It does not ship `refactron-mcp`. + +STEP 3 - Register the server. + +Create `.vscode/mcp.json` in the repository root. + +The root key here is "servers", NOT "mcpServers", and each server needs +"type": "stdio". This is the mistake people make most often: a block copied +from Claude Desktop or Cursor loads nothing here, silently, with no error. + + { "servers": { "refactron": { "type": "stdio", + "command": "refactron-mcp" } } } + +Without a global install, use this instead. The `-p` flag is required, because +`refactron-mcp` is a second binary of the `refactron` package and not a package +of its own: + + { "servers": { "refactron": { "type": "stdio", "command": "npx", + "args": ["-y", "-p", "refactron@0.3.0", "refactron-mcp"] } } } + +If step 5 reports `spawn refactron-mcp ENOENT`, the binary is not on the PATH +VS Code inherited. Use the absolute path from `which refactron-mcp` as +"command". + +STEP 4 - Reload. + +Run "MCP: List Servers" from the Command Palette and start `refactron`. + +If you cannot reach the Command Palette yourself, say so plainly and tell me +exactly what to click. Wait for me before you continue. + +STEP 5 - Confirm the tool is exposed. + +"MCP: List Servers" shows `refactron` with a Running status. Selecting it +offers Show Output and the start command. + +In the Copilot Chat pane the mode selector must be on Agent, and then the tools +picker lists `verify_change` under `refactron`. Ask and Edit modes do not call +tools at all. + +GitHub Copilot CLI keeps its own MCP config and expects "mcpServers". +Configuring VS Code does not configure the CLI. + +You are looking for a server named `refactron`, version 0.3.0, exposing exactly +ONE tool: `verify_change`. + +If the server is connected but no tool appears, the handshake failed. Prove the +binary itself works by sending it one initialize request: + + echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"probe","version":"1.0"}}}' | refactron-mcp + +A working server replies on one line with serverInfo.name "refactron". If that +works and the client still shows nothing, the fault is the config: check the +root key and check that the file parses. + +STEP 6 - Prove it works with one real verification. + +Do not skip this. A connected server is not a working server. + +Pick one small source file that this project's test suite exercises. Propose a +real but behaviour-preserving edit to it: reorder the operands of a commutative +expression, rename a local variable, that kind of thing. One or two lines. + +Do NOT write that edit to disk. Call verify_change with the proposal instead: + + repoRoot the ABSOLUTE path to this repository + edits [{ "path": "", + "newContent": "" }] + testCmd the project's test command, if it is not obvious. For a Python + project installed into the environment (an editable + `pip install -e .` included), prefix it with PYTHONPATH=. so the + tests import the copy being verified rather than the installed + one. Use PYTHONPATH=src for a src layout. + +Verify the change BEFORE it exists on disk. The shadow tree is a copy of the +working tree, so if you write the change first and then pass a `git diff` of +it, the diff no longer applies and you get "diff did not apply (stale base?)" +back instead of a verdict. + +Verification runs the whole test suite in a shadow copy, so it can take minutes +on a real project. That is the work, not a hang. + +STEP 7 - Report, then stop. + +Tell me: + - which file you wrote, or which command you ran + - the exact `verdict` and the exact `reason` from the response + - the value of `coverage.tool`: "coverage.py" means coverage was measured, + "none" means it was not + +Apply nothing. The step 6 edit was a probe. Confirm with `git status` that the +working tree is exactly as dirty as you found it, and no more. + +Do not describe a SAFE verdict as "correct", "proven", or "guaranteed". SAFE +means the project's own tests ran the changed code and stayed green. It +inherits exactly what those tests check, and a weak suite yields a weak SAFE. +``` + +
+ +Prefer to do it yourself? The rest of this page is the same setup by hand. + +## The root key is `servers`, not `mcpServers` + +Claude Desktop, Cursor, Windsurf, and Cline all use `mcpServers`. VS Code uses `servers`. A config copied from any of those clients loads nothing here, with no error: VS Code simply sees no servers. + +## Config location + +| Scope | Path | Applies to | +| --------- | ----------------------------------------- | ------------------- | +| Workspace | `.vscode/mcp.json` in the repository root | This workspace only | +| User | `mcp.json` in your VS Code profile folder | Every workspace | + +Open the user file from the Command Palette with **MCP: Open User Configuration**. For the workspace file, create `.vscode/mcp.json` yourself. + +## Add it + +```json +{ + "servers": { + "refactron": { + "type": "stdio", + "command": "refactron-mcp" + } + } +} +``` + +To pin the version and skip the global install: + +```json +{ + "servers": { + "refactron": { + "type": "stdio", + "command": "npx", + "args": ["-y", "-p", "refactron@0.3.0", "refactron-mcp"] + } + } +} +``` + +The `-p` flag is required. `refactron-mcp` is a second binary of the `refactron` package, not a package of its own. + +## Verify the connection + +Run **MCP: List Servers** from the Command Palette. `refactron` appears with a `Running` status; select it for **Show Output** and the start command. + +In the Copilot Chat pane, switch the mode selector to **Agent**, then open the tools picker. `verify_change` is listed under `refactron` with a checkbox. + +## Troubleshooting + +- **No servers listed**: check the root key. It is `servers`. A copied `mcpServers` block is the usual cause. +- **The server sits at `Stopped`**: open **MCP: List Servers**, select `refactron`, then **Start Server**, and read **Show Output** for the launch error. +- **`spawn refactron-mcp ENOENT`**: the binary is not on the `PATH` VS Code inherited. Run `which refactron-mcp` in a terminal and use that absolute path as `command`, or use the `npx` form. +- **The tool never gets called**: Copilot only calls tools in **Agent** mode. Ask and Edit modes do not. +- **GitHub Copilot CLI does not read this file**: the CLI keeps its own MCP config and expects `mcpServers`. Configuring VS Code does not configure the CLI. +- **A verification takes minutes**: `verify_change` runs your real test suite in a shadow copy. diff --git a/docs/mcp/windsurf.mdx b/docs/mcp/windsurf.mdx new file mode 100644 index 00000000..ed168b37 --- /dev/null +++ b/docs/mcp/windsurf.mdx @@ -0,0 +1,194 @@ +--- +title: Windsurf +icon: /assets/clients/windsurf.svg +description: Add the Refactron MCP server to Windsurf Cascade by editing ~/.codeium/windsurf/mcp_config.json. +--- + +Windsurf keeps MCP servers in a single file under your home directory, shared across every workspace. Cascade picks them up after a refresh. + +## Set it up with your agent + +One prompt, written for Windsurf to read rather than you. It installs the +server, registers it, reloads, and proves the tool works with a real +verification. + +
+ +```text +Set up the Refactron MCP server for yourself in this repository and prove it +works before you tell me it is done. Do the steps in order. + +You are running in Windsurf. + +STEP 1 - Check the prerequisites. + +Run `node --version`. Refactron needs Node.js 18 or newer. If it is older or +missing, stop and tell me. + +Run `python3 --version`, then check that `pytest` and `coverage` are +importable. Coverage attestation is Python-only, and it is what makes a +coverage-backed SAFE verdict possible. Without it the server still runs and +still gates the change, but every verdict caps at UNPROVEN. + +STEP 2 - Install the server. + +Run `which refactron-mcp`, or `where refactron-mcp` on Windows. If it prints a +path, go to step 3. Otherwise install it: + + npm install -g refactron@0.3.0 + +That puts two binaries on PATH: `refactron` (the CLI) and `refactron-mcp` (the +MCP server). If you cannot install globally, install nothing and use the npx +form in step 3 instead. + +Do not use `pip install refactron` for this. The PyPI wrapper provides the +`refactron` command only. It does not ship `refactron-mcp`. + +STEP 3 - Register the server. + +Edit `~/.codeium/windsurf/mcp_config.json`, or +%USERPROFILE%\.codeium\windsurf\mcp_config.json on Windows, root key +"mcpServers". This one file is shared across every workspace. + + { "mcpServers": { "refactron": { "command": "refactron-mcp" } } } + +Merge into the existing object if the file already has servers, and validate +the JSON. Windsurf drops the whole file when it cannot parse it, so one stray +comma removes every server I have. + +Without a global install, use this instead. The `-p` flag is required, because +`refactron-mcp` is a second binary of the `refactron` package and not a package +of its own: + + { "mcpServers": { "refactron": { "command": "npx", + "args": ["-y", "-p", "refactron@0.3.0", "refactron-mcp"] } } } + +STEP 4 - Reload. + +Windsurf reads the config on refresh or restart, never on save. + +You cannot do this yourself. Tell me to click Refresh in the Cascade MCP panel, +under the hammer icon, and wait for me before you continue. + +STEP 5 - Confirm the tool is exposed. + +Ask me to confirm that `refactron` is listed with a green dot under the hammer +icon in the Cascade panel, with one tool beneath it. + +Windsurf caps how many tools it exposes to Cascade. Refactron adds exactly one, +but if I am near the cap, tell me which server to disable. + +You are looking for a server named `refactron`, version 0.3.0, exposing exactly +ONE tool: `verify_change`. + +If the server is connected but no tool appears, the handshake failed. Prove the +binary itself works by sending it one initialize request: + + echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"probe","version":"1.0"}}}' | refactron-mcp + +A working server replies on one line with serverInfo.name "refactron". If that +works and the client still shows nothing, the fault is the config: check the +root key and check that the file parses. + +STEP 6 - Prove it works with one real verification. + +Do not skip this. A connected server is not a working server. + +Pick one small source file that this project's test suite exercises. Propose a +real but behaviour-preserving edit to it: reorder the operands of a commutative +expression, rename a local variable, that kind of thing. One or two lines. + +Do NOT write that edit to disk. Call verify_change with the proposal instead: + + repoRoot the ABSOLUTE path to this repository + edits [{ "path": "", + "newContent": "" }] + testCmd the project's test command, if it is not obvious. For a Python + project installed into the environment (an editable + `pip install -e .` included), prefix it with PYTHONPATH=. so the + tests import the copy being verified rather than the installed + one. Use PYTHONPATH=src for a src layout. + +Verify the change BEFORE it exists on disk. The shadow tree is a copy of the +working tree, so if you write the change first and then pass a `git diff` of +it, the diff no longer applies and you get "diff did not apply (stale base?)" +back instead of a verdict. + +Verification runs the whole test suite in a shadow copy, so it can take minutes +on a real project. That is the work, not a hang. + +STEP 7 - Report, then stop. + +Tell me: + - which file you wrote, or which command you ran + - the exact `verdict` and the exact `reason` from the response + - the value of `coverage.tool`: "coverage.py" means coverage was measured, + "none" means it was not + +Apply nothing. The step 6 edit was a probe. Confirm with `git status` that the +working tree is exactly as dirty as you found it, and no more. + +Do not describe a SAFE verdict as "correct", "proven", or "guaranteed". SAFE +means the project's own tests ran the changed code and stayed green. It +inherits exactly what those tests check, and a weak suite yields a weak SAFE. +``` + +
+ +Prefer to do it yourself? The rest of this page is the same setup by hand. + +## Config location + +| OS | Path | +| ------------ | ------------------------------------------------- | +| macOS, Linux | `~/.codeium/windsurf/mcp_config.json` | +| Windows | `%USERPROFILE%\.codeium\windsurf\mcp_config.json` | + +Windsurf can open it for you: in the Cascade panel, click the hammer icon, then **Configure**. + +## Add it + +```json +{ + "mcpServers": { + "refactron": { + "command": "refactron-mcp" + } + } +} +``` + +To pin the version and skip the global install: + +```json +{ + "mcpServers": { + "refactron": { + "command": "npx", + "args": ["-y", "-p", "refactron@0.3.0", "refactron-mcp"] + } + } +} +``` + +The `-p` flag is required. `refactron-mcp` is a second binary of the `refactron` package, not a package of its own. + +Save the file, then click **Refresh** in the Cascade MCP panel. Windsurf does not reload the file on save. + +## Verify the connection + +Click the hammer icon in the Cascade panel. `refactron` is listed with a green dot and one tool: `verify_change`. + +Ask Cascade to confirm: + +```text +List the tools you have from the refactron MCP server. +``` + +## Troubleshooting + +- **Nothing changes after editing the file**: press **Refresh** in the MCP panel. Windsurf reads the config on refresh or restart, never on save. +- **The server is listed but red**: the command did not launch. Run `which refactron-mcp`. If it prints nothing, run `npm install -g refactron@0.3.0`, or use the `npx` form above. +- **Invalid JSON**: Windsurf drops the whole file when it cannot parse it, so one stray comma removes every server. Validate before refreshing. +- **Tool call limits**: Windsurf caps the number of tools it exposes to Cascade. Refactron adds exactly one, but if you are near the cap, disable a server you are not using. +- **A verification takes minutes**: `verify_change` runs your real test suite in a shadow copy. That is the work, not a hang. diff --git a/docs/overview.mdx b/docs/overview.mdx index 2956d3be..00e4222a 100644 --- a/docs/overview.mdx +++ b/docs/overview.mdx @@ -56,7 +56,7 @@ refactron verify-diff . --diff change.diff --test-cmd "python3 -m pytest -q" Verify a diff from the command line or as a CI merge gate. `UNSAFE` fails the build. - + A `verify_change` tool your AI agent calls before it lands a change. diff --git a/docs/quickstart.mdx b/docs/quickstart.mdx index 1b938305..9275e0c5 100644 --- a/docs/quickstart.mdx +++ b/docs/quickstart.mdx @@ -124,7 +124,7 @@ The same engine is available as an [MCP](https://modelcontextprotocol.io) tool, claude mcp add refactron -- refactron-mcp ``` -The agent proposes an edit (as full-file contents or a unified diff), calls `verify_change`, and gets back the same `SAFE` / `UNSAFE` / `UNPROVEN` report, then decides whether to land it. Full setup in [MCP server](/verification/mcp-server). +The agent proposes an edit (as full-file contents or a unified diff), calls `verify_change`, and gets back the same `SAFE` / `UNSAFE` / `UNPROVEN` report, then decides whether to land it. Full setup, for every client, in the [MCP tab](/mcp/index). ## Migration mode diff --git a/docs/style.css b/docs/style.css new file mode 100644 index 00000000..24754dea --- /dev/null +++ b/docs/style.css @@ -0,0 +1,123 @@ +/* Mintlify picks this file up automatically because it sits next to docs.json. + It loads after the framework styles, so plain specificity is enough and + nothing here needs !important. */ + +/* --------------------------------------------------------------------------- + Client marks (docs/assets/clients/*.svg) + + Mintlify renders a path-based `icon` as . An loads the + SVG as its own document, so the mark cannot inherit the page's CSS `color` + and a `currentColor` fill just resolves to black and disappears on dark. + + The marks therefore ship one fixed near-black fill, and dark mode inverts + them. Every mark is a single monochrome path, so invert(1) is exact. + + Keyed to `.dark` rather than `prefers-color-scheme` on purpose: Mintlify's + theme toggle sets that class on and its bundle contains no + prefers-color-scheme rules at all, so a media query would follow the + operating system and contradict the toggle. + --------------------------------------------------------------------------- */ + +.dark img[src*='/assets/clients/'] { + filter: invert(1); +} + +/* --------------------------------------------------------------------------- + Copy-only agent prompts + + `
` around a fenced code block turns it into a + single copy button. The text inside is addressed to an AI agent, not to a + reader, so showing it costs a screen of scrolling and buys nothing. + + The code body is collapsed with max-height/overflow rather than + `display: none` or `visibility: hidden`: those two remove an element from + the rendered text, so a copy handler reading `innerText` would put an empty + string on the clipboard. Clipped-but-rendered text still copies. + + If this stylesheet ever fails to load, the block degrades to an ordinary + visible code block that still copies correctly. + --------------------------------------------------------------------------- */ + +.agent-prompt .code-block [data-component-part='code-block-root'], +.agent-prompt .code-block [data-fade-overlay] { + max-height: 0; + overflow: hidden; + padding-top: 0; + padding-bottom: 0; + border: 0; +} + +.agent-prompt .code-block { + margin-top: 1rem; + margin-bottom: 1rem; + cursor: pointer; + border-color: #dcd8cd; + background: #f7f6f3; + transition: + background-color 0.15s ease, + border-color 0.15s ease; +} + +.agent-prompt .code-block:hover { + border-color: #c4bda9; + background: #f1efe8; +} + +.dark .agent-prompt .code-block { + border-color: rgba(255, 255, 255, 0.13); + background: rgba(255, 255, 255, 0.035); +} + +.dark .agent-prompt .code-block:hover { + border-color: rgba(234, 231, 222, 0.32); + background: rgba(255, 255, 255, 0.07); +} + +/* The label. `content` reads an inherited custom property so one rule serves + every prompt, and each block sets its own wording via a modifier class. */ +.agent-prompt .code-block::after { + content: var(--prompt-label, 'Copy the prompt'); + display: block; + padding: 1rem 3.5rem 1rem 1.15rem; + font-size: 0.9375rem; + font-weight: 500; + line-height: 1.4; + color: #141416; + pointer-events: none; +} + +.dark .agent-prompt .code-block::after { + color: #eae7de; +} + +.agent-prompt { + --prompt-label: 'Copy the setup prompt'; +} +.agent-prompt.is-rule { + --prompt-label: 'Copy the verification rule'; +} +.agent-prompt.is-project-rule { + --prompt-label: 'Copy the project rule'; +} + +/* Stretch Mintlify's copy button over the whole bar, so the entire strip is + the click target rather than a 26px icon in the corner. Without this the + bar looks pressable and is not, which is worse than looking plain. */ +.agent-prompt .code-block [data-floating-buttons] { + inset: 0; + padding-right: 1.15rem; + justify-content: flex-end; +} + +.agent-prompt .code-block [data-floating-buttons] > div, +.agent-prompt .code-block [data-testid='copy-code-button'] { + width: 100%; + height: 100%; + justify-content: flex-end; +} + +/* The button ships a `backdrop-blur` class. Harmless behind a 26px icon, + but stretched across the bar it blurs the label sitting behind it. */ +.agent-prompt .code-block [data-testid='copy-code-button'] { + backdrop-filter: none; +} diff --git a/docs/styles/config/vocabularies/Mintlify/accept.txt b/docs/styles/config/vocabularies/Mintlify/accept.txt index ce245c04..fbe162b4 100644 --- a/docs/styles/config/vocabularies/Mintlify/accept.txt +++ b/docs/styles/config/vocabularies/Mintlify/accept.txt @@ -46,3 +46,17 @@ config npm venv sdist +Cline +Windsurf +Zed +Codeium +Cascade +Copilot +stdio +mcp +JSON-RPC +globalStorage +Jinja +TOML +Codex +Gemini diff --git a/docs/verification/mcp-server.mdx b/docs/verification/mcp-server.mdx index eabbfa24..b636f862 100644 --- a/docs/verification/mcp-server.mdx +++ b/docs/verification/mcp-server.mdx @@ -1,44 +1,49 @@ --- title: MCP server -icon: plug -description: 'Give your AI agent the deterministic gate it can call before it lands a change: a verify_change tool over MCP that returns a SAFE, UNSAFE, or UNPROVEN verdict.' +icon: /assets/clients/mcp.svg +description: 'The Refactron MCP server has its own tab: setup for every major AI coding client, plus the verify_change tool contract.' --- -Refactron ships an [MCP](https://modelcontextprotocol.io) server that exposes one tool: **`verify_change`**. An agent proposes an edit, calls `verify_change`, and gets back a `SAFE` / `UNSAFE` / `UNPROVEN` verdict with a reproducible report, before it writes anything to your repo. +Refactron ships an [MCP](https://modelcontextprotocol.io) server exposing one tool, **`verify_change`**, so an AI agent can verify a change before it lands. Setup and reference moved to the [MCP tab](/mcp/index), which covers every major client. -This is how Refactron fits an agentic workflow: it isn't a competing code generator, it's the deterministic gate the generator calls to check its own work. + + + What the server is, how to install it, and which client pages exist. + + + Install, register, confirm the tool is listed, and get a first verdict. + + + Arguments, request and response examples, and the error shape. + + + One prompt sets this up end to end. Another keeps it verifying before it applies. + + - - An AI agent calling Refactron's verify_change MCP tool and receiving a SAFE, UNSAFE, or UNPROVEN verdict before landing the change - +## Connect your client -## Install +[Claude Code](/mcp/claude-code), [Claude Desktop](/mcp/claude-desktop), [Codex CLI](/mcp/codex), [Cursor](/mcp/cursor), [GitHub Copilot in VS Code](/mcp/vscode), [Gemini CLI](/mcp/gemini-cli), [Windsurf](/mcp/windsurf), or [any other MCP client](/mcp/other-clients), which covers Zed and Cline. -Prerequisites: Node.js ≥ 18, and for a coverage-backed `SAFE` verdict, Python 3.8+ with `pytest` and `coverage.py` (the same prerequisites as the [quickstart](/quickstart#install)). +## The short version + +Install the npm package, which puts `refactron-mcp` on your `PATH`: ```bash npm install -g refactron@0.3.0 ``` -That puts the server on your `PATH` as `refactron-mcp`, alongside the `refactron` CLI. It speaks MCP over **stdio** and registers itself under the name `refactron`. - - - The PyPI shim (`pip install refactron==0.3.0`) provides the `refactron` command only. The MCP - server comes from the npm package. - - -## Register it with your client - -For Claude Code: +Register it as a stdio server. For Claude Code: ```bash claude mcp add refactron -- refactron-mcp ``` -Any MCP client works the same way: declare `refactron-mcp` as a stdio server. +For clients configured with JSON: ```json { @@ -50,119 +55,6 @@ Any MCP client works the same way: declare `refactron-mcp` as a stdio server. } ``` -The server resolves your repo from the tool arguments, not its own working directory, so it does not matter where the client starts it. - -### From a source checkout (contributors) - -Working on Refactron itself? Build the checkout and register that build instead of the published binary: - -```bash -git clone https://github.com/Refactron-ai/Refactron_Lib_TS -cd Refactron_Lib_TS -npm install -npm run build -``` - -The server is then at `dist/mcp/server.js`. Point the client at it with an absolute path: - -```bash -claude mcp add refactron -- node /absolute/path/to/Refactron_Lib_TS/dist/mcp/server.js -``` - -## The `verify_change` tool - -Verify a proposed change and get the verdict. The change is supplied as **either** full-file contents **or** a unified diff; one of the two is required. +VS Code uses the root key `servers` instead of `mcpServers`, and Zed uses `context_servers`. Per-client paths and verification steps are on the client pages linked above. -| Argument | Type | Required | Description | -| ------------- | ------------------------ | ------------ | --------------------------------------------------------- | -| `repoRoot` | string (absolute path) | yes | The repository root to verify against. | -| `edits` | `[{ path, newContent }]` | one of these | Proposed full-file contents, keyed by repo-relative path. | -| `unifiedDiff` | string | one of these | A unified/git diff to apply and verify. | -| `testCmd` | string | no | Override the test command (e.g. `python3 -m pytest -q`). | - -The tool returns the [verification report](/verification/verify-diff#the-json-report) as JSON text content: the same structure `verify-diff --json` prints: - -```json -{ - "reportVersion": 1, - "verdict": "SAFE", - "gates": { - "syntax": { "passed": true, "durationMs": 11 }, - "imports": { "passed": true, "durationMs": 8 }, - "tests": { "passed": true, "durationMs": 2980 } - }, - "changedFiles": ["calc.py"], - "coverage": { - "tool": "coverage.py", - "changedLinesCovered": true, - "changedStatements": { "total": 3, "covered": 2 }, - "uncovered": [{ "file": "calc.py", "line": 31 }], - "filesWithUncovered": 1 - }, - "reason": "Tests pass and the changed code is covered." -} -``` - -An agent reads `verdict` and decides: land on `SAFE`, stop on `UNSAFE`, and on `UNPROVEN` either add the test named in `missingTests` or ask a human. - -`reportVersion` identifies the schema. Read it before relying on any field, and treat an unknown value as a report you do not understand rather than one you can partially trust. - - - **`SAFE` does not mean every changed statement ran.** It means every changed *file* had at least - one changed statement executed. `coverage.uncovered` is populated on `SAFE` too, and - `changedStatements` gives the ratio: in the example above, two of three. An agent that treats - `SAFE` as "fully tested" is over-reading the verdict. If your policy needs more, gate on - `changedStatements` yourself. - - -### Both list fields are capped - -`missingTests` is capped at **50** entries and `coverage.uncovered` at **200**, so a mass reformat -cannot return a multi-megabyte report. When either is truncated the report says so explicitly: - -```json -"coverage": { - "uncoveredTruncated": { "shown": 200, "total": 412 }, - "filesWithUncovered": 37 -}, -"missingTestsTruncated": { "shown": 50, "total": 412 } -``` - -An agent must not read the absence of a file from `missingTests` as "that file is fine". Check -`missingTestsTruncated` first; when it is present, the named hints are a sample, and `total` plus -`filesWithUncovered` describe the real size of the gap. Each file is guaranteed a share of the list -before any file takes a second helping, so the sample spans the diff instead of stopping at the -first noisy file. - -A hint carrying `"excluded": true` on its `coverage.uncovered` entry sits in a `# pragma: no cover` -or `if TYPE_CHECKING:` block. No test can reach it, so its hint asks for a human review rather than -a new test, and an agent should not try to write one. - - - Coverage is **Python-only**. A TypeScript or mixed-language change returns `UNPROVEN` ("coverage - of the changed code could not be determined"), never `SAFE`. See - [Verdicts](/verification/verdicts). - - -## What it does and doesn't do - -- **Runs entirely local.** The verification happens on your machine, in a shadow tree. Nothing about your code leaves it. -- **Never mutates your repo.** `verify_change` reads your tree and applies the change in an isolated copy. Landing the change is the agent's job, after a verdict it trusts. -- **Deterministic.** The same repo state and the same diff produce the same verdict every time. - - - The `verify-diff` **CLI** is auth-gated (`refactron login`, or `REFACTRON_TOKEN` in CI; - unauthenticated exits `7`). The MCP `verify_change` handler runs the same local verification - engine directly and makes no network calls. - - -## Next - - - - What SAFE, UNSAFE, and UNPROVEN mean, and how coverage fuses in. - - - The same engine from the command line and CI. - - +The tool returns the same report `verify-diff --json` prints. See [Verdicts](/verification/verdicts) for what each verdict is allowed to claim, and [Verify a diff](/verification/verify-diff) for the same engine from the command line. diff --git a/docs/verification/verify-diff.mdx b/docs/verification/verify-diff.mdx index 4fab18aa..3bad286a 100644 --- a/docs/verification/verify-diff.mdx +++ b/docs/verification/verify-diff.mdx @@ -143,7 +143,7 @@ This is a note, not a verdict change. A green verdict on a diff that also weaken ## The JSON report -`--json` emits a reproducible record of the verdict: the same structure the [MCP tool](/verification/mcp-server) returns: +`--json` emits a reproducible record of the verdict: the same structure the [MCP tool](/mcp/tool-reference) returns: ```json { @@ -203,7 +203,7 @@ Unlike `preflight`, `verify-diff` has no `--fail-on-unproven` flag. To fail CI o The three verdicts, coverage fusion, and the Python-only limitation in depth. - + Give your AI agent the same gate as a `verify_change` tool call.