Skip to main content
Glama

create_sprite_atlas

Combine multiple images into a single sprite atlas or spritesheet for game development. Specify columns, padding, and save options to organize assets efficiently.

Instructions

Combine multiple images into a sprite atlas/spritesheet.

Args:
    images_base64: List of base64 encoded images
    columns: Number of columns in the atlas
    padding: Padding between sprites in pixels
    save_to_file: Whether to save atlas to disk
    filename: Custom filename for the atlas

Returns:
    JSON with the combined atlas as base64

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
images_base64Yes
columnsNo
paddingNo
save_to_fileNo
filenameNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The primary handler function for the 'create_sprite_atlas' MCP tool. It decodes input base64 images, calls the create_spritesheet helper to generate the atlas, encodes it back to base64, and returns a JSON response. Also handles optional file saving. The @mcp.tool() decorator registers it with the MCP server.
    @mcp.tool()
    async def create_sprite_atlas(
        images_base64: List[str],
        columns: int = 4,
        padding: int = 0,
        save_to_file: bool = False,
        filename: Optional[str] = None
    ) -> str:
        """Combine multiple images into a sprite atlas/spritesheet.
        
        Args:
            images_base64: List of base64 encoded images
            columns: Number of columns in the atlas
            padding: Padding between sprites in pixels
            save_to_file: Whether to save atlas to disk
            filename: Custom filename for the atlas
        
        Returns:
            JSON with the combined atlas as base64
        """
        import base64
        images = [base64.b64decode(img) for img in images_base64]
        
        atlas_bytes = create_spritesheet(images, columns=columns, padding=padding)
        
        result = {
            "success": True,
            "image_base64": image_to_base64(atlas_bytes),
            "sprite_count": len(images),
            "columns": columns
        }
        
        if save_to_file:
            output_dir = ensure_directory(OUTPUT_DIR / "atlases")
            fname = filename or generate_filename(prefix="atlas")
            file_path = output_dir / fname
            file_path.write_bytes(atlas_bytes)
            result["file_path"] = str(file_path)
        
        return json.dumps(result, indent=2)
  • Supporting utility function that implements the core spritesheet creation logic using PIL. Arranges input images in a grid layout with optional padding and returns the combined PNG bytes. Called by the tool handler.
    def create_spritesheet(
        images: List[bytes],
        columns: int = 4,
        padding: int = 0
    ) -> bytes:
        """Create a spritesheet from multiple images."""
        if not images:
            raise ValueError("No images provided")
        
        # Load all images
        pil_images = [Image.open(BytesIO(img)) for img in images]
        
        # Get dimensions (assume all same size)
        sprite_width = pil_images[0].width
        sprite_height = pil_images[0].height
        
        # Calculate sheet dimensions
        rows = (len(pil_images) + columns - 1) // columns
        sheet_width = columns * sprite_width + (columns - 1) * padding
        sheet_height = rows * sprite_height + (rows - 1) * padding
        
        # Create spritesheet
        sheet = Image.new("RGBA", (sheet_width, sheet_height), (0, 0, 0, 0))
        
        for i, img in enumerate(pil_images):
            row = i // columns
            col = i % columns
            x = col * (sprite_width + padding)
            y = row * (sprite_height + padding)
            sheet.paste(img, (x, y))
        
        buffer = BytesIO()
        sheet.save(buffer, format="PNG")
        return buffer.getvalue()
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions the return format ('JSON with the combined atlas as base64') and the optional file-saving behavior, but lacks critical details like whether this is a read-only or destructive operation, performance characteristics, error conditions, or what happens when 'save_to_file' is true without a filename. The description provides basic output information but misses important behavioral context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured and appropriately sized, with a clear purpose statement followed by organized parameter and return sections. Every sentence adds value, though the 'Args:' and 'Returns:' labels could be more integrated with the natural language flow. It efficiently communicates essential information without redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given 5 parameters with 0% schema coverage and no annotations, the description does a reasonable job explaining parameters and the return format (aided by the output schema). However, as a tool that creates new assets, it lacks important context about side effects, file system interactions when saving, and how the atlas is structured. The presence of an output schema helps, but behavioral gaps remain.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds significant semantic value beyond the input schema, which has 0% description coverage. It explains what each parameter means ('base64 encoded images', 'columns in the atlas', 'padding between sprites', 'save atlas to disk', 'custom filename'), providing context that the schema's bare titles lack. While it doesn't specify format details or constraints, it meaningfully clarifies parameter purposes.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with specific verb ('combine') and resource ('multiple images into a sprite atlas/spritesheet'), distinguishing it from sibling tools like 'generate_sprite' or 'process_image' which handle different image operations. It immediately communicates the core transformation function without ambiguity.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. While it's clear what the tool does, there's no mention of prerequisites, when to choose this over similar tools like 'generate_tileset' or 'batch_generate', or any context about appropriate use cases. The agent must infer usage from the purpose alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/tuannguyen14/ComfyAI-MCP-GameAssets'

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