Skip to content

Latest commit

 

History

History
196 lines (163 loc) · 11.3 KB

mcp.md

File metadata and controls

196 lines (163 loc) · 11.3 KB

AniCraft for AI assistants (MCP)

anicraft-cli mcp is a Model Context Protocol server. Any MCP client (an AI assistant, an editor, a script) can then open a document, draw, animate, look at frames and export through the same commands the app uses.

anicraft-cli mcp                                    # the AniCraft window you have open, while AI agents are on (below)
ROOTS="--automation-read-root /work/project --automation-write-root /work/project/renders"
anicraft-cli mcp --headless $ROOTS                  # a new, empty document
anicraft-cli mcp scene.anicraft $ROOTS              # open a document
anicraft-cli mcp --sample $ROOTS                    # the sample animation

AI agents in the open window

The ArtCraft Launcher has one switch for every Craft app: Settings › AI agents › Let AI agents use Craft apps. With it on (and the suite's AI-MCP flag, under which the apps follow that switch), the launcher adds one ArtCraft entry to Claude Desktop, Claude Code, Cursor and LM Studio, and the gateway behind it runs plain anicraft-cli mcp. AniCraft writes no client configuration of its own.

  • While the switch names AniCraft, the open AniCraft window lets agents in: every edit appears there at once and undoes with Ctrl+Z, like your own. The status bar says "AI agents on". The window listens on 127.0.0.1 only, with a token kept in the settings folder (agent-control.token, readable only by you) and a challenge handshake, and writes agent-connection.json there so anicraft-cli mcp finds it before every call: no port or token in any client's settings. Turn the switch off and the window stops listening at once, with no restart.
  • Agents open and save files only in the agent folders: Documents/ArtCraft/Agents/AniCraft unless the settings name others. The agent_folders tool tells an agent which they are. Your own work in the window is not limited.
  • While AniCraft is closed, mcp starts it and waits for its window (the default), works on a document of its own inside the agent folders, or says AniCraft isn't running: the settings' whenAppClosed (launch, headless or error), or --when-closed for one client.
  • With the switch off, mcp works on a document of its own inside the automation roots given on its command line, and with none it may open and save no file.

The settings are agents.json in AniCraft's settings folder (the same folder as control.json, below), in the shared Craft format:

{"controlPort": 0, "readRoot": "", "writeRoot": "", "whenAppClosed": "launch", "allowAgentControl": true}

controlPort 0 picks a free port; readRoot and writeRoot empty use the default agent folder; allowAgentControl false keeps agents out even with the switch on. They apply when AniCraft starts. A file that can't be read keeps agents out, and the status bar says why. AniCraft has no page for them in Preferences yet.

--headless always works on a document of its own, as do a document, --sample and --plugins on the command line: both roots are then required, as below.

The two folders an assistant may use

mcp does not start without both of these (it prints why and exits with code 2), except plain mcp with the suite's AI-MCP flag on (above): it then keeps to the agent folders while AI agents are on, and without roots touches no file otherwise. Roots given to it are used for a session of its own:

Flag The assistant's commands may
--automation-read-root <folder> read files inside this folder: open, import, saved commands, presets, swatches, data tables, plug-ins. Give it again for more folders.
--automation-write-root <folder> create, replace and delete files inside this folder: save, export, publish, templates. Given once.

They may be the same folder. Each must exist when the server starts. Use absolute paths in a client's configuration: a relative one starts at the folder the client launches the server in.

  • Reading and writing are separate. The write root can't be read from and the read roots can't be written to, unless you give a folder as both. (A command may still ask whether a file in the write root exists, so replacing one asks for "confirm": true as always.)
  • A path is checked as the file it really names: made absolute, .. removed, symbolic links and Windows junctions followed, and on Windows letter case ignored. A link inside a root to a file outside it is outside. A root itself counts as inside.
  • The check covers every file a command touches, not only the path it is given: a plain file.save of a document opened from elsewhere, Publish's outputs, the steps of a saved command, a video a document links to.
  • A refused command comes back as a tool error that names the root, before any file is touched: file.export_png: param 'path': C:\Users\me\a.png is outside the folder automation may write to: the automation write root is C:\work\project\renders.
  • The document and --plugins folder on the command line are your own choice and open as before; the roots apply to what the assistant asks for after that.
  • Temporary files AniCraft makes for itself (the soundtrack it hands to ffmpeg) are not affected.

serve takes the same two flags, optionally: with them it is limited in the same way. The app and the other subcommands (exec, run, render, …), which you run yourself, are not limited. The design is ADR 0124.

Headless, or the older --bridge

--headless (or a document, --sample or --plugins) edits a document of its own, with no window: good for pipelines and batch work. Save it (file.save) to keep the result.

--bridge <port> is the older way to reach a window, and goes in a later release: it prints a notice on stderr, and plain mcp with AI agents on replaces it. With it the same tools act on the AniCraft window you have open, started with anicraft --control <port>: every edit appears there at once, and Ctrl+Z undoes it (docs/control-protocol.md, ADR 0104). The server starts even when AniCraft isn't open (an assistant starts its servers when it starts) and connects on the first tool call; until AniCraft is open with remote control, the tools answer with how to start it. Close and reopen AniCraft whenever you like: the next call reconnects, with no need to restart the assistant. It finds the run's token in control.json in AniCraft's settings folder, so there is nothing to copy.

The two roots apply live too: the bridge sends them with each call and the window keeps that call's commands inside them, while your own work in the window is not limited. The window must be an AniCraft that applies roots (control protocol 2); the bridge refuses to send commands to an older one, which would ignore them.

The server talks MCP's stdio transport: JSON-RPC 2.0, one message per line on stdin and stdout. It speaks protocol revisions 2025-06-18, 2025-03-26 and 2024-11-05.

Connecting a client

With AI agents on in the ArtCraft Launcher there is nothing to set up: the launcher's ArtCraft entry reaches AniCraft. For a client of your own, or without the launcher, most clients take a server entry like this one (use the full path to anicraft-cli):

{
  "mcpServers": {
    "anicraft": {
      "command": "/path/to/anicraft-cli",
      "args": ["mcp", "/path/to/project/scene.anicraft",
               "--automation-read-root", "/path/to/project",
               "--automation-write-root", "/path/to/project"]
    }
  }
}

Without the launcher's switch, the older way to edit live (deprecated): start AniCraft with --control 9878 and use:

{
  "mcpServers": {
    "anicraft": {
      "command": "C:\\path\\to\\anicraft-cli.exe",
      "args": ["mcp", "--bridge", "9878",
               "--automation-read-root", "C:\\path\\to\\project",
               "--automation-write-root", "C:\\path\\to\\project"]
    }
  }
}

Tools

Tool What it does
anicraft_commands Lists the commands (id, label, menu, shortcut, params), optionally filtered by words such as tween or export.
anicraft_run Runs one command with its params.
anicraft_run_script Runs several commands in order; stops at the first error and says which step failed.
anicraft_document Describes the document: stage, scenes, layers and keyframes, library, and the current scene, frame, layer and selection.
anicraft_render Returns a frame of the current scene as a PNG picture, exactly as exported.
agent_folders The folders the agent's commands may open from (read_folder) and save to (write_folder); null for none.

The assistant sees one tool per job, not one per command: the command list is long and grows with every release, and anicraft_commands lets it find what it needs. Frames in params are 0-based, as everywhere in the engine (the CLI's own --frame flags are 1-based, as in the timeline).

Saved commands (ADR 0097) run through anicraft_run too: macro.run with {"path": …} (a saved command's file) or {"steps": [{"cmd", "params"}]} runs the steps as one undo step, and unlike anicraft_run_script a failing step leaves the document as it was. macro.history and macro.save turn the session's undo steps into a saved command.

A frame with artwork left out

A document can hold more than AniCraft draws in one frame (symbols nested many times over, as in a damaged file): the frame is then drawn in part (ADR 0128). The commands that write frames still write it, and their result has "left_out": true and a "warning"; anicraft_render says so in the picture's caption, and the document's state has the two keys for the frame shown. A result without them is a whole frame.

Safety

  • Everything runs through the engine's commands, so params are checked and every edit can be undone with edit.undo.
  • Commands that would lose unsaved work or replace a file refuse until their params include "confirm": true (ADR 0004). The server's instructions ask the assistant to check with you before confirming.
  • Commands read files only inside the automation read roots and write only inside the automation write root (above). Inside them the assistant has your permissions: it can read any file below a read root and create or replace files anywhere below the write root, so give it a project folder, not your home folder. The roots limit AniCraft's commands, not the assistant's other tools. A program running as you that swaps a folder for a link at the right moment could still redirect one operation, and hard links can't be told from files (ADR 0124).
  • An assistant can't choose the program that makes or reads video: over mcp and serve, every command refuses an ffmpeg param (Export Video, Import Video and the rest). Set ANICRAFT_FFMPEG yourself, or have ffmpeg on the PATH. (exec and run, which you type, keep the param.)
  • A failing command comes back as a tool result marked as an error, so the assistant can read the message and try again; it never stops the server.
  • Live (--bridge): an edit whose answer was lost (AniCraft closed mid-call) is never sent again, since it may have been made; the assistant is told to check with anicraft_document. While you are dragging, the assistant's edits wait until you let go, so the two stay separate undo steps.