Skip to main content
Glama
README.md
<p align="center"><img src="assets/banner@4x.gif" alt="Aseprite MCP banner: a brain-in-a-jar wizard robot hovers on rocket jets and casts a spell with a pencil wand at a biting floppy disk, a UFO abducting a cow, a worried planet, a three-eyed jellyfish, a tentacled eyeball and a duck astronaut, while a moon snores and the title glitches" width="960"></p>

# <img src="assets/icon@4x.png" alt="" width="48" height="48" align="top"> Aseprite MCP

Aseprite MCP lets an AI agent draw pixel art live in [Aseprite](https://www.aseprite.org/). The agent writes one JavaScript program per step ("code mode"). The server exposes one tool, `execute`.

## Why it is fast

- One program is one round trip and one undo step, however many pixels it changes.
- Pixel work runs natively. Methods such as `map`, `rect`, `fill` and `shift` change many pixels per call.
- The tool description is under about 1,000 tokens. The agent reads longer guidance on demand with `help(topic)`.

Measured on an Apple Silicon Mac with Aseprite 1.3.18: a program that draws a 48×48 sprite, builds a 12-frame animation and renders a critique view takes about 80 ms on Node and about 55 ms on Bun, from request to result.

## Install

Requires Aseprite and Node.js 24 or later (it runs the TypeScript sources directly). [Bun](https://bun.sh/) also runs the daemon, about 30% faster. The tests need Node.

1. Clone the repository and build the extension.

   ```sh
   git clone https://github.com/ParthMmm/aseprite-mcp.git
   cd aseprite-mcp
   npm install
   npm run build
   ```

2. In Aseprite, open **Preferences > Extensions**, choose **Add Extension**, and select `dist/aseprite-mcp.aseprite-extension`.
3. Restart Aseprite.
4. Print the pairing token.

   ```sh
   node bin/aseprite-mcp.ts token
   ```

5. In Aseprite, choose **File > Aseprite MCP...**, paste the token, and select **Connect**.

To make a new token, run `node bin/aseprite-mcp.ts token --new`, then paste it in the dialog again.

## Run

Start the shared daemon:

```sh
node bin/aseprite-mcp.ts serve   # or: bun bin/aseprite-mcp.ts serve
```

The daemon serves MCP at `http://127.0.0.1:9124/mcp`. Aseprite connects to it on `ws://127.0.0.1:9123`.

Connect a client in one of two ways:

- **Executor:** use Quick Add with the URL `http://127.0.0.1:9124/mcp`.
- **Any stdio client:** set the command to `node /path/to/aseprite-mcp/bin/aseprite-mcp.ts`. It starts the daemon if none runs.

By default, a view is returned as a file path. Use `http://127.0.0.1:9124/mcp?images=inline` to also get image blocks in the result.

Other commands:

| Command | Action |
| --- | --- |
| `node bin/aseprite-mcp.ts status` | Show whether the daemon runs and Aseprite is connected. |
| `node bin/aseprite-mcp.ts stop` | Stop the daemon. |
| `node bin/aseprite-mcp.ts token [--new]` | Print or rotate the Aseprite pairing token. |
| `node bin/aseprite-mcp.ts token --remote [--new]` | Print or rotate the remote HTTP bearer token. |

### Use it from other machines over Tailscale

If your machines share a [Tailscale](https://tailscale.com) tailnet, agents on any of them can connect to the daemon with one URL.

1. On the machine that runs Aseprite, start the daemon with `--tailscale`:

   ```sh
   node bin/aseprite-mcp.ts serve --tailscale
   ```

   The daemon runs `tailscale serve --bg --https=9124 http://127.0.0.1:9124` and logs the URL, such as `https://machine.example-tailnet.ts.net:9124/mcp`. The daemon itself still listens on `127.0.0.1` only.

2. On the other machine, add that URL to the MCP client as an HTTP server.

By default, only the Tailscale user who owns the machine can connect. To allow other users, set `ASEPRITE_MCP_TAILNET_USERS` to a comma-separated list of logins, such as `alice@example.com,bob@example.com`. The daemon compares each login with the `Tailscale-User-Login` header that `tailscale serve` adds, and refuses all other requests, including requests without that header.

If Serve is not yet enabled for your tailnet, `tailscale serve` prints a link to enable it. Open the link, then start the daemon again. The daemon stops with an error if `tailscale serve` does not finish within 30 seconds.

Tailnet callers differ from local callers in two ways:

- Each result includes view images as image blocks, because the caller cannot read file paths on this machine.
- A tailnet caller cannot stop the daemon.

To stop serving the daemon to the tailnet, run `tailscale serve --https=9124 off`.

If you run `tailscale serve` yourself, start the daemon with plain `serve` and set both `ASEPRITE_MCP_TAILNET_HOST` and `ASEPRITE_MCP_TAILNET_USERS`. `ASEPRITE_MCP_TAILNET_HOST` is the `Host` header the proxy forwards, such as `machine.example-tailnet.ts.net:9124`.

### Use it from other machines without Tailscale Serve

On a LAN, WireGuard, Tailscale without Serve, or behind your own TLS reverse proxy, start the daemon with `--remote`:

```sh
node bin/aseprite-mcp.ts serve --remote
```

The daemon binds HTTP to `0.0.0.0` (or `ASEPRITE_MCP_HTTP_HOST`), prints this machine's reachable Tailscale and LAN URLs, and requires `Authorization: Bearer <token>` from remote callers. Print or rotate the remote bearer token with:

```sh
node bin/aseprite-mcp.ts token --remote
node bin/aseprite-mcp.ts token --remote --new
```

The remote bearer token is separate from the Aseprite pairing token and lives in `~/.config/aseprite-mcp/remote-token` (or `ASEPRITE_MCP_REMOTE_TOKEN`). Remote bearer callers get inline view images and cannot stop the daemon, while local loopback callers on `127.0.0.1` keep working without a header.

Plain HTTP is not encrypted by `aseprite-mcp`. Use `--remote` over Tailscale, WireGuard, or a trusted LAN, or keep `ASEPRITE_MCP_HTTP_HOST=127.0.0.1` with `ASEPRITE_MCP_REMOTE_TOKEN` behind a TLS reverse proxy.

### Start the daemon at login on macOS

Save this as `~/Library/LaunchAgents/com.parthmmm.aseprite-mcp.plist`. Replace both paths: the first is your `node` or `bun` binary (`which bun`), the second is your clone.

```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key><string>com.parthmmm.aseprite-mcp</string>
  <key>ProgramArguments</key>
  <array>
    <string>/Users/you/.bun/bin/bun</string>
    <string>/path/to/aseprite-mcp/bin/aseprite-mcp.ts</string>
    <string>serve</string>
  </array>
  <key>RunAtLoad</key><true/>
  <key>KeepAlive</key><true/>
  <key>StandardErrorPath</key><string>/tmp/aseprite-mcp.log</string>
</dict>
</plist>
```

Then load it:

```sh
launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.parthmmm.aseprite-mcp.plist
```

After you update the code, restart it with `launchctl kickstart -k gui/$(id -u)/com.parthmmm.aseprite-mcp`. Aseprite reconnects by itself.

### macOS: keep Aseprite awake

macOS App Nap slows apps that sit in the background, and Aseprite then stalls saves until you bring it to the front. Turn App Nap off for Aseprite once, then restart Aseprite:

```sh
defaults write org.aseprite.Aseprite NSAppSleepDisabled -bool YES
```

### Start the daemon at login on Linux

Save this as `~/.config/systemd/user/aseprite-mcp.service`. Replace both paths: the first is your `node` or `bun` binary (`which bun`), the second is your clone. `%h` is your home directory.

```ini
[Unit]
Description=aseprite-mcp daemon

[Service]
ExecStart=%h/.bun/bin/bun %h/path/to/aseprite-mcp/bin/aseprite-mcp.ts serve
Restart=always
RestartSec=2

[Install]
WantedBy=default.target
```

Then start it, and let it run while you are logged out:

```sh
systemctl --user daemon-reload
systemctl --user enable --now aseprite-mcp
loginctl enable-linger "$USER"
```

After you update the code, restart it with `systemctl --user restart aseprite-mcp`. Aseprite reconnects by itself. Read the daemon's log with `journalctl --user -u aseprite-mcp`.

The daemon needs a running Aseprite, and Aseprite needs a desktop session. On a machine that runs unattended, turn on automatic login for your desktop, and start Aseprite at login: copy its desktop entry with `cp /usr/share/applications/aseprite.desktop ~/.config/autostart/`.

The first time the extension connects, Aseprite asks whether the script may open a network connection. Answer it once at the desktop and give the script full trust. Aseprite saves the answer in `~/.config/aseprite/aseprite.ini`, so later starts connect without asking.

### Settings

Set these environment variables for the daemon.

| Variable | Default |
| --- | --- |
| `ASEPRITE_MCP_HTTP_HOST` | `127.0.0.1` (`0.0.0.0` with `serve --remote`) |
| `ASEPRITE_MCP_HTTP_PORT` | `9124` |
| `ASEPRITE_MCP_PORT` | `9123` (WebSocket port for the extension) |
| `ASEPRITE_MCP_TIMEOUT` | `15000` ms per command (at least 60000 for snapshot and commit) |
| `ASEPRITE_MCP_TOKEN` | Token file |
| `ASEPRITE_MCP_TOKEN_FILE` | `~/.config/aseprite-mcp/token` |
| `ASEPRITE_MCP_REMOTE_TOKEN` | Remote token file (only used with `--remote`, non-loopback `ASEPRITE_MCP_HTTP_HOST`, or when set) |
| `ASEPRITE_MCP_REMOTE_TOKEN_FILE` | `~/.config/aseprite-mcp/remote-token` |
| `ASEPRITE_MCP_PALETTE_FILE` | `~/.config/aseprite-mcp/palettes.json` |
| `ASEPRITE_MCP_LIB_DIR` | `~/.config/aseprite-mcp/lib`, where `lib(name, code)` saves helper code |
| `ASEPRITE_MCP_SPRITES_DIR` | `~/Pictures/aseprite-mcp`, where `s.save("name")` writes |
| `ASEPRITE_MCP_FILE_DIRS` | The sprites folder and the temporary directories |
| `ASEPRITE_MCP_VIEWS_DIR` | The user cache directory |
| `ASEPRITE_MCP_AUTOSAVE` | `~/.config/aseprite-mcp/autosave`, or `off` |
| `ASEPRITE_MCP_AUTOSAVE_KEEP` | `5` copies per sprite |
| `ASEPRITE_MCP_AUTOSAVE_DAYS` | `14` |
| `ASEPRITE_MCP_AUTOSAVE_MB` | `200` |
| `ASEPRITE_MCP_TAILNET_HOST` | From `tailscale status` with `serve --tailscale`; otherwise no tailnet access |
| `ASEPRITE_MCP_TAILNET_USERS` | The machine's owner with `serve --tailscale`; otherwise no tailnet access |

## The program API

The agent calls `execute` with a JavaScript program. Coordinates are 0-based, with (0,0) at the top left.

Globals:

```text
sprite(o?: { new?: [w, h]; colorMode?: "rgb"|"indexed"|"gray"; open?: path; id?: number; name?: string }): Promise<Sprite>
sprites(): Promise<{ id, name, width, height, frames, active }[]>
image(path): Promise<Image>
ramp(base: string, keys: string, o?: { hueShift?: number }): Record<string, string>
palette(name, colors?): Promise<Record<string, string>>
lib(name?, code?): Promise<string[] | string>
use(name): void
help(topic?): string
```

- `sprite()` with no arguments returns the active sprite.
- `ramp` makes OKLCH shades, dark to light, one per key.
- `palette` loads a named palette, or saves it when you pass colors.
- `image` loads a PNG as pixels. See [Sprite sheets, GIFs and reference images](#sprite-sheets-gifs-and-reference-images).
- `lib` saves, reads or lists helper code. See [Saved helper code](#saved-helper-code).
- `help` has the topics `maps`, `animation`, `critique`, `conflicts`, `files`, `export` and `lib`.

A `Sprite` has `layers()`, `frames()`, `selection()`, `cel(layer, frame)`, `cels(layer)`, `layer(name, opts)`, `setFrames(count, opts)`, `tag(name, from, to, opts)`, `view(opts)`, `resize(width, height, opts)`, `commit(label)`, `undo(n)`, `redo(n)`, `changes()`, `save(path)` and `export(name, opts)`.

A `Cel` has `map`, `px`, `line`, `rect`, `ellipse`, `fill`, `outline`, `shift`, `copy`, `recolor`, `clear`, `read` and `bounds`. Drawing methods return the number of pixels changed. `bounds()` returns `[x, y, w, h]` of the non-transparent pixels, or `null` for an empty cel.

Colors are `"#rgb"`, `"#rrggbb"` or `"#rrggbbaa"`. A pixel map uses a palette of one-character keys and one string per row:

```js
const s = await sprite({ new: [32, 32] });
const P = { k: "#1a1c2c", ...ramp("#b13e53", "rst") };
const c = s.cel("Layer 1");
c.ellipse([8, 8, 16, 16], P.s, { fill: true });
c.map(P, ["..tt", ".tsst"], { x: 12, y: 10 });
c.outline();
return await s.view({ critique: true });
```

Rules:

- Edits go to a draft. When the program returns, each touched sprite commits as one undo step labeled `MCP: program`.
- A throw or a timeout commits nothing. Call `await s.commit("label")` for a checkpoint that survives a later throw.
- Do not loop over single pixels in JavaScript. Use `map`, `rect`, `fill` and `shift`.
- Return only what you need, such as counts or a few rows.
- `view()` writes a PNG and returns its path. With `critique: true`, the image shows color, grayscale values, silhouette and true size. `background: "#080707"` draws that color instead of the checkerboard.
- Pixels that a drawing call puts outside the canvas are dropped. The result's `warnings` list each such call once, for example `map on "body"@0 dropped 12 pixels outside the 48x48 canvas`.
- `s.resize(64, 64, { x, y })` changes the canvas size, not the scale of the art. The art moves by `(x, y)`. By default it stays at the bottom center, so a figure on a baseline stays on it. `resize` returns a handle with the new `width` and `height`, and it commits in the same undo step as the other edits. It needs extension 0.2.0 or later.

### Saved helper code

`lib(name, code)` saves JavaScript helpers to `~/.config/aseprite-mcp/lib/<name>.js`. A later program loads them with a top-level `use("name")` statement. Before the program runs, the daemon puts each used library in front of it, dependencies first, so the functions it declares are in scope.

```js
await lib(
  "style",
  'use("base")\nfunction blob(c, x, y) { c.rect([x, y, 4, 4], INK, { fill: true }) }'
);
// next program:
use("style");
const s = await sprite({ new: [48, 48] });
blob(s.cel("Layer 1"), 10, 10);
```

- `lib(name)` returns the source and `lib()` lists the names. A name has 1 to 40 characters from `a-z`, `0-9`, `_` and `-`.
- The daemon parses the code before it saves it. A syntax error names the line, and nothing is saved.
- A library can `use` other libraries. A missing library or a cycle fails before the program runs.
- An error inside a library names the library and its line. Lines in the program stay as you wrote them.

### Sprite sheets, GIFs and reference images

`s.export(name, opts)` writes a sprite sheet and an animated GIF for apps and previews. A bare name such as `"slime"` goes to the sprites folder.

```js
const s = await sprite();
return await s.export("slime", { scale: 4, gif: true, columns: 4 });
// { sheet: ".../slime.png", json: ".../slime.json", gif: ".../slime.gif", frames: 8, width: 192, height: 192 }
```

- `slime.png` holds every frame, composited from the visible layers and scaled up by `scale` with nearest-neighbor sampling. Frames run left to right; `columns` wraps them into a grid.
- `slime.json` gives each frame's `x`, `y`, `w`, `h` and `duration` in milliseconds, the tags with `from`, `to` and `direction`, the sheet `size` and the `scale`.
- `slime.gif` loops and keeps the frame durations. It has one transparent color and at most 255 other colors.
- `tag: "idle"` exports only that tag's frames. `sheet: false` writes only the GIF.

`image(path)` loads a PNG, such as a reference drawing, as pixels. It returns `{ image, width, height }` with `read(opts)`, `colors(max)` and `downscale(factor)`. `downscale(4)` turns art drawn at 4x back into one pixel per block. To paste it into a cel, pass the handle (or `{ image: ref.image }`): `c.copy(ref, { x: 8, y: 8 })`. The decoder reads 8-bit PNGs and palette PNGs; it refuses interlaced and 16-bit files.

## Safety

- The daemon listens on loopback addresses only (`127.0.0.1`) by default. With `serve --tailscale`, it also accepts requests that `tailscale serve` forwards for the allowed Tailscale users. With `serve --remote` (or a non-loopback `ASEPRITE_MCP_HTTP_HOST`), it requires `Authorization: Bearer <token>` from remote callers, rejects cross-site browser requests, and keeps `/shutdown` loopback-only.
- Aseprite and the daemon pair with a shared token. Each side proves it knows the token with an HMAC-SHA256 exchange, and the extension checks the server too. The token never crosses the connection, unpaired WebSocket messages are capped at 64 KiB, and browser origins are rejected on the extension socket.
- A program can read and write files only inside the allowed folders: by default `~/Pictures/aseprite-mcp` and the temporary directories. Set `ASEPRITE_MCP_FILE_DIRS` to change it.
- Each program runs in a sandboxed interpreter (`psychoscript`). Defaults: 60 seconds, 64,000 bytes of output and a 64 MB draft.
- The daemon saves backup copies after each commit and removes old ones by count, age and size.

See [DISCLAIMER.md](DISCLAIMER.md).

## Undo and conflicts

Each program is one undo step in Aseprite. Press Ctrl+Z (Cmd+Z on macOS) to undo the whole program.

The program edits a private draft of the sprite. At commit, the daemon compares each cel it wrote with what Aseprite holds now. If you changed the same cel meanwhile, the daemon merges both edits. Where you both changed the same pixel, your edit wins. The commit result reports `merged` cels and `lost` pixels. After three failed retries, the commit fails and the agent runs the program again.

`s.changes()` lists what you drew since the agent last looked. Use `s.selection()` or `rect: "selection"` for "this part".

## Development

The code is TypeScript that Node and Bun run directly; there is no build step for the server.

```sh
npm install
npm test             # node --test
npm run typecheck    # tsc, type check only
npm run check        # Ultracite: oxlint and oxfmt
npm run fix          # apply safe fixes, then rerun the tests
```

`node --test` also runs `test/aseprite.test.ts`. It runs `test/aseprite-handlers.lua` in a real Aseprite in batch mode, and it skips when it cannot find the app. Set `ASEPRITE=/path/to/aseprite` to point to the binary.

`npm run build` writes `dist/aseprite-mcp.aseprite-extension` (currently extension `0.3.0`).

The icon and banner in `assets/` come from `scripts/art.lua`. To draw them again, run `aseprite -b --script scripts/art.lua`. It writes the `.aseprite` sources, scaled PNGs and the animated banner GIF.

### Architecture

See [GLOSSARY.md](GLOSSARY.md) for the domain terms used across the codebase.

| Path | Responsibility |
| --- | --- |
| `bin/aseprite-mcp.ts` | CLI (`serve`, `token`, `status`, `stop`, and stdio MCP proxy) |
| `src/daemon.ts` | HTTP MCP server, loopback/tailnet/remote bearer auth, and `/health` + `/shutdown` |
| `src/program.ts` | `psychoscript` sandbox runtime and the `execute` tool API |
| `src/session.ts` | Sprite Session over `Link` (drafts, diffs, compare-and-swap commits, conflict merges, artist changes) |
| `src/link.ts`, `src/wire.ts` | Authenticated WebSocket transport and binary frame protocol |
| `src/render.ts`, `src/codecs.ts` | Compositing, Views, Critique Sheets, sprite sheet/GIF export, and PNG/GIF codecs |
| `src/raster.ts`, `src/color.ts` | Native pixel drawing operations and OKLCH/hex color math |
| `src/files.ts`, `src/library.ts` | Injectable `Workspace` storage (path sandboxing, tokens, views, backups, palettes) and saved libraries |
| `src/tailnet.ts` | Tailscale Serve integration and LAN/tailnet address discovery |
| `extension/` | Aseprite Lua plugin (`0.3.0`) |

## License

Public domain under [the Unlicense](LICENSE). Use, copy, change and sell it for any purpose, with no conditions and no attribution needed.

TDQS

A4.4/5.0

Scored across 1 tool

Disambiguation5/5

There is only one tool, so there is no possibility of misselection between tools. The single entry point cleanly routes all capability through a documented JavaScript API.

Naming Consistency4/5

With a single tool there is no pattern to violate, so consistency is trivially satisfied. The name 'execute' is generic and doesn't convey the pixel-art domain, though the description compensates immediately.

Tool Count3/5

A single tool is a deliberate design choice here — it exposes an entire scripting API (sprite, cel, palette, export, help) rather than a thin capability. Still, one tool is on the thin side and offers no discoverability of operations without reading a long description.

Completeness4/5

The surface covers creation, layers, frames, tags, drawing primitives, palettes, libraries, view/critique, save/export, and undo/redo — a genuinely broad lifecycle. Minor gaps exist, such as no way to set the selection (only read it) and no explicit tilemap or slice operations.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues