Skip to main content
Glama

mgba_read_range

Read a contiguous range of memory addresses from Game Boy, GBC, or GBA ROMs using the mGBA emulator for automated testing and game analysis.

Instructions

Read a contiguous range of memory addresses

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
rom_pathYesPath to the ROM file
start_addressYesStarting memory address
lengthYesNumber of bytes to read
savestate_pathNoOptional savestate to load
framesNoFrames to run before reading (default: 60)

Implementation Reference

  • Handler for mgba_read_range tool in the MCP call_tool dispatcher. Parses arguments, calls emulator.read_memory_range, formats the hex dump output, and adds screenshot if available.
    elif name == "mgba_read_range":
        result = emu.read_memory_range(
            rom_path=arguments["rom_path"],
            start_addr=arguments["start_address"],
            length=arguments["length"],
            savestate_path=arguments.get("savestate_path"),
            frames_before_read=arguments.get("frames", 60),
        )
    
        if result.success and result.data:
            data = result.data["data"]
            start = result.data["start"]
            # Format as hex dump with 16 bytes per line
            lines = [f"Memory range 0x{start:04X} - 0x{start + len(data) - 1:04X}:"]
            for i in range(0, len(data), 16):
                addr = start + i
                hex_bytes = " ".join(f"{b:02X}" for b in data[i:i+16])
                lines.append(f"  {addr:04X}: {hex_bytes}")
            result_content.append(TextContent(type="text", text="\n".join(lines)))
            if result.screenshot:
                result_content.append(ImageContent(
                    type="image",
                    data=base64.b64encode(result.screenshot).decode(),
                    mimeType="image/png",
                ))
        else:
            result_content.append(TextContent(type="text", text=f"Error: {result.error}"))
  • Schema definition for mgba_read_range tool, including input parameters and validation in the list_tools registration.
    Tool(
        name="mgba_read_range",
        description="Read a contiguous range of memory addresses",
        inputSchema={
            "type": "object",
            "properties": {
                "rom_path": {
                    "type": "string",
                    "description": "Path to the ROM file",
                },
                "start_address": {
                    "type": "integer",
                    "description": "Starting memory address",
                },
                "length": {
                    "type": "integer",
                    "description": "Number of bytes to read",
                },
                "savestate_path": {
                    "type": "string",
                    "description": "Optional savestate to load",
                },
                "frames": {
                    "type": "integer",
                    "description": "Frames to run before reading (default: 60)",
                    "default": 60,
                },
            },
            "required": ["rom_path", "start_address", "length"],
        },
    ),
  • Core helper method that generates Lua script to read memory range using mGBA's emu:read8 API after specified frames, writes JSON output, takes screenshot, and uses _run_with_lua to execute.
        def read_memory_range(
            self,
            rom_path: str,
            start_addr: int,
            length: int,
            savestate_path: Optional[str] = None,
            frames_before_read: int = 60,
        ) -> EmulatorResult:
            """Read a range of memory addresses."""
            lua_script = f"""
    local frame = 0
    
    callbacks:add("frame", function()
        frame = frame + 1
        if frame >= {frames_before_read} then
            local f = io.open("output.json", "w")
            if f then
                f:write('{{"start": {start_addr}, "length": {length}, "data": [')
                for i = 0, {length - 1} do
                    if i > 0 then f:write(',') end
                    f:write(tostring(emu:read8({start_addr} + i)))
                end
                f:write(']}}')
                f:close()
            end
            emu:screenshot("screenshot.png")
            -- Write DONE marker
            local done = io.open("DONE", "w")
            if done then done:write("OK"); done:close() end
        end
    end)
    """
            return self._run_with_lua(rom_path, lua_script, savestate_path)
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 but only states the basic operation. It doesn't mention what happens when reading memory (does it require emulation to be running?), what format the output takes, whether there are limitations on address ranges, or what happens with invalid addresses. For a memory read operation with 5 parameters, this is insufficient 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.

Conciseness5/5

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

The description is a single, clear sentence that efficiently communicates the core function. There's no wasted language or unnecessary elaboration - every word serves the purpose of explaining what the tool does.

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

Completeness2/5

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

For a tool with 5 parameters, no annotations, and no output schema, the description is inadequate. It doesn't explain what the tool returns (raw bytes? formatted data?), how errors are handled, or the relationship between parameters like 'savestate_path' and 'frames' with the memory reading operation. The context demands more complete information.

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 schema has 100% description coverage, so all parameters are documented in the schema itself. The description adds no additional parameter information beyond what's already in the schema descriptions. This meets the baseline expectation when schema coverage is complete.

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 action ('Read') and resource ('contiguous range of memory addresses'), making the purpose immediately understandable. However, it doesn't distinguish this tool from sibling tools like 'mgba_read_memory' - both appear to read memory, so the specific distinction isn't explained.

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 about when to use this tool versus alternatives. With sibling tools like 'mgba_read_memory' and 'mgba_dump_entities' available, there's no indication of what makes this tool the appropriate choice for reading a contiguous range versus other memory access methods.

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/struktured-labs/mgba-mcp'

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