Skip to main content
Glama

edit_level_row

Replace an entire row of tiles in a VibeTide 2D platformer level by specifying the row index and new tile configuration.

Instructions

Edit an entire row in a VibeTide level.

Args:
    encoded_level: An encoded level string from a URL or sharing link
    row: Row index to replace (0-based, from top)
    new_row_tiles: Array of tile types for the new row (each 0-7)

Returns the modified level data with the entire row replaced.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
encoded_levelYes
rowYes
new_row_tilesYes

Implementation Reference

  • The core handler function for the 'edit_level_row' tool. Decorated with @mcp.tool(), it decodes the input encoded level string, validates the row index and new row tiles array (ensuring correct length and tile types 0-7), replaces the specified row in the 2D tiles array, re-encodes the level, generates an ASCII visualization, computes a play URL, and returns a comprehensive response with the updated level data, encoded string, visualization, and change summary.
    @mcp.tool()
    async def edit_level_row(
        encoded_level: str, row: int, new_row_tiles: List[int]
    ) -> Dict[str, Any]:
        """Edit an entire row in a VibeTide level.
    
        Args:
            encoded_level: An encoded level string from a URL or sharing link
            row: Row index to replace (0-based, from top)
            new_row_tiles: Array of tile types for the new row (each 0-7)
    
        Returns the modified level data with the entire row replaced.
        """
        try:
            # Decode the level first
            try:
                level_data = level_encoder.decode(encoded_level)
            except Exception as e:
                return {
                    "success": False,
                    "error": f"Failed to decode level: {str(e)}",
                }
    
            tiles = level_data["tiles"]
            if not isinstance(tiles, list) or not tiles:
                return {"success": False, "error": "Invalid tiles array"}
    
            height = len(tiles)
            width = len(tiles[0]) if tiles else 0
    
            # Validate row index
            if row < 0 or row >= height:
                return {
                    "success": False,
                    "error": f"Invalid row {row} - must be 0-{height-1}",
                }
    
            # Validate new row tiles
            if not isinstance(new_row_tiles, list):
                return {"success": False, "error": "new_row_tiles must be a list"}
    
            if len(new_row_tiles) != width:
                return {
                    "success": False,
                    "error": f"new_row_tiles length {len(new_row_tiles)} doesn't match level width {width}",
                }
    
            # Validate tile types
            for i, tile_type in enumerate(new_row_tiles):
                if not isinstance(tile_type, int) or tile_type < 0 or tile_type > 7:
                    return {
                        "success": False,
                        "error": f"Invalid tile type {tile_type} at position {i} - must be integer 0-7",
                    }
    
            # Make the edit
            old_row = tiles[row].copy()
            tiles[row] = new_row_tiles.copy()
    
            # Create new level data
            edited_level = level_data.copy()
            edited_level["tiles"] = tiles
    
            # Generate encoded version
            try:
                encoded_level = level_encoder.encode(edited_level)
                play_url = f"{VIBE_TIDE_CONFIG['web_player_url']}?level={encoded_level}"
            except Exception as e:
                logger.warning(f"Failed to encode edited level: {e}")
                encoded_level = None
                play_url = None
    
            # Generate visualization
            visualization = visualize_level(edited_level)
    
            return {
                "success": True,
                "level_data": edited_level,
                "encoded_level": encoded_level,
                "play_url": play_url,
                "visualization": visualization,
                "change_summary": f"Replaced row {row}: {old_row} → {new_row_tiles}",
                "message": f"Successfully edited row {row}",
            }
    
        except Exception as e:
            logger.error(f"Failed to edit level row: {e}")
            return {"success": False, "error": f"Failed to edit level row: {str(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/banjtheman/vibe_tide_mcp'

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