Skip to main content
Glama

mgba_write8

Write a single byte value to any RAM address in the Game Boy Advance emulator, using direct memory access that bypasses cartridge bus effects. Writes to ROM regions are ignored.

Instructions

Write a single byte value to a memory address. Only works on RAM regions; writes to ROM are no-ops.

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
valueYesByte value (0-255)

Implementation Reference

  • Tool definition (name, description, inputSchema) for mgba_write8, registered in the TOOLS array. Schema requires address (integer) and value (integer 0-255).
    {
      name: "mgba_write8",
      description: `Write a single byte value to a memory address. Only works on RAM regions; writes to ROM are no-ops.\n\n${MBC_CAVEAT}`,
      inputSchema: {
        type: "object",
        required: ["address", "value"],
        properties: {
          address: { type: "integer", description: "RAM address" },
          value:   { type: "integer", minimum: 0, maximum: 255, description: "Byte value (0-255)" },
        },
      },
    },
  • Handler for mgba_write8: calls mgba.call('write8', {address, value}) via the RPC client and returns a formatted success message.
    case "mgba_write8": {
      await mgba.call("write8", { address: p.address, value: p.value });
      return ok(`Wrote ${formatHex(p.value)} → 0x${(p.address as number).toString(16).toUpperCase()}`);
    }
  • src/tools.ts:258-261 (registration)
    The registerTools function registers all tools (including mgba_write8) via server.setRequestHandler(ListToolsRequestSchema).
    export function registerTools(server: Server, mgba: MgbaClient): void {
      server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: TOOLS }));
    
      server.setRequestHandler(CallToolRequestSchema, async (req) => {
  • Helper functions ok() and formatHex() used by the mgba_write8 handler to format its response.
    function ok(text: string) {
      return { content: [{ type: "text" as const, text }] };
    }
    
    function formatHex(n: unknown): string {
      if (typeof n !== "number") return String(n);
      return `${n} (0x${n.toString(16).toUpperCase()})`;
    }
  • MgbaClient.call() method — the RPC transport used to send the 'write8' method 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 provided, so the description carries full burden. Discloses that writes to ROM are no-ops and explains bypass of cartridge bus model, MBC commands, and SRAM behavior. No contradictions.

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?

Two clear sentences plus a well-structured NOTE paragraph. Front-loaded with main action. The note is justified for a nuanced tool but adds length.

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?

Fully explains behavior, limitations, and alternatives given complexity. No output schema needed; return values are trivial. Suitable for an AI agent to use correctly.

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?

Schema covers both parameters with 100% coverage ('RAM address', 'Byte value (0-255)'). The description adds only context about RAM-only operation but no new parameter-specific meaning beyond the schema.

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?

Clearly states 'Write a single byte value to a memory address' with a specific verb and resource. Distinguishes itself from sibling read/write tools and specifies it only works on RAM regions.

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?

Explicitly states when to use (RAM writes) and when not (ROM writes are no-ops). Provides a detailed note on MBC behavior and suggests alternative tools (mgba_save_state/mgba_load_state) for seeding SRAM.

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