Skip to main content
Glama

generate_sprite

Create game sprites from text descriptions using AI, with customizable styles like pixel art and hand-painted, and control over dimensions and generation parameters.

Instructions

Generate a single game sprite from a text description.

Args:
    prompt: Description of the sprite to generate (e.g., "a blue slime monster")
    preset: Style preset to use (default, pixel_16, pixel_32, flat_ui, handpainted, etc.)
    width: Override width in pixels
    height: Override height in pixels
    negative_prompt: Additional things to avoid (appended to preset's negative prompt)
    seed: Random seed for reproducibility
    steps: Number of generation steps (more = higher quality but slower)
    save_to_file: Whether to save the image to disk
    filename: Custom filename (auto-generated if not provided)

Returns:
    JSON with base64 image data and metadata

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
promptYes
presetNodefault
widthNo
heightNo
negative_promptNo
seedNo
stepsNo
save_to_fileNo
filenameNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The complete handler function for the 'generate_sprite' tool. It is registered via the @mcp.tool() decorator. The function generates a sprite image using the backend (ComfyUI or mock), applies preset configurations, handles resizing, error handling, and optional file saving. The input schema is defined by the function parameters and docstring.
    @mcp.tool()
    async def generate_sprite(
        prompt: str,
        preset: str = "default",
        width: Optional[int] = None,
        height: Optional[int] = None,
        negative_prompt: Optional[str] = None,
        seed: Optional[int] = None,
        steps: Optional[int] = None,
        save_to_file: bool = False,
        filename: Optional[str] = None
    ) -> str:
        """Generate a single game sprite from a text description.
        
        Args:
            prompt: Description of the sprite to generate (e.g., "a blue slime monster")
            preset: Style preset to use (default, pixel_16, pixel_32, flat_ui, handpainted, etc.)
            width: Override width in pixels
            height: Override height in pixels
            negative_prompt: Additional things to avoid (appended to preset's negative prompt)
            seed: Random seed for reproducibility
            steps: Number of generation steps (more = higher quality but slower)
            save_to_file: Whether to save the image to disk
            filename: Custom filename (auto-generated if not provided)
        
        Returns:
            JSON with base64 image data and metadata
        """
        try:
            preset_config = get_preset(preset)
            
            # Build full prompt
            full_prompt = f"{preset_config.prompt_prefix}{prompt}{preset_config.prompt_suffix}"
            full_negative = preset_config.negative_prompt
            if negative_prompt:
                full_negative = f"{full_negative}, {negative_prompt}"
            
            # Use preset defaults or overrides
            img_width = width or preset_config.default_width
            img_height = height or preset_config.default_height
            gen_steps = steps or preset_config.steps
            
            render_width = img_width
            render_height = img_height
            should_downscale = (img_width < preset_config.default_width) or (img_height < preset_config.default_height)
            if should_downscale:
                render_width = preset_config.default_width
                render_height = preset_config.default_height
            
            
            # Generate image with timeout
            image_bytes = await asyncio.wait_for(
                backend.generate_image(
                    prompt=full_prompt,
                    negative_prompt=full_negative,
                    width=render_width,
                    height=render_height,
                    seed=seed,
                    steps=gen_steps,
                    cfg_scale=preset_config.cfg_scale,
                    sampler=preset_config.sampler,
                    scheduler=preset_config.scheduler
                ),
                timeout=300.0  # 5 minute timeout
            )
            
            
            if should_downscale:
                resample = Image.Resampling.NEAREST if preset.startswith("pixel") else Image.Resampling.LANCZOS
                image_bytes = resize_image(image_bytes, img_width, img_height, resample=resample)
            
            result = {
                "success": True,
                "backend": backend.get_name(),
                "backend_type": BACKEND_TYPE,
                "image_base64": image_to_base64(image_bytes),
                "width": img_width,
                "height": img_height,
                "preset": preset,
                "prompt": full_prompt,
                "hash": hash_image(image_bytes)
            }
            
            # Save to file if requested
            if save_to_file:
                output_dir = ensure_directory(OUTPUT_DIR / "sprites")
                fname = filename or generate_filename(prefix="sprite", suffix=preset)
                file_path = output_dir / fname
                file_path.write_bytes(image_bytes)
                result["file_path"] = str(file_path)
            
            return json.dumps(result, indent=2)
            
        except asyncio.TimeoutError:
            return json.dumps({
                "success": False,
                "error": "Generation timed out after 5 minutes",
                "backend": backend.get_name(),
                "backend_type": BACKEND_TYPE
            }, indent=2)
        except Exception as e:
            return json.dumps({
                "success": False,
                "error": str(e),
                "backend": backend.get_name(),
                "backend_type": BACKEND_TYPE
            }, indent=2)
  • server/main.py:109-109 (registration)
    The @mcp.tool() decorator registers the generate_sprite function as an MCP tool.
    @mcp.tool()
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. While it mentions quality/speed tradeoffs for 'steps' and that images can be saved to disk, it lacks critical information about permissions, rate limits, computational requirements, or what happens when save_to_file is false. For a complex generation tool with 9 parameters, this is insufficient.

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 with clear sections (purpose, args, returns) and uses bullet-like formatting. Every sentence adds value, though the parameter explanations could be slightly more concise. It's appropriately sized for a tool with 9 parameters.

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

Completeness4/5

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

Given the tool's complexity (9 parameters, generation functionality) and the presence of an output schema (which handles return values), the description is mostly complete. It thoroughly documents parameters and states the return format. However, it lacks behavioral context about computational requirements or limitations that would be important for a generation tool.

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

Parameters5/5

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

The description provides excellent parameter semantics beyond the 0% schema description coverage. It explains each parameter's purpose with examples (e.g., 'a blue slime monster' for prompt), lists preset options, clarifies that width/height are overrides, explains negative_prompt behavior, defines seed for reproducibility, describes the steps tradeoff, and explains save_to_file and filename behavior. This fully compensates for the schema's lack of descriptions.

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: 'Generate a single game sprite from a text description.' It specifies the verb ('generate'), resource ('single game sprite'), and input type ('text description'), distinguishing it from siblings like generate_tileset or generate_character_animations.

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?

No guidance is provided on when to use this tool versus alternatives like generate_character, generate_tileset, or batch_generate. The description only states what the tool does, not when it's appropriate compared to other sprite-generation tools in the server.

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