From 351736ef6b0d8e55dc71a37c75ba0fe92bb29ec0 Mon Sep 17 00:00:00 2001 From: Nigel Ihza Firdausy <106657905+Ni-zav@users.noreply.github.com> Date: Fri, 9 Oct 2026 19:03:58 +0700 Subject: [PATCH] docs(mcp): grant scoped file roots in headless registration examples (#1673) The PHOTOCRAFT_AUTOMATION_*_ROOT variables are read only by the desktop app, so headless photocraft-cli mcp/serve need the --automation-*-root flags. Say so, and pass explicit roots in the .mcp.json and claude mcp add examples. Fixes #1551. Co-Authored-By: Claude Opus 5.5 --- docs/control-protocol.md | 7 +++++-- docs/development.md | 15 ++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/docs/control-protocol.md b/docs/control-protocol.md index 593db12b876..366a3f1cff1 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -248,8 +248,11 @@ lines are visible. The protocol is unencrypted and must remain on loopback; do n it to an untrusted host. Filesystem access fails closed unless launch-time read and/or write roots are granted with -`--automation-read-root` and `--automation-write-root` (or -`PHOTOCRAFT_AUTOMATION_READ_ROOT` / `PHOTOCRAFT_AUTOMATION_WRITE_ROOT`). Request paths must be +`--automation-read-root` and `--automation-write-root`. The environment-variable equivalents +(`PHOTOCRAFT_AUTOMATION_READ_ROOT` / `PHOTOCRAFT_AUTOMATION_WRITE_ROOT`) are supported by +the desktop `photocraft` process, but not by headless `photocraft-cli mcp` or `serve`; +for those CLI modes, supply the flags explicitly. In MCP bridge mode, configure roots on the +desktop process rather than on the bridging CLI. Request paths must be non-empty, forward-slash relative paths beneath the applicable root. Absolute paths, parent traversal, alternate separators, drive/device/stream prefixes, malformed components, and link escapes are rejected before file effects. Read and write authority are independent; the parent of diff --git a/docs/development.md b/docs/development.md index 64bff77685a..06bc0fff879 100644 --- a/docs/development.md +++ b/docs/development.md @@ -65,8 +65,8 @@ By default PhotoCraft's own crates log at `info` and everything else at `warn`. | `RUST_LOG` | Log levels for standard error and the log file (see [Logs](#logs)) | | `PHOTOCRAFT_CONTROL_TOKEN` | 64-hex bearer token for control TCP (avoid on shared systems where environment inspection is possible) | | `PHOTOCRAFT_CONTROL_TOKEN_FILE` | Read, or create for a server, the control bearer-token file | -| `PHOTOCRAFT_AUTOMATION_READ_ROOT` | Directory capability for automation reads; requests use relative paths | -| `PHOTOCRAFT_AUTOMATION_WRITE_ROOT` | Separate directory capability for automation writes; requests use relative paths | +| `PHOTOCRAFT_AUTOMATION_READ_ROOT` | Desktop app only: automation read root. Headless CLI modes require the `--automation-read-root` flag | +| `PHOTOCRAFT_AUTOMATION_WRITE_ROOT` | Desktop app only: automation write root. Headless CLI modes require the `--automation-write-root` flag | | `PHOTOCRAFT_CPU_CANVAS=1` | Force the CPU canvas path instead of the wgpu shader canvas | | `PHOTOCRAFT_NATIVE_WAYLAND=1` | Linux: stay on native Wayland when a pen is attached (by default the window then opens through Xwayland, because Wayland gives the app no pen input; #639) | | `WGPU_BACKEND=dx12` | Pick the wgpu backend(s) (`vulkan`, `dx12`, `metal`, `gl`); overrides `performance.gpuBackend` and the startup fallback | @@ -138,6 +138,8 @@ Keep one `PcraftWriter` per open document: re-saving then only compresses and wr - **Headless:** `photocraft-cli mcp --automation-read-root --automation-write-root `. It drives an in-process engine session and has no file authority when a root is omitted. - **Live app:** start `photocraft --control 7878 --control-token-file --automation-read-root --automation-write-root `, then run `photocraft-cli mcp --bridge 127.0.0.1:7878 --control-token-file `. The desktop process owns the roots. See `docs/control-protocol.md#mcp-bridge`. +For headless MCP clients, pass absolute paths to deliberately chosen trusted workspace directories in the launch arguments. Desktop `PHOTOCRAFT_AUTOMATION_READ_ROOT` and `PHOTOCRAFT_AUTOMATION_WRITE_ROOT` environment variables do **not** grant headless CLI access. Omitting a root flag deliberately denies that direction of access. + Tools: - `session_list` @@ -153,7 +155,7 @@ Claude Code (`.mcp.json` in the repo root, or `claude mcp add`): "mcpServers": { "photocraft": { "command": "/path/to/photocraft/target/release/photocraft-cli", - "args": ["mcp"] + "args": ["mcp", "--automation-read-root", "/absolute/path/to/trusted/workspace", "--automation-write-root", "/absolute/path/to/trusted/workspace"] }, "photocraft-live": { "command": "/path/to/photocraft/target/release/photocraft-cli", @@ -165,7 +167,10 @@ Claude Code (`.mcp.json` in the repo root, or `claude mcp add`): ```sh cargo build --release -p photocraft-cli -claude mcp add photocraft -- "$PWD/target/release/photocraft-cli" mcp +mkdir -p "$PWD/photocraft-work" +claude mcp add photocraft -- "$PWD/target/release/photocraft-cli" mcp \ + --automation-read-root "$PWD/photocraft-work" \ + --automation-write-root "$PWD/photocraft-work" ``` `doc_inspect` (and the engine command `document.inspect`) reports the layer tree with kinds, @@ -178,7 +183,7 @@ capability-scoped export, resize/crop, CMYK + native save) driven purely over MC Without MCP, `photocraft-cli serve [--port N]` keeps a headless session open and answers JSON lines (see `docs/control-protocol.md#headless-server`). -A typical agent loop: +A typical agent loop (place inputs under the configured read root and outputs under the write root): 1. `doc_open {path}` 2. `command_list {filter:"blur"}`