Skip to main content
Glama
ext-sakamoro

Aseprite MCP Tools

by ext-sakamoro

create_palette

Create or replace color palettes in Aseprite files by specifying hex color codes and optional palette names for pixel art projects.

Instructions

Create or replace a palette in an Aseprite file.

Args: filename: Name of the Aseprite file to modify colors: List of hex color codes (e.g., ["FF0000", "00FF00", "0000FF"]) palette_name: Optional name for the palette

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filenameYes
colorsYes
palette_nameNo

Implementation Reference

  • The main handler function for creating/replacing a palette in an Aseprite file using Lua script generation.
    async def create_palette(
        filename: str,
        colors: List[str],
        palette_name: Optional[str] = None
    ) -> str:
        """Create or replace a palette in an Aseprite file.
    
        Args:
            filename: Name of the Aseprite file to modify
            colors: List of hex color codes (e.g., ["FF0000", "00FF00", "0000FF"])
            palette_name: Optional name for the palette
        """
        try:
            # Validate inputs
            file_path = validate_file_path(filename, must_exist=True)
            
            if not colors:
                raise ValidationError("colors", colors, "Color list cannot be empty")
            
            if len(colors) > 256:
                raise ValidationError("colors", len(colors), "Palette cannot have more than 256 colors")
            
            # Validate all colors
            validated_colors = [validate_color(color) for color in colors]
            
            # Build Lua script
            builder = LuaBuilder()
            builder.open_sprite(str(file_path))
            builder.add_line('local spr = app.activeSprite')
            builder.if_condition('not spr')
            builder.add_line('error("No active sprite")')
            builder.end_if()
            builder.add_line()
            
            # Create new palette
            builder.add_line('local palette = Palette(#spr.palettes > 0 and spr.palettes[1] or ' + str(len(validated_colors)) + ')')
            
            # Set colors
            for i, color in enumerate(validated_colors):
                r = int(color[0:2], 16)
                g = int(color[2:4], 16)
                b = int(color[4:6], 16)
                builder.add_line(f'palette:setColor({i}, Color{{r={r}, g={g}, b={b}, a=255}})')
            
            # Resize palette if needed
            builder.if_condition(f'#palette < {len(validated_colors)}')
            builder.add_line(f'palette:resize({len(validated_colors)})')
            builder.end_if()
            
            # Set palette
            builder.add_line('spr:setPalette(palette)')
            
            builder.save_sprite()
            
            # Execute script
            cmd = get_command()
            success, output = cmd.execute_lua_script(builder.build())
            
            return f"Palette with {len(validated_colors)} colors created successfully in {file_path}"
            
        except (ValidationError, AsepriteError) as e:
            return f"Failed to create palette: {e}"
        except Exception as e:
            return f"Unexpected error: {e}"

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ext-sakamoro/AsepriteMCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server