mesen-for-ai
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.
README
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.
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/Mesen
The 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.daemon
The 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.bin
MCP Tools
Implemented tools:
session.load_rom,session.info,session.reset,session.shutdownrun.step_frames,run.statuscpu.registers,cpu.read_memory,cpu.write_memorywatch.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.
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.
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.
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 -v
Real 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 60
Do 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.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。