MCP server for persistent live mGBA control with script bridge, screenshots, memory and input tooling
Project description
mgba-live-mcp
MCP server for persistent, live mGBA control. It is designed for agent workflows that need to keep one emulator process running across multiple tool calls (input, Lua, memory reads, OAM/entity dumps, screenshots).
If you need one-shot/headless runs instead of persistent sessions, see struktured-labs/mgba-mcp.
What You Get (MCP Context)
- Long-lived session lifecycle:
mgba_live_start,mgba_live_attach,mgba_live_status,mgba_live_stop - Live control:
mgba_live_input_tap,mgba_live_input_set,mgba_live_input_clear,mgba_live_run_lua - Inspection:
mgba_live_read_memory,mgba_live_read_range,mgba_live_dump_pointers,mgba_live_dump_oam,mgba_live_dump_entities - Snapshot output:
mgba_live_export_screenshotplus image snapshots returned bystatus/attach/start_with_lua/most live commands
MCP reference: docs/mcp-reference.md
Quick Start (uvx)
- Run directly from PyPI with
uvx:
uvx mgba-live-mcp
- If you want to run from git (for unreleased changes), use:
uvx --from git+https://github.com/penandlim/mgba-live-mcp mgba-live-mcp
- Register in an MCP client (Codex example):
[mcp_servers.mgba]
command = "uvx"
args = ["mgba-live-mcp"]
Git fallback (if package is not yet published):
[mcp_servers.mgba]
command = "uvx"
args = ["--from", "git+https://github.com/penandlim/mgba-live-mcp", "mgba-live-mcp"]
Local Development
- Install dependencies for this repo:
uv sync
- Run the MCP server:
uv run mgba-live-mcp
- Register it in your MCP client (Codex example):
[mcp_servers.mgba]
command = "uv"
args = [
"run",
"--directory",
"/absolute/path/to/mgba-live-mcp",
"mgba-live-mcp",
]
- Install and run pre-commit hooks (lint/checks via
uv run):
make precommit-install
make precommit-run
Requirements And Setup Links
- mGBA:
Build/install a Qt + Lua-capable binary (
mgba-qt/mGBA) with these required CMake flags:-DBUILD_QT=ON -DENABLE_SCRIPTING=ON -DUSE_LUA=ON - uv:
Python package/runtime manager used by this repo (
uv sync,uv run ...) - Model Context Protocol: Protocol used by the server; configure this process as an MCP server in your client
Important runtime notes:
- A ROM path is required to start (
.gba,.gb,.gbc). - Binary auto-discovery order:
mgba-qt,mgba,mGBA. - If auto-discovery fails, pass
mgba_pathinmgba_live_startormgba_live_start_with_lua. - Runtime state is stored at
~/.mgba-live-mcp/runtime(sessions, logs, command/response files). - Dead or crashed session directories are moved to
~/.mgba-live-mcp/runtime/archived_sessions/instead of being deleted. - Archived sessions are not treated as active and are not returned by
mgba_live_statuscalls. - This is a hard cutover from repo-local
.runtime; no hybrid fallback is used. - If you have old repo-local sessions, migrate manually by copying
.runtime/*to~/.mgba-live-mcp/runtime/. mgba_live_statuswithall=truelists sessions from this shared user-level runtime root.scripts/mgba_live_bridge.luais transitional for local workflows; packagedsrc/mgba_live_mcp/resources/mgba_live_bridge.luais the runtime source of truth.
Common MCP Flows
1) Start a session
{
"rom": "/absolute/path/to/game.gba",
"fast": true
}
Notes:
fast: truemaps tofps_target=600- default when omitted is
fps_target=120
2) Start + run Lua immediately
Use mgba_live_start_with_lua when you need first-frame setup and a post-Lua
snapshot in one call.
{
"rom": "/absolute/path/to/game.gba",
"code": "return emu:currentFrame()"
}
3) Tap input and capture after settle
{
"session": "20260220-120000",
"key": "A",
"frames": 2,
"wait_frames": 6
}
wait_frames is applied after release before the screenshot is captured.
4) Read memory
{
"session": "20260220-120000",
"start": 49664,
"length": 64
}
5) Save screenshot to a known path
{
"session": "20260220-120000",
"out": "/tmp/mgba-shot.png"
}
Important Behavior
mgba_live_startis bootstrap-only (no Lua arg, no screenshot return).mgba_live_start_with_luarequires exactly one offileorcode.mgba_live_run_luasupports callback-style macros by returning{ macro_key = "..." }and setting_G[macro_key].active = falsewhen done; the tool waits for completion before returning its snapshot.mgba_live_input_setandmgba_live_input_clearupdate held keys but do not include a snapshot; callmgba_live_statusto verify visually.- Automatic snapshots in tool responses include only
framemetadata and image content. Files are persisted only viamgba_live_export_screenshot.
Local CLI (Dev/Debug)
The MCP server wraps scripts/mgba_live.py. This script is a compatibility shim
that delegates to the packaged module CLI.
uv run python scripts/mgba_live.py --help
uv run python scripts/mgba_live.py start --help
uv run pytest
Quality commands:
make lint
make typecheck
make test
make check
Release Checklist
- Update version in
pyproject.tomlandsrc/mgba_live_mcp/__init__.py. - Add release notes in
CHANGELOG.md. - Run local checks:
uv sync --group dev && make check && uv build - Trigger TestPyPI publish workflow (
publish-testpypi) and verify install from TestPyPI. - Push tag
vX.Y.Zto trigger the PyPI release workflow. - Smoke test:
uvx mgba-live-mcpanduvx --from git+https://github.com/penandlim/mgba-live-mcp mgba-live-mcp.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mgba_live_mcp-0.3.2.tar.gz.
File metadata
- Download URL: mgba_live_mcp-0.3.2.tar.gz
- Upload date:
- Size: 110.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
241b579ad35fd05bf4f24355d632ec3680a4be5a52920a2331823d31d2f315ae
|
|
| MD5 |
b2a3194596a7bb82c330e75da43a26d0
|
|
| BLAKE2b-256 |
e58b5414f5bfb6fb9450135174133839132e6965d6ea26050d22c7c1572897f8
|
Provenance
The following attestation bundles were made for mgba_live_mcp-0.3.2.tar.gz:
Publisher:
release.yml on penandlim/mgba-live-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mgba_live_mcp-0.3.2.tar.gz -
Subject digest:
241b579ad35fd05bf4f24355d632ec3680a4be5a52920a2331823d31d2f315ae - Sigstore transparency entry: 1006117563
- Sigstore integration time:
-
Permalink:
penandlim/mgba-live-mcp@8fab09b245fc06d3f437477b1288d6e1c088335f -
Branch / Tag:
refs/tags/v0.3.2 - Owner: https://github.com/penandlim
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8fab09b245fc06d3f437477b1288d6e1c088335f -
Trigger Event:
push
-
Statement type:
File details
Details for the file mgba_live_mcp-0.3.2-py3-none-any.whl.
File metadata
- Download URL: mgba_live_mcp-0.3.2-py3-none-any.whl
- Upload date:
- Size: 23.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c44c667b6512448bdf1181933b80ec3f9f3f8293e323a941f9b95cf4ba4a6a34
|
|
| MD5 |
640415307a3e5166d478b256b09aef87
|
|
| BLAKE2b-256 |
f5097dc38f30ff8ad46bdbf5a3dda83d775b8a5deae79e83a8b445e89bb45f69
|
Provenance
The following attestation bundles were made for mgba_live_mcp-0.3.2-py3-none-any.whl:
Publisher:
release.yml on penandlim/mgba-live-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mgba_live_mcp-0.3.2-py3-none-any.whl -
Subject digest:
c44c667b6512448bdf1181933b80ec3f9f3f8293e323a941f9b95cf4ba4a6a34 - Sigstore transparency entry: 1006117564
- Sigstore integration time:
-
Permalink:
penandlim/mgba-live-mcp@8fab09b245fc06d3f437477b1288d6e1c088335f -
Branch / Tag:
refs/tags/v0.3.2 - Owner: https://github.com/penandlim
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8fab09b245fc06d3f437477b1288d6e1c088335f -
Trigger Event:
push
-
Statement type: