Files
deckcraft/docs/mcp.md
T
David MannandClaude Opus 5.5 cae5964ad8 fix(automation): confine agent screenshots and folderless sessions, bound reply reads
- ui.screenshot checks its path against the request's agent folders when accepted
- a headless session for agents let in with no agent folder may use no files
- read_line checks the deadline before each socket read
- an empty or relative XDG_CONFIG_HOME falls back to ~/.config
- help and docs agree that a session that went headless stays headless
- tests write the agent token owner-only, as the client requires on Unix

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-12-04 01:42:17 +01:00

10 KiB
Raw Blame History

MCP server

deckcraft-cli mcp runs a Model Context Protocol server on stdio. Every tool call goes to the open DeckCraft window while AI agents may use it, and otherwise to the server's own headless engine (no window). --headless always uses the headless engine; --sample opens the sample deck in it. Stdio request frames are limited to 16 MiB including the newline; oversized frames receive a JSON-RPC error and are drained so the next request can still be handled. Invalid UTF-8 frames receive a parse error.

Agents in the open window

One switch serves every Craft app: ArtCraft Launcher › Settings › AI agents. With the suite's AI-MCP flag on, DeckCraft lets agents into its open window while that switch names it; the launcher also adds one ArtCraft entry to the MCP clients it supports, so DeckCraft writes no client configuration of its own.

  • The window (crates/ui-egui/src/agents.rs, over the framework's AgentLink): while the switch allows it, DeckCraft serves its control protocol on 127.0.0.1, with a token in its settings folder, and publishes the port in agent-connection.json there. It stops and removes the file when the switch turns off; a file a crashed run left is removed at the next start. Port 0 (any free port) is the default; a taken port is tried again every few seconds.
  • The client: plain deckcraft-cli mcp reads that file on every tool call (the framework's Live), checks that the process it names is still running, and makes the window prove it holds the token before it proves it holds it too (auth.challenge), so the token never crosses the wire. A window opened after the session started is found too, unless a call already ran without a window: a session that went headless stays headless, so its documents don't move under the agent.
  • While DeckCraft is closed, the choice in Preferences › AI Integrations applies: open DeckCraft and wait for it, work without a window, or answer with an error. --when-closed launch|headless|error overrides it for one session.
  • Folders: an agent's requests in the window open and save files only in the agent folders set in Preferences › AI Integrations (Documents/ArtCraft/Agents/DeckCraft when none is set). That covers the engine's commands, the window's own reads and writes (app.open, ui.render and screenshots with a path, Save to a presentation's own path) and the commands the keys and clicks an agent queues fire later. The agent_folders tool names the folders; a headless session without automation roots answers unrestricted: true. Agents can't change the agent settings (app.agents refuses them from a confined request).
  • With the switch off, or without the AI-MCP flag, nothing listens and plain mcp runs headless. A window started with --control serves that channel for the whole run instead, and Preferences says the launch options manage it. A nightly and a run with DECKCRAFT_NO_PREFS let no agents in.

The settings live in agents.json in the settings folder (%APPDATA%\DeckCraft, ~/Library/Application Support/DeckCraft, ~/.config/deckcraft), written by the app and read by the CLI.

--connect (deprecated)

deckcraft-cli mcp --connect PORT --control-token-file PATH still drives a DeckCraft started with --control PORT --control-token-file PATH for one more release, and says on stderr that it is deprecated. The client authenticates with the app's per-launch token. Alternatively, use --control-token TOKEN; DECKCRAFT_CONTROL_TOKEN and DECKCRAFT_CONTROL_TOKEN_FILE supply fallbacks when their corresponding flags are absent. Headless mode does not resolve these credentials. Agent folders don't apply to it: nothing confines a --control window.

Connected mode uses the framework's ControlClient for reply reading and framing, with a 256 MiB reply cap including the newline. CRLF is accepted. Unparseable or unterminated replies, oversized replies and transport failures close the connection and report that the command may or may not have run; they never cause a replay. Check the document before retrying a mutation. Before sending another request, an unusable connection (including unsolicited buffered or socket bytes) is replaced and authenticated again. Large image replies must fit this budget; render to a file or use a smaller scale when necessary.

Regression coverage for #718 includes the framework trials in craft-libs' crates/automation/src/client_tests.rs: replies_are_matched_by_id, a_reply_cut_off_before_its_newline_is_a_lost_reply and an_unasked_line_makes_the_connection_unusable_before_sending. DeckCraft's crates/mcp/src/backend.rs keeps lost_reply_is_not_resent and connection_closed_before_the_call_is_retried to guard its replay and reconnect policy.

Confining file access

deckcraft-cli mcp --automation-read-root /work/project --automation-write-root /work/project/out
{"mcpServers": {"deckcraft": {"command": "deckcraft-cli",
  "args": ["mcp", "--automation-read-root", "/work/project", "--automation-write-root", "/work/project/out"]}}}

The two flags keep the agent to the folders you give it. Repeat either flag to allow access to more folders:

  • Every file a command reads must lie inside the read root: open_presentation and file.open, and insert_picture, insert.picture, picture.change, insert.audio and insert.video with a path. Pictures, audio and video are copied into the deck when they are inserted, so playing them later reads nothing from disk.
  • Every file a command writes must lie inside the write root: save_presentation, export (every format, and every slide of an image export), file.save, file.saveAs, file.export, and render_slide with a path, plus the .saving temporary file a save goes through.
  • Read and write access are separate. Give the same folder twice for both; a root left out grants none of its access (with only --automation-read-root, nothing can be written to disk). Without either flag nothing changes.
  • A path is made absolute against the server's working directory, then its links are followed: a file (or folder) link that leads out of a root is outside it. For a file that doesn't exist yet, its nearest existing folder's links are followed and the rest must be plain names, so .. below a folder that doesn't exist is refused, as is a link that leads nowhere (writing through it would create its target). The result is compared with the root by whole folder names: /work2/x is not inside /work. On Windows names are compared exactly after what exists is resolved to its real case (so OUT\x reaches the root out on an ordinary volume, but not in a case-sensitive folder), UNC paths (\\server\share\...) are resolved like drive-letter ones, and device names (CON, NUL, COM1, COM¹..., also followed by an extension or a colon) are refused.
  • A refused path is an ordinary tool error the agent can read and correct, for example automation path rejected: outside the write root /work/project/out: /etc/x.pptx or automation filesystem access is not granted: write authority is absent: /work/project/out/x.pptx.
  • The roots must be existing folders; a missing one stops the server with an error. Repeat either flag to allow access to another folder; both --flag <dir> and --flag=<dir> forms work.

The flags confine the in-process server, so --connect together with them is an error: the server would otherwise talk to an app that isn't confined. With them, plain mcp always runs headless; the open window keeps to its own agent folders (above). A running app started with deckcraft --control is not confined. --sample is the operator's own choice and is opened before the roots apply.

What the roots do not cover: commands that take no path still read and change the open deck, and inspect_document and inspect_slide return it. The system font scan and the app's own recovery folder are fixed paths, not agent input, and are not checked. Anything that reads or writes a path goes through one place in the engine (io::read_file and io::write_file); a test keeps the rest of the engine from touching the file system on its own.

The checks hold for every thread of the server process. A path is checked, then opened: another program that swaps a link in between can still win that race, so the roots keep an agent to the files it was given rather than guarding against other software on the computer.

Tools

Tool What it does
list_commands Every command (id, label, menu, shortcut, params doc), optionally filtered
run_command Run one command: {command, params} — every menu item, ribbon button and gesture is a command
batch Run several commands in order and stop at the first error
new_presentation, open_presentation, save_presentation, export Files: native .deckcraft, PowerPoint .pptx, PDF (slides, notes pages, handouts), PNG/JPEG, outline, animated GIF (size, seconds per slide, loop, slides)
inspect_document, inspect_slide Structure of the deck / one slide (shapes, text, placeholders, animations)
render_slide A slide as an image the model can look at
add_slide, go_to_slide Slides by layout
add_shape, add_text_box, set_text Shapes and text
insert_picture, insert_table, insert_chart Content
select, pointer, select_tool, key, type_text The same selection, mouse and keyboard paths as the UI
screenshot The whole window, UI included (open window)
call_app Any control protocol method (open window)
agent_folders Where the app opens and saves files for agents (read_folder, write_folder)

A tool refuses an argument that is not in its schema (insert_chart: unknown argument "data" (expected: categories, h, series, title, type, w, x, y)). Keys inside run_command's params are that command's parameters.

Useful commands for building decks: slide.new {layout, title, body}, shape.insert {preset, rect, text}, shape.connect {from, to, preset}, shape.freeform {points, closed, smooth}, shape.merge {op, ids}, format.*, design.theme, transition.set, animation.set, chart.* (chart.options {textColor} colours a chart's title, axes, legend and labels), table.*, file.export {path, layout} (PDF) or {path, width, secondsPerSlide, loop} (GIF). deckcraft-cli describe COMMAND prints any command's parameters.