mesen-for-ai
This server is an MCP bridge that lets AI agents drive Mesen headlessly for console reverse engineering and game conversion work, exposing debugger-facing Lua functionality as MCP tools over stdio.
Session management: load ROMs (including ZIPs), inspect session info, reset, and shut down sessions.
Emulation control: step a specified number of frames, optionally resetting first, and check run status.
Input control: set or get named controller button latches, applied at Mesen's safe
inputPolledcallback.Video export: write the current rendered frame as a binary P6 RGB image.
CPU inspection: read/write CPU memory and inspect registers, with optional CPU type and state.
Watches: create, list, and delete watchpoints on memory regions/addresses to observe accesses.
Breakpoints: create, list, and delete breakpoints on memory/address conditions.
Code/Data Logger (CDL): start/stop coverage windows, read decoded CDL bytes by offset/length, and export CDL maps with range summaries and byte counts.
Tracing: start, stop, and list CPU instruction traces.
Supported systems: SNES, NES, PC Engine, and Game Boy Advance, with CDL coverage for their main ROM/CHR regions.
Deterministic evidence runs: supports reproducible RAM dumps and controlled reset-plus-frames operations for reliable reverse-engineering experiments.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@mesen-for-aiLoad the ROM, step 60 frames, and dump the CPU registers."
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
mesen-for-ai
mesen-for-ai is an MCP server that lets AI agents drive Mesen headlessly for
console reverse engineering and game conversion work.
It does not port or vendor Mesen. It launches an existing Mesen/MesenCE binary,
runs bridge.lua inside the emulator, and exposes the debugger-facing Lua API
over MCP JSON-RPC on stdio.
If you are an LLM, read this first: AGENTS.md.
Supported Systems
Use this project for Mesen systems where the required debugger surface is available:
SNES / Super Nintendo
NES / Famicom
PC Engine / TurboGrafx-16
Game Boy Advance
The Code/Data Logger is available for SNES PRG ROM, NES PRG/CHR ROM, PC Engine PRG ROM, and GBA PRG ROM. Mesen emulates more systems, but this project does not promise CDL coverage for Master System, Game Boy, or WonderSwan because Mesen does not register those CDL loggers.
Related MCP server: mcp-retroarch
Requirements
Python 3.11 or newer.
xvfb-runon Linux for headless Mesen execution.A Mesen or MesenCE build with
--testrunnersupport and Lua socket support.Set
MESEN_BINto the Mesen executable you want to use.
Example:
export MESEN_BIN=/path/to/MesenThe local wrapper has a development default for MESEN_BIN, but public use
should set the variable explicitly.
Run the MCP Daemon
From a checkout:
PYTHONPATH=src python3 -m mesen_mcp.daemonThe daemon speaks MCP-style JSON-RPC 2.0 over its own stdio. Mesen stdout and
stderr are not part of the MCP protocol; Mesen talks to the daemon through a
per-session TCP socket opened by bridge.lua.
Headless Runner
You can run a Lua testrunner script directly:
MESEN_BIN=/path/to/Mesen ./scripts/run_headless.sh <rom> <script.lua>The runner creates an isolated Mesen home and writes deterministic settings:
Lua IO/OS access enabled.
Lua network access enabled for the socket bridge.
deterministic RAM power-on state for SNES, NES, PC Engine, GBA, and Game Boy.
NES mapper and CPU/PPU alignment randomization disabled.
For a deterministic RAM smoke test:
MESEN_BIN=/path/to/Mesen MESEN_MCP_FRAMES=60 MESEN_MCP_DUMP_PATH=/tmp/ram-a.bin \
./scripts/run_headless.sh /path/to/game.sfc scripts/dump_ram.lua
MESEN_BIN=/path/to/Mesen MESEN_MCP_FRAMES=60 MESEN_MCP_DUMP_PATH=/tmp/ram-b.bin \
./scripts/run_headless.sh /path/to/game.sfc scripts/dump_ram.lua
cmp /tmp/ram-a.bin /tmp/ram-b.binMCP Tools
Implemented tools:
session.load_rom,session.info,session.reset,session.shutdownrun.step_frames,run.statusinput.set,input.getvideo.export_framecpu.registers,cpu.read_memory,cpu.write_memoryconsole.statefor the held machine's complete serialized scalar state, including NES PPUVideoRamAddr,TmpVideoRamAddr,ScrollX, andWriteTogglewatch.create,watch.list,watch.deletebreakpoint.create,breakpoint.list,breakpoint.deletecdl.start,cdl.stop,cdl.get,cdl.exporttrace.start,trace.stop,trace.list
session.load_rom accepts normal ROM files and ZIP archives. For ZIPs, the
daemon extracts the single supported ROM member into the session temporary
directory, launches Mesen against that extracted file, and removes it on
session.shutdown.
For deterministic evidence runs, call run.step_frames with reset=true. That
makes reset plus N frames one bridge operation and avoids variable frames
between separate MCP calls. A newly loaded ROM is held before its first frame
starts until that explicit run request, so watches and CDL can be armed without
recording an uncontrolled pre-reset interval.
input.set latches named controller buttons and applies them from Mesen's
inputPolled callback, which is the only safe point for scripted input. Change
the latch while held at a frame boundary, then advance the intended number of
frames. video.export_frame writes the held rendered frame as binary P6 RGB.
Code/Data Logger Semantics
Mesen's Lua API exposes getCdlData; it does not expose a logger on/off switch.
cdl.start and cdl.stop are MCP-side window markers only. Collection is
continuous inside Mesen.
The Lua getCdlData table is zero-indexed even though ordinary Lua arrays are
usually one-indexed. The bridge preserves physical ROM offset zero as JSON
element zero; do not add an index adjustment in callers.
cdl.export returns coveredBytes and memorySize. Equality means the exported
map has one decoded record for every byte in that ROM region. It does not mean
the run executed or read the whole ROM.
The evidence that CDL is live is growth in codeBytes, dataBytes, and
summaryRanges when a deterministic run is driven for longer or through more
gameplay.
NES CHR is the platform-specific exception to the generic flag names. Mesen's
source defines bit 0x01 as NesChrDrawn for CHR ROM, not CPU Code.
Inline/exported CHR records therefore expose drawn, summaries classify those
ranges as drawn, and export counts report drawnBytes; codeBytes and
dataBytes remain zero for CHR.
Skills
The repo ships Codex/Codex-compatible skills in skills/:
skills/mesen-emulator- load ROMs, manage session handles, step frames, read/write memory, and inspect CPU registers.skills/mesen-debug- answer debugging questions with watches, breakpoints, traces, registers, and memory inspection.skills/mesen-codedata- export and interpret Mesen Code/Data Logger maps.
Install them by symlinking or copying the skill directories into your agent's
skill directory. If the skills are installed outside this checkout, set
MESEN_FOR_AI_REPO to the checkout root so scripts/mesen_client.py can find
the daemon.
Validation
Unit and static smoke tests:
python3 -m py_compile src/mesen_mcp/*.py scripts/test_mcpd.py
PYTHONPATH=src python3 -m unittest discover -s tests -vReal emulator validation requires a private test ROM supplied by the user:
MESEN_BIN=/path/to/Mesen PYTHONPATH=src scripts/test_mcpd.py --rom /path/to/test-rom.zip --frames 60Do not commit, upload, or redistribute ROM, BIOS, firmware, disc-image, or other copyrighted game material.
License
mesen-for-ai is licensed under GPL-3.0-only. See LICENSE.
Mesen itself is an upstream GPL-3.0 emulator and is not vendored in this
repository. The wrapper code in this repository is original, but bridge.lua
runs inside the Mesen process and calls Mesen's Lua API directly. The
conservative licensing position is therefore to publish the wrapper under
GPL-3.0-only as well.
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- AlicenseAqualityCmaintenanceMCP server for PCSX2 and other emulators that speak the PINE protocol. Read and write 8/16/32/64-bit emulator memory and control save states for PlayStation-family emulation.14252MIT
- AlicenseAqualityCmaintenanceMCP server for RetroArch via its Network Control Interface. Drive any libretro core — read/write memory, save/load state, screenshot, pause/frame-advance/reset — across NES, SNES, Genesis, N64, GBA, PS1 and more.17233MIT
- AlicenseAqualityBmaintenanceMCP server for the mGBA Game Boy Advance emulator. Read and write GBA memory, inject button presses, take screenshots, save/load state, and step the emulator through a Lua bridge.18331MIT
- AlicenseAqualityCmaintenanceMCP 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.20304MIT
Related MCP Connectors
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to control Unreal E…
MCP server exposing the Backtest360 engine API as tools for AI agents.
MCP server for OpenMM — exposes market data, account, trading, and strategy tools to AI agents
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
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/paulomanrique/mesen-for-ai'
If you have feedback or need assistance with the MCP directory API, please join our Discord server