Skip to content

MCP: confine file access with --automation-read-root and --automation-write-root - #247

Merged
h-a-n-a-s-h-i merged 4 commits into
storytold:mainfrom
isaac-levine:mcp-automation-roots
Oct 14, 2026
Merged

h-a-n-a-s-h-i merged 4 commits into
storytold:mainfrom
isaac-levine:mcp-automation-roots

Conversation

@isaac-levine

Copy link
Copy Markdown
Contributor

deckcraft-cli mcp gives the agent on the other end the same file access as the user running it. VectorCraft already has two flags for this, so this adds the same ones here with the same names and behaviour, and one client config works across the apps. It is the same change as storytold/gridcraft#480 and storytold/wordcraft#798.

deckcraft-cli mcp --automation-read-root /work/project --automation-write-root /work/project/out

How it works

The engine only ever opens a user-named file in three places: file.open, the media read behind insert.picture, insert.audio, insert.video and picture.change, and the writer behind file.save, file.saveAs and file.export. Those now go through two small helpers, io::read_file and io::write_file, and the checks sit there. The new crates/engine/src/file_access.rs holds the roots and the path logic: make the path absolute, follow symlinks (for a file that doesn't exist yet, resolve its nearest existing ancestor and require the rest to be plain names), then compare with the root by whole path components. On Windows the comparison ignores case, handles \\?\ and UNC prefixes, and refuses device names like CON and NUL. Refusals come back as ordinary tool errors with VectorCraft's wording, for example automation path rejected: outside the read root /work/project: /etc/passwd.

A test walks every file under crates/engine/src and fails if one other than io.rs, file_access.rs, recovery.rs and the test files calls std::fs, File::open, File::create or OpenOptions.

Headless::with_automation_roots in deckcraft-mcp puts the roots in force for every call. The CLI accepts --flag DIR or --flag=DIR, refuses a flag given twice, and refuses a root that is missing or not a folder. A root left out grants none of its access, so --automation-read-root alone makes the server read-only. The flags only make sense for the in-process server, so combining them with --connect is an error. docs/mcp.md gets a "Confining file access" section.

What is covered

Reads: open_presentation, file.open, and insert_picture, insert.picture, picture.change, insert.audio and insert.video with a path. Writes: save_presentation, export (every format, and every slide of an image export), file.save, file.saveAs, file.export, render_slide with a path, plus the .saving temporary file a save goes through. Calls that return bytes instead of writing a path keep working with only a read root. Pictures, audio and video are copied into the deck when inserted, so playing them at show time reads nothing from disk and needs no check of its own.

Not covered: --sample is the operator's own choice and is opened before the roots apply. The desktop app (deckcraft --control) doesn't take the flags yet, since VectorCraft's app-side version also has to leave the user's own file dialogs unconfined, which is a bigger change in ui-egui that I'd rather do separately, so the docs say a running app is not confined. Commands that take no path still read and change the open deck. The system font scan and the app's recovery folder are fixed paths set by the host, not agent input, and are not checked. Like VectorCraft, this is check-then-open, so it keeps an agent inside the folders it was given rather than defending against other programs racing it.

The --connect error says to drop --connect instead of pointing at app-side flags like VectorCraft's does, since DeckCraft's app has none, matching the GridCraft wording.

This does not touch edit.rs or ui-egui, so it should merge independently of #191. It also doesn't depend on #177, but if the GIF export lands first its writer needs to use io::write_file (the guard test will say so).

Testing

Unit tests on the path logic (inside/outside, .., same-prefix sibling, symlinks out via a temp dir, each root left out, both roots the same folder) and on the flag parsing. crates/mcp/tests/automation_roots.rs goes through the MCP protocol and checks that opening or inserting from outside the read root is refused and nothing from the file reaches the deck, that every saving command is refused outside the write root and no file appears, the one-root configurations, links out being refused, and that no roots means no confinement. apps/deckcraft-cli/tests/cli.rs runs the real binary with both flag spellings and each argument error.

cargo fmt --all -- --check
cargo clippy -p deckcraft-engine -p deckcraft-mcp -p deckcraft-cli --all-targets -- -D warnings
cargo test -p deckcraft-engine -p deckcraft-mcp -p deckcraft-cli
cargo xtask layers
cargo xtask wasm

All pass. cargo xtask ci passed all six steps (fmt, clippy, test, assets, layers, wasm) before the last change, which only widened the guard test and edited one docs sentence, after which I reran the commands above. Windows paths weren't exercised, I only have a Mac.

@echelon

echelon commented Oct 14, 2026

Copy link
Copy Markdown
Member

Thank you for this contribution, @isaac-levine! It has landed on main and will ship in the next DeckCraft release.

If you haven't already, please come join us on Discord: https://discord.gg/artcraft

h-a-n-a-s-h-i pushed a commit that referenced this pull request Oct 14, 2026
design.browseTheme reads its path with io::read_file, and File › Info sizes the file with
io::file_len (which checks the read root), so commands_do_not_touch_the_file_system_themselves
passes. spell.rs is allow-listed beside recovery.rs: it touches only the app's own dictionary
folders. main's render_slide MCP tool refuses a `path` argument (#371), so the root tests
render to a file through call_app ui.render instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
uvxszi added a commit to uvxszi/deckcraft that referenced this pull request Oct 14, 2026
Morph keeps both a re-cropped picture's crop and a 3-D model's turn. Save as Picture and a model's
companion files go through `crate::io`, so the automation roots (storytold#247) confine them; the model
tests, which write their own fixture files, are `tests_model3d.rs`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants