Skip to main content
Glama

mesen-probe

Extension for mesen-for-ai, the MCP server that drives Mesen headlessly. mesen-probe adds what a ROM hacking or translation workflow needs and the original does not offer, without copying the original: it runs on top of it.

What it adds

Tool

Purpose

state.save, state.load

SNES savestates as standard Mesen .mss files. Mesen only allows them inside an exec callback of the main CPU, so the state is taken on the next instruction, or exactly at the instruction when the session is held at an exec breakpoint hit. After a load the frame counter restarts at 0.

snesVideoRam, snesCgRam, snesSpriteRam

Read-only memory types for VRAM (64 KiB), palette (512 bytes, BGR555) and OAM (544 bytes). Addresses are byte offsets. Writes are rejected.

memory.export

Writes a memory region (default: all of it) to a binary file and returns its SHA-256.

cdl.export_binary

Writes the Code/Data Logger as raw bytes, one per ROM byte (flags 0x01 code, 0x02 data, 0x04 jump target, 0x08 sub entry point), and returns its SHA-256 and counts. The original cdl.export writes one JSON object per byte, hundreds of MB for a 4 MiB ROM.

video.export_frame with format

ppm (default, raw framebuffer, 256x239) or png (the visible frame as Mesen shows it, 256x224).

probe.info

Confirms that the extension is loaded in the session.

Windows launcher

Each session gets an isolated portable Mesen home (hardlinked Mesen.exe plus a deterministic settings.json), so the original, which only supports Linux, works on Windows.

All tools of mesen-for-ai remain available. Savestates and video memory are implemented for SNES; other consoles return an error.

Related MCP server: mcp-bizhawk

How it works

mesen-for-ai has no extension points, so patches/ holds two small patches against it: bridge.lua loads the Lua file named by MESEN_BRIDGE_EXTENSION and gives it an API table, and SessionManager starts Mesen through an overridable _spawn. The extension is src/mesen_probe/probe.lua; the Python side subclasses the original daemon and session manager. See patches/README.md.

Setup

  1. Get MesenCE (the emulator) and mesen-for-ai.

  2. Check out mesen-for-ai at the commit in patches/BASE and apply the patches, leaving them uncommitted:

    git -C /path/to/mesen-for-ai checkout "$(cat patches/BASE)"
    git -C /path/to/mesen-for-ai apply --ignore-whitespace patches/*.patch
  3. Install mesen-probe, preferably in a virtual environment (the sources in src/ are installed as the package mesen_probe), point it at the patched mesen-for-ai, and start the server:

    pip install -e .
    export MESEN_FOR_AI_DIR=/path/to/mesen-for-ai
    export MESEN_BIN=/path/to/Mesen            # Mesen.exe on Windows
    python -m mesen_probe.daemon

mesen-probe refuses to start if mesen-for-ai is missing or not patched. The server speaks MCP over stdio; an example .mcp.json entry is:

{
  "mcpServers": {
    "mesen": {
      "command": "/path/to/venv/bin/python",
      "args": ["-m", "mesen_probe.daemon"],
      "env": {
        "MESEN_FOR_AI_DIR": "/path/to/mesen-for-ai",
        "MESEN_BIN": "/path/to/Mesen"
      }
    }
  }
}

Tests

MESEN_FOR_AI_DIR=/path/to/mesen-for-ai MESEN_BIN=/path/to/Mesen python -m unittest discover -s tests -v

Emulator tests run on a synthetic SNES ROM generated in memory by tests/support.py, so no game is needed; they are skipped without MESEN_BIN. The tests that check the patches need MESEN_FOR_AI_DIR.

Limitations

  • Savestates are tied to one ROM build and one Mesen version.

  • A frame captured right after a reset can still show boot output; step past the boot first.

  • At maximum speed Mesen skips rendering frames based on wall-clock time (SnesPpu.cpp, _skipRender), so a capture can show the previous frame while the emulated state has moved on. The Windows launcher disables it (Snes.DisableFrameSkipping in the session settings.json); the Linux path uses mesen-for-ai's own shell runner, which does not, so captures taken there are not reproducible pixel for pixel. Memory dumps (WRAM, VRAM, CGRAM, OAM) are never affected.

  • The patches are made against one upstream commit; a newer mesen-for-ai may need them adjusted.

License

The code of mesen-probe is released under the MIT License; see LICENSE. The two files in patches/ are the exception: they are modifications of mesen-for-ai, which is licensed under GPL-3.0-only, so they stay under that license (see patches/LICENSE). mesen-for-ai is by paulomanrique; see its repository for its license and credits.

mesen-probe imports and extends mesen-for-ai, which is GPL-3.0-only, and the MIT License is compatible with it. Whoever distributes mesen-probe together with, or combined with, mesen-for-ai distributes a combined work and has to meet the GPL for that combination.

Never commit ROMs, BIOS images, savestates or any other copyrighted game material.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      C
      maintenance
      MCP server for BizHawk, the multi-system emulator. Drive NES, SNES, GB/GBC/GBA, Genesis, N64, PSX, Saturn and more through one Lua bridge — memory r/w across named domains, joypad input, frame-advance, screenshot, save/load state.
      20
      51 npm
      6
      MIT
    • A
      license
      C
      quality
      C
      maintenance
      Enables MAME reverse engineering tasks including memory access tracing, input injection, ROM auditing, and IO-port discovery for arcade-to-SNES porting.
      25
      3
      GPL 2.0
    • A
      license
      C
      quality
      C
      maintenance
      MCP server that launches Mesen/MesenCE headlessly and exposes the emulator's debugger-face Lua API over MCP JSON-RPC, enabling AI agents to load ROMs, step frames, inspect memory/registers, manage breakpoints/watches, trace execution, and export Code/Data Logger maps for SNES, NES, PC Engine, and Game Boy Advance.
      22
      1
      GPL 3.0