Skip to main content
Glama

generate_tileset

Create tileable game tiles for specific themes and tile types using AI workflows, supporting style presets and reproducible seeds for consistent asset generation.

Instructions

Generate a set of tileable game tiles.

Args:
    theme: Overall theme for the tileset (e.g., "forest", "dungeon", "sci-fi")
    tile_types: List of tile types to generate (e.g., ["ground", "wall", "water"])
    preset: Style preset to use (default: tileset). Options: tileset, topdown_tile
    tile_size: Size of each tile in pixels (square)
    seed: Base seed for reproducibility (each tile gets seed+index)
    save_to_file: Whether to save images to disk

Returns:
    JSON with base64 images for each tile type

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
themeYes
tile_typesYes
presetNotileset
tile_sizeNo
seedNo
save_to_fileNo

Implementation Reference

  • The complete implementation of the generate_tileset tool handler, including registration via @mcp.tool() decorator. It generates multiple tile images based on theme and types using the AI backend, handles resizing, and returns JSON with base64 images.
    @mcp.tool()
    async def generate_tileset(
        theme: str,
        tile_types: List[str],
        preset: str = "tileset",
        tile_size: int = 32,
        seed: Optional[int] = None,
        save_to_file: bool = False
    ) -> str:
        """Generate a set of tileable game tiles.
        
        Args:
            theme: Overall theme for the tileset (e.g., "forest", "dungeon", "sci-fi")
            tile_types: List of tile types to generate (e.g., ["ground", "wall", "water"])
            preset: Style preset to use (default: tileset). Options: tileset, topdown_tile
            tile_size: Size of each tile in pixels (square)
            seed: Base seed for reproducibility (each tile gets seed+index)
            save_to_file: Whether to save images to disk
        
        Returns:
            JSON with base64 images for each tile type
        """
        if not tile_types:
            return json.dumps({"success": False, "error": "No tile_types provided"}, indent=2)
        
        preset_config = get_preset(preset)
        
        tiles = []
        for i, tile_type in enumerate(tile_types):
            prompt = f"{theme} {tile_type} tile"
            full_prompt = f"{preset_config.prompt_prefix}{prompt}{preset_config.prompt_suffix}"
            gen_seed = (seed + i) if seed is not None else None
     
            render_size = tile_size
            should_downscale = tile_size < min(preset_config.default_width, preset_config.default_height)
            if should_downscale:
                render_size = min(preset_config.default_width, preset_config.default_height)
             
            image_bytes = await backend.generate_image(
                prompt=full_prompt,
                negative_prompt=preset_config.negative_prompt,
                width=render_size,
                height=render_size,
                seed=gen_seed,
                steps=preset_config.steps,
                cfg_scale=preset_config.cfg_scale,
                sampler=preset_config.sampler,
                scheduler=preset_config.scheduler
            )
     
            if should_downscale:
                resample = Image.Resampling.NEAREST if preset.startswith("pixel") else Image.Resampling.LANCZOS
                image_bytes = resize_image(image_bytes, tile_size, tile_size, resample=resample)
            
            tile_data = {
                "index": i,
                "type": tile_type,
                "theme": theme,
                "image_base64": image_to_base64(image_bytes),
                "size": tile_size
            }
            
            if save_to_file:
                output_dir = ensure_directory(OUTPUT_DIR / "tiles" / theme)
                fname = generate_filename(prefix=f"tile_{tile_type}")
                file_path = output_dir / fname
                file_path.write_bytes(image_bytes)
                tile_data["file_path"] = str(file_path)
            
            tiles.append(tile_data)
        
        return json.dumps({
            "success": True,
            "theme": theme,
            "tile_size": tile_size,
            "count": len(tiles),
            "tiles": tiles
        }, indent=2)

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