From 819df314267f447c3fa9b7a0cd1db3c34bc02eaa Mon Sep 17 00:00:00 2001 From: yoriswind Date: Tue, 1 Dec 2026 05:58:36 -0800 Subject: [PATCH] Document the control token for live MCP sessions (cherry picked from commit 946ffdf7f5aa8f2ec37992bcf7d5ec341a019509) --- docs/control-protocol.md | 13 +++++--- docs/mcp.md | 67 ++++++++++++++++++++++++++++------------ 2 files changed, 55 insertions(+), 25 deletions(-) diff --git a/docs/control-protocol.md b/docs/control-protocol.md index df9b36eee8..945f6e8b99 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -4,7 +4,9 @@ `vectorcraft --control ` listens on `127.0.0.1:` (loopback only). The port must be a number from 1 to 65535 (`--control=` works too), given once; otherwise the app prints an error and exits -before it starts. One JSON request per line: +before it starts. Each connection must authenticate with the app's control token before it can send +commands. The [MCP setup guide](mcp.md#connect-to-the-desktop-app) shows how to give the app and the CLI +the same token file. After authentication, send one JSON request per line: `{"id": 1, "method": "ui.inspect", "params": {}}` → `{"id": 1, "ok": true, "result": {...}}` or `{"id":1,"ok":false,"error":"..."}`. Set `VECTORCRAFT_CONFIG_DIR` to a dedicated directory for an isolated native test profile. Preferences, @@ -23,10 +25,11 @@ nothing sent after it on that connection runs. That covers text that isn't JSON, an object without `method`, invalid UTF-8, and a line longer than 4 MiB. An HTTP request (for example a web page's cross-origin `fetch` to `127.0.0.1:`) therefore can't smuggle a command in its body: its request line is rejected first. At most 16 connections are served at once; further ones get an error -line and are closed. Clients that get an error reply should reconnect. The port has no authentication, -so only enable it while you use it. Idle clients have 5 minutes to start their next line; once the -first byte arrives, the complete line must arrive within an absolute 30 seconds (trickled bytes do not -renew it). A reply has 60 seconds to be written. Expiration closes the connection and returns its slot +line and are closed. Clients that get an error reply should reconnect and authenticate again. Keep +the control token private and enable the port only while you use it. Idle clients have 5 minutes to start +their next line. Once the first byte arrives, the complete line must arrive within an absolute 30 seconds +(trickled bytes do not renew it). A reply has 60 seconds to be written. Expiration closes the connection +and returns its slot (an idle connection is closed without a line, so nothing waits where the next reply would be; a line that stalls gets the usual error line first); persistent clients can send further requests within these bounds, or reconnect after idle expiration. diff --git a/docs/mcp.md b/docs/mcp.md index 99c8f3ab1b..b925380696 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -12,11 +12,11 @@ It has two backends: | Mode | How | What works | |---|---|---| -| **Remote** | `vectorcraft-cli mcp --connect 127.0.0.1:7979` (the app must run with `vectorcraft --control 7979`) | Everything. Tool calls are forwarded over the [control protocol](control-protocol.md), so you watch the app change live. | +| **Remote** | `vectorcraft-cli mcp --connect 127.0.0.1:7979` with the [live-session setup](#connect-to-the-desktop-app) | Everything. Tool calls are forwarded over the [control protocol](control-protocol.md), so you watch the app change live. | | **Headless** | `vectorcraft-cli mcp --headless` | An in-process engine session with a CPU renderer. Everything except the UI-only tools (`inspect_ui` or `ui_inspect`, `type_text`, `answer_dialog`, `open_panel`, `screenshot {window:true}` or `ui_screenshot`). | -With no flag, the server tries `127.0.0.1:7979` and falls back to headless. Logs go to stderr; stdout carries -only protocol messages. +With no flag, the server tries `127.0.0.1:7979` when it has a control token and falls back to headless if +it cannot connect. Logs go to stderr; stdout carries only protocol messages. ### Command catalogue (headless vs remote) @@ -40,9 +40,8 @@ cargo install --path apps/vectorcraft-cli --locked export PATH="${CARGO_HOME:-$HOME/.cargo}/bin:$PATH" vectorcraft-cli --help claude mcp add vectorcraft -- vectorcraft-cli mcp -# or pin a mode: +# or explicitly use headless mode: claude mcp add vectorcraft-headless -- vectorcraft-cli mcp --headless -claude mcp add vectorcraft-app -- vectorcraft-cli mcp --connect 127.0.0.1:7979 ``` Cargo installs a binary, not a symlink into `target/`, so it survives `cargo clean`. @@ -66,8 +65,6 @@ installed binary path, not a literal `~` or `$HOME` expression. Avoid symlinks i `target/release`: cleaning the build directory breaks them. A source build alone does not put the CLI on `PATH`. -For a live session, start the app first: `cargo run --release -p vectorcraft -- --control 7979`. - ### From an installed release The release packages ship `vectorcraft-cli` alongside the desktop app, so no build is needed: @@ -85,24 +82,54 @@ claude mcp add vectorcraft -- "$env:LOCALAPPDATA\Programs\ArtCraft\VectorCraft\v claude mcp add vectorcraft -- vectorcraft-cli mcp ``` -For a live session, start the installed app with the control port before the MCP client starts the server: +### Connect to the desktop app + +The app and the MCP server need the same control token. Choose an absolute path to a token file in an +existing private directory. Start the app with that path before starting the MCP server. VectorCraft +creates the token file if it is missing and reuses a valid token already in the file. ```sh -# macOS: quit VectorCraft first, since `open -a` passes no arguments to an app that is already running -open -a VectorCraft --args --control 7979 -# Windows (PowerShell), default install folder -& "$env:LOCALAPPDATA\Programs\ArtCraft\VectorCraft\vectorcraft.exe" --control 7979 -# Linux (deb, rpm) -vectorcraft --control 7979 +# Linux (deb, rpm). Use your private token-file path. +vectorcraft --control 7979 --control-token-file "/absolute/path/to/control-7979.token" +# macOS. Quit VectorCraft first so open -a starts it with these arguments. +open -a VectorCraft --args --control 7979 --control-token-file "/absolute/path/to/control-7979.token" +# From a source checkout +cargo run --release -p vectorcraft -- --control 7979 --control-token-file "/absolute/path/to/control-7979.token" ``` +```powershell +# Windows, default install folder. Use your private token-file path. +& "$env:LOCALAPPDATA\Programs\ArtCraft\VectorCraft\vectorcraft.exe" --control 7979 --control-token-file "C:\path\to\control-7979.token" +``` + +In the MCP client, run `vectorcraft-cli mcp --connect 127.0.0.1:7979` and set +`VECTORCRAFT_CONTROL_TOKEN_FILE` in the server process's environment to the same absolute path. For +clients that use an `mcpServers` JSON configuration, the entry looks like this: + +```json +{ + "mcpServers": { + "vectorcraft": { + "command": "vectorcraft-cli", + "args": ["mcp", "--connect", "127.0.0.1:7979"], + "env": {"VECTORCRAFT_CONTROL_TOKEN_FILE": "/absolute/path/to/control-7979.token"} + } + } +} +``` + +Use the installed CLI’s absolute path for `command` if it is absent from the client’s `PATH`. Keep +the token file private. As an alternative to the file, set `VECTORCRAFT_CONTROL_TOKEN` to the app’s +token in the server process. When using the token file, leave `VECTORCRAFT_CONTROL_TOKEN` unset in +that process because the CLI reads it first. + The Dock, Start menu and desktop launchers start the app without `--control`, so the app opens no control -port unless `VECTORCRAFT_CONTROL_PORT` is set. `vectorcraft-cli mcp` with no flag tries `127.0.0.1:7979` -once, when it starts: a server that started before the app stays headless until the MCP client restarts -it. `open -a` and PowerShell's `&` return before the app opens the port, so wait until the VectorCraft -window is open before you start the MCP client. With `--connect`, a server that finds no app stops and -prints `vectorcraft-cli: cannot connect to 127.0.0.1:7979: ` followed by the system's connection error, for -example `connection timed out`. +port unless `VECTORCRAFT_CONTROL_PORT` is set. With a token and no mode flag, `vectorcraft-cli mcp` tries +`127.0.0.1:7979` once at startup. A server that started before the app stays headless until the MCP client +restarts it. `open -a` and PowerShell's `&` return before the app opens the port, so wait until the VectorCraft +window is open before you start the MCP client. With `--connect`, `no control token` means the server +process has no token configured or read an empty token file. If the CLI reports that it cannot read the file, +check the path and its permissions. Restart the MCP server after changing the client’s configuration. ## Confining file access