像素艺术编辑桥接服务

一个基于Rust的MCP服务器,桥接AI助手(如Claude、GPT等)与Aseprite像素艺术编辑器,实现通过自然语言指令创建、编辑和导出像素艺术精灵和动画。

  • by Dizzd
  • Rust
  • 本地部署
  • 7 星标
  • 更新于
在 GitHub 查看 Dizzd/aseprite_mcp

使用说明

Asprite MCP服务器

A. 模型上下文协议(MCP)服务器 用Rust编写,将AI助手(Claude、GPT等)与 像素精灵 像素艺术编辑器。这允许AI通过自然语言指令创建、编辑和导出像素艺术精灵和动画。

特性

44个MCP工具用于完全无菌控制

类别 工具 描述
(传说中的)精灵 create_sprite, get_sprite_info, resize_sprite, crop_sprite, flip_sprite, rotate_sprite, canvas_size, duplicate_sprite, auto_crop_sprite, change_color_mode, reverse_frames 创建、检查、转换、复制和优化精灵
图层 list_layers, add_layer, remove_layer, set_layer_property, duplicate_layer, merge_down_layer, flatten_layers 具有复制、合并和展平功能的全层管理
框架 list_frames, add_frame, remove_frame, set_frame_duration 动画帧管理
标签 list_tags, create_tag, delete_tag 动画标签/序列管理
切片 list_slices, create_slice, delete_slice 游戏引擎的命名区域:hitbox、9片UI、枢轴点
摄氏度 list_cels, move_cel, set_cel_opacity, clear_cel, new_cel 动画的细粒度cel(层×帧)管理
绘图 draw_pixels, use_tool, get_pixel_data 使用所有Aseprite工具进行像素级绘图和读取
调色板 get_palette, set_palette_color, resize_palette, load_palette, save_palette, color_quantization 具有加载/保存和自动量化功能的全调色板管理
选择 select_region, deselect, select_all, invert_selection, select_by_color 高级选择操作,包括基于颜色的选择
出口 export_sprite, export_spritesheet 导出为多种格式,并使用JSON元数据创建精灵表
效果 replace_color, outline 颜色替换和轮廓效果
过滤器 brightness_contrast, hue_saturation, invert_color, despeckle 用于颜色调整和降噪的图像滤镜
高级 run_lua_script, execute_cli 直接Lua脚本和CLI访问

建筑

┌─────────────┐     stdio (MCP)     ┌──────────────────┐     CLI      ┌──────────┐
│ AI Assistant │◄──────────────────►│ aseprite_mcp     │────────────►│ Aseprite │
│ (Claude etc) │                    │ (Rust MCP Server) │  Lua scripts │ (batch)  │
└─────────────┘                    └──────────────────┘             └──────────┘

服务器通过stdio上的MCP协议与AI助手通信,并通过以下方式控制Aseprite:

  1. 基于工具参数动态生成Lua脚本
  2. 通过以下方式执行它们 aseprite --batch --script script.lua
  3. 解析Aseprite标准输出的JSON输出
  4. 将结构化结果返回给AI助手

安装

先决条件

  • 锈 (1.85+,支持2024版)
  • 像素精灵 安装在您的系统上

构建

cargo build --release

二进制文件将位于 target/release/aseprite_mcp.exe (Windows)或 target/release/aseprite_mcp (Linux/macOS)。

配置优先级路径

服务器会自动在常见位置搜索Aseprite:

  • 视窗: C:\Program Files\Aseprite\Aseprite.exe,蒸汽路径
  • macOS: /Applications/Aseprite.app/Contents/MacOS/aseprite
  • Linux:路径,蒸汽路径

要指定自定义路径,请设置 ASEPRITE_PATH 环境变量:

export ASEPRITE_PATH="/path/to/aseprite"

MCP客户端配置

克劳德桌面版

添加到您的 claude_desktop_config.json:

{
  "mcpServers": {
    "aseprite": {
      "command": "path/to/aseprite_mcp.exe",
      "env": {
        "ASEPRITE_PATH": "C:\\Program Files\\Aseprite\\Aseprite.exe"
      }
    }
  }
}

VS代码(副本)

添加到您的 .vscode/mcp.json:

{
  "servers": {
    "aseprite": {
      "type": "stdio",
      "command": "path/to/aseprite_mcp.exe",
      "env": {
        "ASEPRITE_PATH": "C:\\Program Files\\Aseprite\\Aseprite.exe"
      }
    }
  }
}

光标

添加到光标MCP设置中:

{
  "mcpServers": {
    "aseprite": {
      "command": "path/to/aseprite_mcp.exe",
      "env": {
        "ASEPRITE_PATH": "C:\\Program Files\\Aseprite\\Aseprite.exe"
      }
    }
  }
}

工具示例

创建一个Sprite

