execute
Run JavaScript programs in Aseprite to create sprites, draw pixel art, animate frames, and export sheets or GIFs, with each program committed as one undo step.
Instructions
Draw pixel art live in the user's Aseprite by running a JavaScript program. Coordinates are 0-based, (0,0) top-left; frames are 0-based.
Globals: sprite(o?: { new?: [w, h]; colorMode?: "rgb"|"indexed"|"gray"; open?: path; id?: number; name?: string }): Promise // no args = the active sprite sprites(): Promise<{ id, name, width, height, frames, active }[]> image(path): Promise // load a PNG reference: Image { image, width, height, read(o?), colors(max = 32), downscale(factor) } ramp(base: string, keys: string, o?: { hueShift?: number }): Record<string, string> // OKLCH shades, dark to light, one per key palette(name, colors?): Promise<Record<string, string>> // load, or save with colors, a named palette lib(name?, code?): Promise<string[] | string> // save helper code: lib(name, code); read: lib(name); list: lib() use(name): void // top-level use("style") puts a saved library's functions in scope; see help("lib") help(topic?): string // topics: maps, animation, critique, conflicts, files, export, lib
Sprite { id, name, width, height, colorMode layers(): string[] // paths, bottom to top; "group/child" frames(): number; selection(): Rect | null cel(layer, frame = 0): Cel; cels(layer): Cel[] // one per frame layer(name, o?: { below?, visible?, opacity? (0-255), rename?, remove? }): void // unknown name = new layer setFrames(count, o?: { duration?: ms | ms[] }): void // new frames copy the last frame tag(name, from, to, o?: { direction?: "forward"|"reverse"|"pingpong" }): void view(o?: { frame?: number | "all"; rect?: Rect; scale?: number; critique?: boolean; background?: "#080707" }): Promise<{ path, width, height }> // background replaces the checkerboard resize(w, h, o?: { x?, y? }): Sprite // canvas size, not scale; art moves by (x, y), default bottom-centred; use the returned handle commit(label?): Promise<{ label, cels, pixels, merged, lost }> // checkpoint now undo(n = 1): Promise; redo(n = 1): Promise changes(): Promise<{ layer, frame, rect, palette, rows }[]> // the artist's edits since you last looked save(nameOrPath?): Promise // save("slime") -> ~/Pictures/aseprite-mcp/slime.aseprite export(name, o?: { scale?, tag?, sheet? = true, gif?, columns? }): Promise<{ sheet?, json?, gif?, frames, width, height }> } // sprite sheet PNG + JSON, GIF Cel { layer, frame map(palette, rows, o?: { x?, y?, flip?: "h"|"v"|"hv" }): number // one char per pixel; "." and " " skip; "#00000000" erases px(points: [x, y, color][]): number; line(x0, y0, x1, y1, color): number rect(r, color, o?: { fill? }): number; ellipse(r, color, o?: { fill? }): number; fill(x, y, color): number outline(color?, o?: { mode?: "selective"|"outside"|"inside"; rect? }): number // selective needs no colour shift(dx, dy, o?: { rect? }): number copy(from: { layer, frame?, sprite? } | { image: img.image }, o?: { rect?, x?, y?, flip? }): number // not the handle itself recolor(map: { "#from": "#to" }, o?: { rect? }): number; clear(r?): number bounds(): Rect | null // [x, y, w, h] of the non-transparent pixels; null when empty read(o?: { rect?; palette? }): { palette, rows } } // same format as map; pass your palette to keep its keys Rect = [x, y, w, h] | "selection". Colours are "#rgb", "#rrggbb" or "#rrggbbaa". Drawing methods return pixels changed.
Rules:
Edits go to a draft. When the program returns, each touched sprite commits as ONE undo step ("MCP: program").
A throw or timeout commits nothing; the result lists the discarded cels. await s.commit("label") is a checkpoint that survives a later throw.
Pixel loops belong in methods: map/rect/fill/shift run natively; a JS loop per pixel is slow.
Return only what you need (counts, a few rows), never whole sprites or handles.
view() writes a PNG and returns its path; open the file to look. Use critique: true to judge colour, values and silhouette in one image.
The result's warnings name each drawing call that dropped pixels outside the canvas; move the art or s.resize().
The result's commit list reports merged and lost: if the artist drew on the same cels meanwhile, both edits are kept and the artist wins where you overlap.
Example: 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 })
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"code": "<code>"
},
"name": "execute"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | JavaScript program body; its return value becomes `value`. |