Skip to main content
Glama

press_b

Simulate pressing the B button on a GameBoy emulator. Configure the duration in frames to control how long the button is held, enabling precise input for gameplay or testing.

Instructions

Press the B button on the GameBoy

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
duration_framesNoNumber of frames to hold the button

Implementation Reference

  • Async handler function executed when the 'press_b' tool is called. It presses the B button for the specified number of frames via emulatorService and returns the updated screen as ImageContent.
    async ({ duration_frames }): Promise<CallToolResult> => {
      // Press the button using the service (advances one frame)
      emulatorService.pressButton(button, duration_frames);
    
      // Return the current screen using the service
      const screen = emulatorService.getScreen();
      return { content: [screen] };
    }
  • Zod schema defining the input parameters for the press_b tool: optional duration_frames (defaults to 25).
    {
      duration_frames: z.number().int().positive().optional().default(1).describe('Number of frames to hold the button').default(25)
    },
  • src/tools.ts:21-36 (registration)
    Loop that registers the 'press_b' tool (when button==='B') on the MCP server, including name, description, schema, and handler.
    Object.values(GameBoyButton).forEach(button => {
      server.tool(
        `press_${button.toLowerCase()}`,
        `Press the ${button} button on the GameBoy`,
        {
          duration_frames: z.number().int().positive().optional().default(1).describe('Number of frames to hold the button').default(25)
        },
        async ({ duration_frames }): Promise<CallToolResult> => {
          // Press the button using the service (advances one frame)
          emulatorService.pressButton(button, duration_frames);
    
          // Return the current screen using the service
          const screen = emulatorService.getScreen();
          return { content: [screen] };
        }
      );
  • Invokes registration of press_b tool (via registerGameBoyTools) on the MCP server instance.
    // Register GameBoy tools
    registerGameBoyTools(server, emulatorService); // Pass emulatorService
  • Supporting method called by the tool handler to press the specified button (B for press_b) and return the screen.
    pressButton(button: GameBoyButton, durationFrames: number): ImageContent {
      log.debug(`Pressing button: ${button}`);
      if (!this.isRomLoaded()) {
        log.warn('Attempted to press button with no ROM loaded');
        throw new Error('No ROM loaded');
      }
      this.emulator.pressButton(button, durationFrames); // This advances one frame
      return this.getScreen();
    }
Install Server

Other Tools

Related 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/mario-andreschak/mcp-gameboy'

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