Content
# Aseprite MCP Server
A [Model Context Protocol](https://modelcontextprotocol.io) (MCP) server that exposes [Aseprite](https://www.aseprite.org)'s pixel art capabilities to AI assistants such as Claude. Designed for creating sprites, characters, and backgrounds for 2D games in pixel art style.
## How It Works
The server runs Aseprite in **headless batch mode** — no GUI is needed. For every MCP tool call, it:
1. Generates a Lua script using Aseprite's scripting API
2. Executes `aseprite --batch --script <file>`
3. Returns the result to the MCP client (Claude, etc.)
```
Claude ──tool call──▶ aseprite-mcp ──Lua script──▶ aseprite --batch
◀──result text──────────────────────────
```
## Requirements
- [Go 1.22+](https://go.dev/dl/)
- [Aseprite](https://www.aseprite.org) v1.2.10 or later (must be installed with a valid license)
## Installation
```bash
git clone https://github.com/rfsbsb/aseprite-mcp
cd aseprite-mcp
go build -o aseprite-mcp .
```
## Configuration
| Environment Variable | Default | Description |
|----------------------|------------|-----------------------------------------|
| `ASEPRITE_PATH` | `aseprite` | Full path to the Aseprite binary |
### Locating the Aseprite binary
| Platform | Typical path |
|----------|-------------|
| macOS | `/Applications/Aseprite.app/Contents/MacOS/aseprite` |
| Linux | `/usr/bin/aseprite` or `~/.local/bin/aseprite` |
| Windows | `C:\Program Files\Aseprite\aseprite.exe` |
## Claude Code Integration
Add the server to your Claude Code MCP configuration using the CLI:
```bash
claude mcp add aseprite -- /absolute/path/to/aseprite-mcp
```
To pass the Aseprite binary path as an environment variable:
```bash
claude mcp add aseprite \
-e ASEPRITE_PATH=/Applications/Aseprite.app/Contents/MacOS/aseprite \
-- /absolute/path/to/aseprite-mcp
```
This adds the server to your project-local `.mcp.json`. To add it globally (available in all projects):
```bash
claude mcp add aseprite --scope user \
-e ASEPRITE_PATH=/Applications/Aseprite.app/Contents/MacOS/aseprite \
-- /absolute/path/to/aseprite-mcp
```
### Verifying the connection
In a Claude Code session, ask:
> "What Aseprite tools do you have available?"
Claude will list all 37 tools if the server is running correctly.
## Usage Guide
### Workflow: Creating a game character sprite
This is the recommended workflow for creating a new character sprite for a 2D game:
**Step 1 — Create the canvas**
> "Create a 32x32 RGB sprite and save it to `/sprites/hero.aseprite`"
Typical sizes for pixel art game sprites:
- **8×8** — micro sprites, bullets, small tiles
- **16×16** — characters, items (NES/Game Boy style)
- **32×32** — detailed characters (SNES style)
- **48×48 or 64×64** — large characters / bosses
**Step 2 — Set up layers**
> "Add a layer named 'outline' to `/sprites/hero.aseprite`"
> "Add a layer named 'fill' to `/sprites/hero.aseprite`"
> "Add a layer named 'shadow' to `/sprites/hero.aseprite`"
**Step 3 — Apply a palette**
> "Set the palette for `/sprites/hero.aseprite` to the following colors: `[{"r":34,"g":32,"b":52},{"r":69,"g":40,"b":60},{"r":102,"g":57,"b":49}]`"
**Step 4 — Draw**
> "Draw a filled rectangle at (10,5) size 12x20 on layer 'fill' in `/sprites/hero.aseprite` with color r=102 g=57 b=49"
> "Draw a line from (10,5) to (22,5) on layer 'outline' in `/sprites/hero.aseprite` with color r=34 g=32 b=52"
**Step 5 — Animate**
> "Add 3 more frames to `/sprites/hero.aseprite`"
> "Create an animation tag named 'idle' covering frames 1-2 in `/sprites/hero.aseprite`"
> "Create an animation tag named 'walk' covering frames 3-4 in `/sprites/hero.aseprite`"
**Step 6 — Export**
> "Export `/sprites/hero.aseprite` as a horizontal spritesheet PNG to `/sprites/hero_sheet.png`"
> "Export `/sprites/hero.aseprite` as a GIF to `/sprites/hero_preview.gif`"
---
### Workflow: Creating a tileset / background
> "Create a 128x128 RGB sprite at `/sprites/tileset.aseprite`"
> "Add a layer named 'grass' to `/sprites/tileset.aseprite`"
> "Draw a filled rectangle at (0,0) size 16x16 on layer 'grass' with r=106 g=190 b=48"
> "Export a spritesheet with 8 columns from `/sprites/tileset.aseprite` to `/sprites/tiles.png`"
---
### Workflow: Inspecting an existing sprite
> "Get info for `/sprites/hero.aseprite`"
> "List all layers in `/sprites/hero.aseprite`"
> "List all animation tags in `/sprites/hero.aseprite`"
> "Get the color of the pixel at (5, 10) in `/sprites/hero.aseprite`"
---
### Color format
All colors use RGBA (0–255 per channel). Alpha defaults to 255 (fully opaque).
```
r=255, g=0, b=0, a=255 → opaque red
r=0, g=255, b=0, a=128 → semi-transparent green
r=0, g=0, b=0, a=0 → fully transparent (erase)
```
### Coordinate system
Coordinates are **0-based** from the **top-left** corner of the sprite canvas.
```
(0,0) ──────── (width-1, 0)
│ │
│ │
(0, height-1) ─ (width-1, height-1)
```
### Frame numbering
Frames are **1-based** (first frame = 1). This matches Aseprite's UI display.
---
## Available Tools
### Sprite / Canvas Management
| Tool | Required args | Description |
|------|--------------|-------------|
| `create_sprite` | `width`, `height`, `output_path` | Create a new sprite |
| `open_sprite` | `file_path` | Verify a sprite file is readable |
| `save_sprite` | `file_path` | Save sprite in-place or to new path |
| `save_sprite_copy` | `file_path`, `output_path` | Export copy (no filename change) |
| `get_sprite_info` | `file_path` | Get size, color mode, layer/frame count |
| `resize_sprite` | `file_path`, `width`, `height` | Resize canvas |
| `crop_sprite` | `file_path`, `x`, `y`, `width`, `height` | Crop to rectangle |
| `flatten_layers` | `file_path` | Merge all layers into one |
Optional: `color_mode` (rgb/grayscale/indexed, default: rgb).
### Layer Management
| Tool | Required args | Description |
|------|--------------|-------------|
| `add_layer` | `file_path`, `name` | Add layer (optional: `type`: normal/group) |
| `delete_layer` | `file_path`, `name` | Delete layer by name |
| `set_layer_opacity` | `file_path`, `name`, `opacity` | Opacity 0–255 |
| `set_layer_blend_mode` | `file_path`, `name`, `blend_mode` | See blend modes below |
| `set_layer_visibility` | `file_path`, `name`, `visible` | true/false |
| `get_layers` | `file_path` | List all layers |
Blend modes: `normal`, `multiply`, `screen`, `overlay`, `darken`, `lighten`, `colordodge`, `colorburn`, `hardlight`, `softlight`, `difference`, `exclusion`, `hue`, `saturation`, `color`, `luminosity`, `addition`, `subtract`, `divide`.
### Drawing
| Tool | Required args | Description |
|------|--------------|-------------|
| `draw_pixel` | `file_path`, `x`, `y`, `r`, `g`, `b` | Single pixel |
| `draw_pixels` | `file_path`, `pixels` | Batch pixels as JSON array |
| `draw_line` | `file_path`, `x1`, `y1`, `x2`, `y2`, `r`, `g`, `b` | Bresenham line |
| `draw_rectangle` | `file_path`, `x`, `y`, `width`, `height`, `r`, `g`, `b` | Optional: `filled` |
| `draw_circle` | `file_path`, `x`, `y`, `width`, `height`, `r`, `g`, `b` | Optional: `filled` |
| `fill_area` | `file_path`, `x`, `y`, `r`, `g`, `b` | Flood fill |
| `clear_layer` | `file_path` | Erase entire layer cel |
All drawing tools accept optional: `a` (alpha, default 255), `layer` (name), `frame` (1-based, default 1).
`draw_pixels` format:
```json
[{"x": 0, "y": 0, "r": 255, "g": 0, "b": 0, "a": 255}, ...]
```
### Color & Palette
| Tool | Required args | Description |
|------|--------------|-------------|
| `get_palette` | `file_path` | List all palette colors |
| `set_palette_color` | `file_path`, `index`, `r`, `g`, `b` | Set one entry |
| `set_palette` | `file_path`, `colors` | Replace entire palette (JSON array) |
| `load_palette` | `file_path`, `palette_path` | Load from .ase/.gpl/.png file |
`set_palette` colors format:
```json
[{"r": 0, "g": 0, "b": 0, "a": 255}, {"r": 255, "g": 255, "b": 255}]
```
### Frame & Animation
| Tool | Required args | Description |
|------|--------------|-------------|
| `add_frame` | `file_path` | Add empty frame (optional: `at` position) |
| `duplicate_frame` | `file_path`, `frame` | Copy frame content |
| `delete_frame` | `file_path`, `frame` | Remove frame by index |
| `set_frame_duration` | `file_path`, `frame`, `duration_ms` | Duration in milliseconds |
| `create_tag` | `file_path`, `name`, `from_frame`, `to_frame` | Optional: `ani_dir` |
| `delete_tag` | `file_path`, `name` | Remove tag |
| `get_frames` | `file_path` | List frames with durations |
| `get_tags` | `file_path` | List animation tags |
Animation directions (`ani_dir`): `forward` (default), `reverse`, `pingpong`.
### Selection
| Tool | Required args | Description |
|------|--------------|-------------|
| `select_rectangle` | `file_path`, `x`, `y`, `width`, `height` | Optional: `mode` |
| `select_all` | `file_path` | Select entire canvas |
| `deselect` | `file_path` | Clear selection |
| `invert_selection` | `file_path` | Invert selection |
| `fill_selection` | `file_path`, `r`, `g`, `b` | Fill with color |
Selection modes: `replace` (default), `add`, `subtract`, `intersect`.
### Transform
| Tool | Required args | Description |
|------|--------------|-------------|
| `flip_sprite` | `file_path`, `direction` | `horizontal` or `vertical` |
| `rotate_sprite` | `file_path`, `degrees` | `90`, `180`, or `270` |
| `scale_sprite` | `file_path`, `width`, `height` | Nearest-neighbor (pixel-perfect) |
### Export
| Tool | Required args | Description |
|------|--------------|-------------|
| `export_png` | `file_path`, `output_path` | Optional: `frame` index |
| `export_gif` | `file_path`, `output_path` | Animated GIF |
| `export_spritesheet` | `file_path`, `output_path` | Optional: `layout`, `columns` |
| `export_layer_as_png` | `file_path`, `output_path`, `layer` | Optional: `frame` |
Spritesheet layouts: `horizontal` (default), `vertical`, `packed`.
### Pixel Inspection
| Tool | Required args | Description |
|------|--------------|-------------|
| `get_pixel` | `file_path`, `x`, `y` | RGBA of one pixel |
| `get_pixels_region` | `file_path`, `x`, `y`, `width`, `height` | Region up to 4096 pixels |
---
## Testing
### Unit tests (no Aseprite required)
```bash
go test ./...
```
Runs **61 unit tests** covering:
- Lua script builder (`lua/`)
- Executor temp-file lifecycle and error handling (`executor/`)
- Argument validation helpers — `requireString`, `requireInt`, `optString`, `optInt`, `optBool` (`tools/`)
- Input validation for every tool handler (invalid dimensions, unknown color modes, bad JSON, etc.)
- Pixel art geometry — Bresenham line algorithm and ellipse rasterizer (`tools/`)
### Integration tests (requires Aseprite)
```bash
ASEPRITE_PATH=/Applications/Aseprite.app/Contents/MacOS/aseprite \
go test ./tools/... -run Integration -v
```
Integration tests exercise the full round-trip: create a sprite on disk, modify it, inspect it, and export it. They cover:
| Test | What it validates |
|------|------------------|
| `TestIntegration_CreateSprite` | Sprite file is created on disk |
| `TestIntegration_GetSpriteInfo` | Metadata (size, color mode) round-trips correctly |
| `TestIntegration_AddAndGetLayers` | Layers are persisted and listed |
| `TestIntegration_AnimationTagWorkflow` | Frames added, tag created and listed |
| `TestIntegration_ExportPNG` | PNG file is produced |
| `TestIntegration_DrawPixelAndReadBack` | Pixel color survives write→read |
| `TestIntegration_PaletteRoundTrip` | Palette color survives set→get |
| `TestIntegration_ResizeAndCrop` | Dimensions reflect resize+crop |
| `TestIntegration_FlattenLayers` | Single layer remains after flatten |
| `TestIntegration_BatchPixelsDraw` | Batch pixel draw returns correct count |
Integration tests are automatically **skipped** when `ASEPRITE_PATH` is not set, so they never block CI/CD pipelines without Aseprite.
### Run with coverage
```bash
go test ./... -coverprofile=coverage.out
go tool cover -html=coverage.out
```
---
## Architecture
```
main.go → Entry point: loads config, creates StdioServer, starts Listen
config/config.go → Reads ASEPRITE_PATH env var
executor/
executor.go → Runs Lua scripts via CLI, handles result JSON files
lua/
templates.go → Type-safe Lua script builder (EscapeLua, ColorRGBA, etc.)
server/server.go → Creates MCPServer, registers all tool groups
tools/
sprite.go → Sprite/canvas tools + shared argument helpers
layer.go → Layer management tools
drawing.go → Pixel drawing tools + Bresenham/ellipse algorithms
palette.go → Color palette tools
animation.go → Frame and animation tag tools
selection.go → Selection tools
transform.go → Flip/rotate/scale tools
export.go → PNG/GIF/spritesheet export tools
pixels.go → Pixel read tools
export_test_helpers.go → Exported wrappers for internal functions (test only)
```
## License
MIT
Connection Info
You Might Also Like
No recommendations available