Skip to main content
Glama

mgba_write32

Write a 32-bit little-endian value to a 4-byte-aligned memory address in GBA RAM. Note that writes bypass cartridge bus effects on Game Boy MBC games.

Instructions

Write a 32-bit value (little-endian) to a memory address. Address must be 4-byte aligned.

NOTE: writes use mGBA's debug-direct memory access, which bypasses the cartridge bus model. On Game Boy with an MBC cartridge, this means writes to ROM region (0x0000-0x7FFF) won't trigger MBC bank-switch / RAM-enable commands, and writes to SRAM (0xA000-0xBFFF) hit the underlying buffer regardless of MBC enable state. To seed cartridge SRAM cleanly, use mgba_save_state / mgba_load_state with a pre-prepared state file.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
addressYesRAM address (4-byte aligned)
valueYes32-bit value

Implementation Reference

  • Tool definition and input schema for mgba_write32 — declares name, description, and inputSchema with required 'address' and 'value' (32-bit integer) parameters.
    {
      name: "mgba_write32",
      description: `Write a 32-bit value (little-endian) to a memory address. Address must be 4-byte aligned.\n\n${MBC_CAVEAT}`,
      inputSchema: {
        type: "object",
        required: ["address", "value"],
        properties: {
          address: { type: "integer", description: "RAM address (4-byte aligned)" },
          value:   { type: "integer", minimum: 0, description: "32-bit value" },
        },
      },
    },
  • Handler case for mgba_write32 — calls mgba.call('write32', ...) via the MgbaClient RPC and returns a formatted success string.
    case "mgba_write32": {
      await mgba.call("write32", { address: p.address, value: p.value });
      return ok(`Wrote ${formatHex(p.value)} → 0x${(p.address as number).toString(16).toUpperCase()}`);
    }
  • src/tools.ts:258-259 (registration)
    Registration function registerTools that wires up both ListToolsRequestSchema (exposing the TOOLS array) and CallToolRequestSchema (dispatching to handlers via switch).
    export function registerTools(server: Server, mgba: MgbaClient): void {
      server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: TOOLS }));
  • MgbaClient.call() method — the generic RPC helper that serializes the method name ('write32') and params to JSON and sends them over a TCP socket to the mGBA Lua bridge.
      async call<T = unknown>(
        method: string,
        params?: Record<string, unknown>,
      ): Promise<T> {
        // Lazy (re)connect — bridge.lua reloads kill the socket, and the user
        // shouldn't have to restart the MCP host every time they edit the script.
        if (!this.socket || this.socket.destroyed) {
          try {
            await this.connect();
          } catch (err) {
            throw new Error(
              `Cannot reach mGBA bridge at ${this.host}:${this.port}. ` +
              `Make sure mGBA is running with bridge.lua loaded (Tools > Scripting). ` +
              `Underlying error: ${(err as Error).message}`,
            );
          }
        }
    
        return new Promise<T>((resolve, reject) => {
          const sock = this.socket;
          if (!sock) {
            reject(new Error("socket vanished after connect"));
            return;
          }
    
          const id = this.nextId++;
          this.pending.set(id, (resp) => {
            if (resp.error) {
              reject(new Error(`mGBA RPC error [${resp.error.code}]: ${resp.error.message}`));
            } else {
              resolve(resp.result as T);
            }
          });
    
          const msg = JSON.stringify({ id, method, params: params ?? {} }) + "\n";
          sock.write(msg, (err) => {
            if (err) {
              this.pending.delete(id);
              reject(err);
            }
          });
        });
      }
    }
Behavior5/5

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

No annotations are provided, so the description bears full responsibility. It thoroughly discloses that writes bypass the cartridge bus, do not trigger MBC commands, and affect SRAM regardless of enable state—critical behavioral traits beyond the basic write operation.

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 efficient with three sentences. The first sentence is clear and action-oriented. The note is appropriately placed and concise, though it could be slightly shortened without losing meaning.

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

Completeness5/5

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

Given the complexity of the tool (direct memory write in an emulator), lack of annotations, and no output schema, the description is exceptionally complete. It covers purpose, alignment, behavioral side effects, and even provides an alternative for a specific use case.

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

Parameters4/5

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

Input schema has 100% coverage with descriptions for both parameters. The description adds value beyond schema by explicitly stating little-endianness for the value and reinforcing alignment, which the schema hints at but does not fully elaborate.

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 it writes a 32-bit little-endian value to a memory address with alignment requirement. It distinguishes itself from sibling read/write tools by specifying data size and operation type.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description includes explicit guidance on when not to use this tool (e.g., for triggering MBC commands) and suggests an alternative (mgba_save_state/mgba_load_state) for clean SRAM seeding, providing clear when-to-use and when-not-to-use context.

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/dmang-dev/mcp-mgba'

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