Skip to main content
Glama

view_level

Generate a visual representation of VibeTide 2D platformer levels from encoded strings to preview level layouts and designs.

Instructions

View a VibeTide level with visual representation.

Args:
    encoded_level: An encoded level string from a URL or sharing link

Returns a visual representation of the level.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
encoded_levelYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The @mcp.tool()-decorated async function implementing the core logic of the 'view_level' tool: decodes the input encoded_level using LevelEncoder, generates an ASCII visualization via visualize_level, constructs a play URL, and returns structured level data.
    @mcp.tool()
    async def view_level(encoded_level: str) -> Dict[str, Any]:
        """View a VibeTide level with visual representation.
    
        Args:
            encoded_level: An encoded level string from a URL or sharing link
    
        Returns a visual representation of the level.
        """
        try:
            # Decode level from string
            level_data = level_encoder.decode(encoded_level)
            play_url = f"{VIBE_TIDE_CONFIG['web_player_url']}?level={encoded_level}"
    
            # Generate visualization
            visualization = visualize_level(level_data)
    
            return {
                "success": True,
                "level_data": level_data,
                "visualization": visualization,
                "play_url": play_url,
                "message": "Level visualized successfully",
            }
    
        except Exception as e:
            logger.error(f"Failed to view level: {e}")
            return {"success": False, "error": f"Failed to view level: {str(e)}"}
  • Helper function called by view_level to generate an ASCII art visualization of the level layout using tile symbols, including level info, parameters, layout grid, and legend.
    def visualize_level(level_data: Dict[str, Any]) -> str:
        """Create a visual representation of the level using symbols"""
        tiles = level_data.get("tiles", [])
        if not tiles:
            return "Empty level"
    
        visualization = []
        visualization.append(f"Level: {level_data.get('name', 'Unnamed')}")
        visualization.append(f"Size: {len(tiles[0])}x{len(tiles)}")
    
        # Add game parameters if present
        params = []
        if "maxEnemies" in level_data:
            params.append(f"Max Enemies: {level_data['maxEnemies']}")
        if "enemySpawnChance" in level_data:
            params.append(f"Enemy Spawn: {level_data['enemySpawnChance']}%")
        if "coinSpawnChance" in level_data:
            params.append(f"Coin Spawn: {level_data['coinSpawnChance']}%")
    
        if params:
            visualization.append("Parameters: " + ", ".join(params))
    
        visualization.append("\nLevel Layout:")
        visualization.append("=" * (len(tiles[0]) + 2))
    
        for row in tiles:
            row_str = "|"
            for tile in row:
                symbol = TILE_TYPES.get(tile, {"symbol": "?"})["symbol"]
                row_str += symbol
            row_str += "|"
            visualization.append(row_str)
    
        visualization.append("=" * (len(tiles[0]) + 2))
    
        # Add legend
        visualization.append("\nTile Legend:")
        for tile_id, tile_info in TILE_TYPES.items():
            visualization.append(
                f"  {tile_info['symbol']} = {tile_info['name']} ({tile_info['description']})"
            )
    
        return "\n".join(visualization)
  • The LevelEncoder class provides the decode method used in view_level to parse the encoded_level string into structured level data (tiles, dimensions, etc.). Global instance: level_encoder.
    class LevelEncoder:
        """Fast level encoding/decoding without agent tools"""
    
        def __init__(self):
            # Character mapping for tiles (URL-safe)
            self.tile_chars = {
                0: ".",  # Empty - most common
                1: "G",  # Grass
                2: "R",  # Rock
                3: "Y",  # Yellow
                4: "I",  # Ice
                5: "F",  # Fire/Red
                6: "S",  # Spikes
                7: "W",  # Water
            }
            self.char_tiles = {char: tile for tile, char in self.tile_chars.items()}
    
        def encode(self, level_data: Dict[str, Any]) -> str:
            """Encode level data to URL-safe string"""
            try:
                tiles = level_data.get("tiles", [])
                if not tiles:
                    raise ValueError("No tiles found")
    
                height = len(tiles)
                width = len(tiles[0]) if tiles else 0
    
                # Convert 2D array to character string
                tile_string = ""
                for row in tiles:
                    for tile in row:
                        tile_string += self.tile_chars.get(tile, ".")
    
                # Apply run-length encoding for empty tiles
                tile_string = self._run_length_encode(tile_string)
    
                # Create base format
                encoded = f"{width}x{height}:{tile_string}"
    
                # Add game parameters if provided
                params = {}
                for param in ["maxEnemies", "enemySpawnChance", "coinSpawnChance"]:
                    if param in level_data and level_data[param] is not None:
                        params[param] = level_data[param]
    
                if params:
                    params_json = json.dumps(params)
                    encoded += f"|{self._base64url_encode(params_json)}"
    
                return self._base64url_encode(encoded)
    
            except Exception as e:
                logger.error(f"Failed to encode level: {e}")
                raise ValueError(f"Level encoding failed: {str(e)}")
    
        def decode(self, encoded_string: str) -> Dict[str, Any]:
            """Decode URL-safe string back to level data"""
            try:
                encoded_string = encoded_string.strip()
                if not encoded_string:
                    raise ValueError("Empty encoded string")
    
                # Decode from base64url
                decoded = self._base64url_decode(encoded_string)
    
                # Parse parameters if present
                main_data = decoded
                game_params = {}
    
                if "|" in decoded:
                    parts = decoded.split("|", 1)
                    if len(parts) == 2:
                        main_data, params_data = parts
                        try:
                            params_json = self._base64url_decode(params_data)
                            game_params = json.loads(params_json)
                        except Exception as e:
                            logger.warning(f"Failed to parse parameters: {e}")
    
                # Parse format: widthxheight:encoded_data
                if ":" not in main_data:
                    raise ValueError("Invalid format: missing colon")
    
                dimensions, tile_data = main_data.split(":", 1)
    
                if "x" not in dimensions:
                    raise ValueError("Invalid format: missing dimensions")
    
                width, height = map(int, dimensions.split("x"))
    
                if width < 1 or height < 1:
                    raise ValueError(f"Invalid dimensions: {width}x{height}")
    
                # Decode run-length encoding
                tile_string = self._run_length_decode(tile_data)
    
                # Convert back to 2D array
                tiles = []
                index = 0
    
                for y in range(height):
                    tiles.append([])
                    for x in range(width):
                        char = tile_string[index] if index < len(tile_string) else "."
                        tiles[y].append(self.char_tiles.get(char, 0))
                        index += 1
    
                result = {
                    "tiles": tiles,
                    "width": width,
                    "height": height,
                    "name": self._generate_level_name(tiles),
                }
    
                # Add game parameters
                for param in ["maxEnemies", "enemySpawnChance", "coinSpawnChance"]:
                    if param in game_params:
                        result[param] = game_params[param]
    
                return result
    
            except Exception as e:
                logger.error(f"Failed to decode level: {e}")
                raise ValueError(f"Level decoding failed: {str(e)}")
    
        def _run_length_encode(self, s: str) -> str:
            """Run-length encoding for repeated empty tiles"""
            if not s:
                return s
    
            result = ""
            count = 1
            current = s[0]
    
            for i in range(1, len(s)):
                if s[i] == current and current == ".":
                    count += 1
                else:
                    if current == "." and count > 2:
                        result += f".{count}"
                    else:
                        result += current * count
                    current = s[i]
                    count = 1
    
            # Handle final sequence
            if current == "." and count > 2:
                result += f".{count}"
            else:
                result += current * count
    
            return result
    
        def _run_length_decode(self, s: str) -> str:
            """Decode run-length encoding"""
            result = ""
            i = 0
    
            while i < len(s):
                char = s[i]
    
                if char == "." and i + 1 < len(s) and s[i + 1].isdigit():
                    # Extract number
                    num_str = ""
                    j = i + 1
                    while j < len(s) and s[j].isdigit():
                        num_str += s[j]
                        j += 1
                    count = int(num_str)
                    result += "." * count
                    i = j
                else:
                    result += char
                    i += 1
    
            return result
    
        def _base64url_encode(self, s: str) -> str:
            """URL-safe base64 encoding"""
            encoded = base64.b64encode(s.encode("utf-8")).decode("ascii")
            return encoded.replace("+", "-").replace("/", "_").rstrip("=")
    
        def _base64url_decode(self, s: str) -> str:
            """URL-safe base64 decoding"""
            try:
                # Add padding if necessary
                padding = (4 - len(s) % 4) % 4
                s += "=" * padding
                s = s.replace("-", "+").replace("_", "/")
    
                decoded_bytes = base64.b64decode(s)
                return decoded_bytes.decode("utf-8")
            except Exception as e:
                logger.error(f"Base64 decode error: {e}")
                raise ValueError(f"Invalid base64 encoding: {str(e)}")
    
        def _generate_level_name(self, tiles: List[List[int]]) -> str:
            """Generate a name based on level content"""
            stats = self._analyze_level_content(tiles)
    
            name = ""
            if stats["water"] > 0.3:
                name += "Aquatic "
            if stats["spikes"] > 0.1:
                name += "Dangerous "
            if stats["ice"] > 0.2:
                name += "Icy "
            if stats["platforms"] < 0.1:
                name += "Minimal "
            if stats["platforms"] > 0.4:
                name += "Dense "
    
            name += "Adventure"
            return name.strip()
    
        def _analyze_level_content(self, tiles: List[List[int]]) -> Dict[str, float]:
            """Analyze level content for statistics"""
            if not tiles:
                return {
                    "empty": 1.0,
                    "platforms": 0.0,
                    "ice": 0.0,
                    "dangerous": 0.0,
                    "spikes": 0.0,
                    "water": 0.0,
                }
    
            total = len(tiles) * len(tiles[0])
            counts = {i: 0 for i in range(8)}
    
            for row in tiles:
                for tile in row:
                    counts[tile] = counts.get(tile, 0) + 1
    
            return {
                "empty": counts[0] / total,
                "platforms": (counts[1] + counts[2] + counts[3]) / total,
                "ice": counts[4] / total,
                "dangerous": counts[5] / total,
                "spikes": counts[6] / total,
                "water": counts[7] / total,
            }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states that the tool returns 'a visual representation of the level', which is helpful, but doesn't cover important aspects like whether this is a read-only operation, potential rate limits, authentication needs, or what format the visual representation takes. For a tool with no annotation coverage, this leaves significant gaps.

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 appropriately concise with three sentences that each serve a purpose: stating the tool's function, describing the parameter, and explaining the return value. It's front-loaded with the main purpose. The structure is clear, though the 'Args:' and 'Returns:' formatting could be slightly more polished.

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 that there's an output schema (which should document return values), the description doesn't need to fully explain returns. However, for a tool with no annotations and 0% schema description coverage, it should provide more behavioral context. The description covers the basics but lacks details on usage scenarios, error conditions, or visual representation specifics that would make it complete.

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

Parameters3/5

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

The description adds meaningful context for the single parameter 'encoded_level', explaining it should be 'from a URL or sharing link'. With 0% schema description coverage, this compensates somewhat by clarifying the parameter's source and format. However, it doesn't provide examples or detailed syntax, leaving room for improvement in fully documenting the parameter.

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

Purpose4/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: 'View a VibeTide level with visual representation.' It specifies the verb ('view') and resource ('VibeTide level'), distinguishing it from siblings like 'create_level' or 'edit_level_metadata'. However, it doesn't explicitly differentiate from 'view_level_image', which might serve a similar visual purpose.

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 minimal guidance on when to use this tool. It mentions that the input is 'an encoded level string from a URL or sharing link', but doesn't specify when to choose this over alternatives like 'view_level_image' or 'play_level'. No explicit when/when-not scenarios or prerequisites are included.

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/banjtheman/vibe_tide_mcp'

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