Create a 64x64 pixel art sprite with indexed color mode and save it as player.aseprite

工具调用: create_sprite(width=64, height=64, output_path="player.aseprite", color_mode="indexed")

绘制像素

Draw a red pixel at (10, 10) and a blue pixel at (20, 20) on the player sprite

工具调用: draw_pixels(file_path="player.aseprite", pixels=[{x:10,y:10,color:"#ff0000"}, {x:20,y:20,color:"#0000ff"}])

使用绘图工具

Draw a yellow line from (0,0) to (63,63) on the player sprite

工具调用: use_tool(file_path="player.aseprite", tool="line", points=[{x:0,y:0},{x:63,y:63}], color="#ffff00")

导出Spritesheet

Export the animation as a spritesheet with JSON data

工具调用: export_spritesheet(file_path="player.aseprite", output_image="sheet.png", output_data="sheet.json", sheet_type="rows", columns=4)

运行自定义Lua脚本

Run a custom script to create a checkerboard pattern

工具调用: run_lua_script(script="...", file_path="player.aseprite")

可用绘图工具

这 use_tool 命令支持所有Aseprite工具:

工具ID 描述
pencil 徒手像素绘图
line 直线
rectangle 矩形轮廓
filled_rectangle 填充矩形
ellipse 椭圆轮廓
filled_ellipse 填充椭圆
paint_bucket 洪水填方
spray 喷雾/喷枪
eraser 擦除像素
contour 绘制轮廓
polygon 绘制多边形

颜色格式

颜色使用十六进制字符串格式:

  • #rrggbb --RGB(例如。, #ff0000 红色)
  • #rrggbbaa --具有α的RGBA(例如。, #ff000080 半透明红色)

WebSocket插件(可选)

为了对正在运行的Aseprite实例进行实时交互控制,中包含了一个可选的WebSocket插件 scripts/aseprite-mcp-plugin/.

安装插件

  1. 复制 scripts/aseprite-mcp-plugin/ 文件夹到您的Aseprite扩展目录:
    • 窗户: %APPDATA%\Aseprite\extensions\
    • macOS: ~/Library/Application Support/Aseprite/extensions/
    • Linux: ~/.config/aseprite/extensions/
  2. 重新启动Aseprite
  3. 首选 Help > MCP Server > Connect to MCP Server

项目结构

aseprite_mcp/
├── Cargo.toml                          # Rust dependencies
├── README.md                           # This file
├── src/
│   ├── main.rs                         # Entry point, MCP transport setup
│   ├── server.rs                       # MCP server, tool routing & ServerHandler
│   ├── aseprite.rs                     # Aseprite CLI runner (process execution)
│   ├── lua_helpers.rs                  # Reusable Lua snippets (find_layer, etc.)
│   ├── utils.rs                        # Color parsing & validation utilities
│   └── tools/                          # Tool implementations (one file per domain)
│       ├── mod.rs                      # Module re-exports
│       ├── sprite.rs                   # Sprite management (create, info, resize, crop, flip, rotate, canvas, duplicate, auto_crop, color_mode, reverse)
│       ├── layer.rs                    # Layer management (list, add, remove, set properties, duplicate, merge, flatten)
│       ├── frame.rs                    # Frame management (list, add, remove, set duration)
│       ├── tag.rs                      # Animation tag management (list, create, delete)
│       ├── slice.rs                    # Slice management (list, create, delete — 9-slice, pivots, hitboxes)
│       ├── cel.rs                      # Cel management (list, move, opacity, clear, new)
│       ├── drawing.rs                  # Drawing tools (draw_pixels, use_tool, get_pixel_data)
│       ├── palette.rs                  # Palette management (get, set, resize, load, save, quantize)
│       ├── selection.rs                # Selection operations (region, all, invert, by_color, deselect)
│       ├── export.rs                   # Export tools (export_sprite, export_spritesheet)
│       ├── effects.rs                  # Effects (replace_color, outline)
│       ├── filter.rs                   # Image filters (brightness_contrast, hue_saturation, invert, despeckle)
│       └── scripting.rs                # Direct Lua & CLI execution
└── scripts/
    └── aseprite-mcp-plugin/            # Optional Aseprite WebSocket plugin
        ├── package.json
        └── plugin.lua

技术栈

  • 锈 (2024年版)
  • rmcp 0.3--MCP协议框架
  • 东京 --异步运行时
  • Serde/Serde JSON --JSON序列化
  • 追踪 --结构化日志记录

环境变量

变量 描述 默认值
ASEPRITE_PATH Aseprite可执行文件的完整路径 自动检测到
ASEPRITE_OUTPUT_DIR 生成文件的默认输出目录 工作目录
RUST_LOG 日志级别(trace, debug, info, warn, error) info

许可证

麻省理工学院