# MCP server: RetroArch as a tool for AI assistants RetroArch can act as a [Model Context Protocol](https://modelcontextprotocol.io) server, so an AI assistant that speaks MCP can drive it: pause and resume, load and save states, take screenshots, read core memory, load content. Every tool is one of RetroArch's network commands, described as `HELP` describes it on the network command interface. Not every command is a tool: `tools/list` leaves out the ones an assistant has no use for, or that another tool covers. The server is off by default. ## Turning it on In **Settings > Network**, turn on **MCP Server**. Two more entries appear: | Key | Default | Meaning | | --- | --- | --- | | `mcp_server_enable` | `false` | Runs the server. Takes effect when RetroArch next starts. | | `mcp_server_port` | `55357` | TCP port. | | `mcp_server_token` | | The token every client must send. Made on the first start when empty. | | `mcp_server_bind_address` | `127.0.0.1` | Address to listen on; `retroarch.cfg` only. | Restart RetroArch. The log reports the address: [MCP] Listening on http://127.0.0.1:55357/mcp. If it cannot listen there - another RetroArch still running holds the port, say - it says so on screen as well as in the log, since a client would otherwise be talking to that other RetroArch without knowing. On the first start a random token is made and shown under **MCP Server Token**. It is saved with the other passwords in the keychain, never in `retroarch.cfg`. A build without the crypto library cannot make one: enter your own there, or set `mcp_server_token`, before the server will start. ## Connecting a client Clients that support MCP over HTTP ("Streamable HTTP") need three things: - the address: `http://127.0.0.1:55357/mcp` - the transport: HTTP - a header: `Authorization: Bearer ` Where these go depends on the client. Many take a JSON entry of this shape in their MCP server configuration: ```json { "retroarch": { "type": "http", "url": "http://127.0.0.1:55357/mcp", "headers": { "Authorization": "Bearer " } } } ``` The server speaks protocol revision 2026-07-28, and 2025-11-25, 2025-06-18 and 2025-03-26 for clients that open with `initialize`. Its list results and `server/discover` carry `ttlMs: 0` and `cacheScope: "private"`, as 2026-07-28 requires them: the tools are compiled in and `listChanged` is false, so nothing would tell a client holding a list that an upgrade changed it. A client that keeps one anyway sees a rebuilt RetroArch's new parameters once it reconnects. ## Over stdin and stdout A client that starts RetroArch itself can talk to it on stdin and stdout instead of a port, with no token: only the process that started RetroArch holds the other ends. ```json { "retroarch": { "command": "/path/to/retroarch", "args": ["--mcp-stdio"] } } ``` Each message is one line of JSON. stdout is kept for them; whatever else would write there, RetroArch's own log and any core's included, goes to stderr. The MCP Server setting does not need to be on for this. Over stdin and stdout RetroArch also offers logging: after `logging/setLevel`, what it logs at that level and above arrives as `notifications/message`. When the client closes stdin, RetroArch quits. ## The handshake `initialize` answers with `instructions`: how the tools fit together to play a game - find it with `LIST_PLAYLISTS` and `GET_PLAYLIST`, load it paused, `WATCH` what each step needs, step with `STEPS` - queued, so the game plays on while the next stretch is planned - `PRESS ... until` or `RUN_UNTIL`, and `STATE checkpoint` before a risky move. A client shows this to the model once rather than in every tool. Every tool also has a `title` for people, made from its name: `Run frames` for `RUN_FRAMES`. ## What the tools do A tool is named as its command (`GET_STATUS`, `STATE`, `SCREENSHOT`). Its parameters are named, typed and marked needed or not, so a client is told what to send rather than having to write the command's own line by hand: ```json { "name": "LOAD_CONTENT", "arguments": { "core": "/path/to/core.so", "content": "/games/a.rom" } } ``` `STATE` takes an `action`, and a `slot` number for `save` and `load`, `GET_PLAYLIST` takes `playlist` and an optional `first`, `OPTION` takes an `action`, an `option` and a `state` of `on` or `off` - which the schema gives as the only two values it accepts. `tools/list` describes every one of them. A parameter that is needed and left out, one that should be an integer and is not, one the tool does not take, a value outside the set a parameter offers, one sent as `true`, `false`, `null`, an object or an array - no tool takes those - and a tool that does not exist are answered before anything runs, as JSON-RPC invalid params (`-32602`) rather than as a tool failure. The schemas leave other names unforbidden to keep the tool list short; the server refuses them instead, so a misspelt parameter is never dropped and the command run without it. The single `argument` string this server took before the parameters still works, so a client holding a cached tool list keeps going until it reads the new one. The tool's result is what the command answers; commands that answer nothing report `Done.`. `GET_STATUS` and `READ_CORE_MEMORY` answer one line, and give it as fields of its own: `{"state": "PLAYING", "system": "nes", "content": "Super Mario Bros.nes"}` and `{"address": "1000", "bytes": "AA 0F 10"}`. The last field takes the rest of the line, so a comma in a game's name stays in it. A read that runs past the end of one region goes on into the next; where nothing maps the rest it stops there and says so, `TRUNCATED 2` after the bytes, given as `truncated: true, read: 2`. ## Results that are rows The replies that are lines of tab-separated fields - `OPTION`, `LIST_CORES`, `LIST_PLAYLISTS`, `GET_PLAYLIST`, `CORE_OPTION`, `GET_MEMORY_MAP`, `GET_LOG`, `INPUT`, `WATCH`, `RUN_FRAMES`, `PRESS`, `RUN_UNTIL`, `STEPS` and `MENU` - come with `structuredContent` beside the text, so a client is handed the rows rather than splitting them itself. Each of those tools declares an `outputSchema` naming its columns, described by the first tool in the list to answer with them - `RUN_FRAMES` for the watched bytes, which `PRESS`, `RUN_UNTIL`, `STEPS` and `WATCH` then name without repeating: ```json { "content": [ { "type": "text", "text": "0\tSuper Mario World\t/games/smw.sfc\t/cores/snes9x.so\n" } ], "structuredContent": { "rows": [ { "index": "0", "label": "Super Mario World", "content": "/games/smw.sfc", "core": "/cores/snes9x.so" } ] } } ``` The columns are `option` and `value` for the options, `name` and `path` for the cores, `playlist` for the playlists, `index`, `label`, `content` and `core` for a playlist's entries, `key`, `value`, `description` and `values` for a core's options, `start`, `length`, `select`, `disconnect`, `kind`, `access`, `order` and `space` for the memory map, `player`, `buttons` and `axes` for what a player holds, and `label`, `address` and `value` for the bytes `WATCH` watches, and `index`, `label` and `value` for the menu's entries. Every field is a string: it is the text's own field, which the server does not read as anything else. **A tool answers with `structuredContent` exactly when it declared an `outputSchema` and succeeded**, so a client reads the schema it was handed at `tools/list` and does not have to probe each reply. The end-to-end test calls every tool that declares one and holds each reply to it: the required fields, the declared types, and no field it leaves out. A reply marked `isError` is its reason as text, with no `structuredContent`. A tool with no `outputSchema` answers with text alone, because its reply is prose or a confirmation rather than rows. A reply may end short of its columns, and the schema requires only the ones every row carries: `CORE_OPTION show` gives an option's `values` only where it was asked for that option by key. A line the command opens with its own name, such as `LIST_CORES none`, is not a row. Neither are the lines that carry a number about the reply rather than a row of it, which become fields of their own - the number ending the line, so `PRESS 1 right+a 4` gives `frames: 4`: | Line | Field | Where | | --- | --- | --- | | `MORE` | `more: true` | a list cut short with nowhere to resume | | `MORE 200` | `more: true`, `next: 200` | `GET_PLAYLIST`'s next page | | `NEXT 48` | `next: 48` | where `GET_LOG` reached | | `SKIPPED 12` | `skipped: 12` | log lines gone before the first kept | | `RUN_FRAMES 3` | `frames: 3` | the frames `RUN_FRAMES` ran | | `PRESS 1 a 4` | `frames: 4` | the frames `PRESS` ran | | `MET 12` | `met: 12` | the frames `RUN_UNTIL` ran until the byte met it | | `WAITING 540` | `waiting: 540` | the frames it ran without that | | `VALUE 5` | `value: 5` | what `RUN_UNTIL`, or a `PRESS` with `until`, waited on holds | | `QUEUED 4` | `queued: 4` | the steps a queued `STEPS` has left to run | | `DISCARDED 3` | `discarded: 3` | the steps a queued `STEPS` dropped, as the queue had ended | | `PREVIOUS STOPPED 43 STOP 1 STEP 1` | `previous: {"stopped": 43, "stop": 1, "step": 1}` | how a queued `STEPS` ended, on the next reply; `PREVIOUS ERROR ` gives `error` | | `IDLE 1830` | `idle: 1830` | milliseconds the content has sat paused since the queue ran dry | | `DONE 30` | `done: 30` | the frames `STEPS` ran when every step had | | `STOPPED 12` | `stopped: 12` | the frames it ran when its `stop` held | | `STOP 2` | `stop: 2` | which `stop` held, from 1, when `STEPS` stopped | | `STEP 3` | `step: 3` | the step it ended on, from 1 | | `TRUNCATED 2` | `truncated: true`, `read: 2` | a `READ_CORE_MEMORY` that met unmapped memory | | `CLOSED` | `closed: true` | `MENU` with the menu closed | | `SELECTED 3` | `selected: 3` | the menu entry selected | | `COUNT 40` | `count: 40` | the entries in the menu's list | | `MESSAGE Press again to quit` | `message: "Press again to quit"` | a message over the menu, on any line | | `KEYBOARD Username` | `keyboard: "Username"` | the menu asking for text, on any line | | `PATH Main Menu > Settings` | `path: "Main Menu > Settings"` | the lists above the menu's own, on any line | | `MORE 50` | `more: true`, `next: 50` | the menu's next page, as `from` takes it | `GET_LOG` always says where to go on from, so it carries `next` without carrying `more`: a client asks again from `next` and gets whatever has been written since. `GET_LOG` carries no rows: the log is its lines, and a page of them runs to 60 kB, so answering with a row apiece would send the whole page twice. Its `structuredContent` is the trailers alone - `{"next": 482}` - and its `outputSchema` declares only those. The text is unchanged: a client that reads it and nothing else sees exactly what it always did. A game whose name holds a tab is the one thing it will read wrong, and the rows get right - the fields before and after the name are read from the ends of the line, so the stray tab stays inside the name. Both come from revision 2025-06-18, which added them; a client of 2025-03-26 is sent neither. Over HTTP the revision is the one the client names in `MCP-Protocol-Version` on each request; over stdin and stdout it is the one agreed at `initialize`, and it holds for the session. Not every command is a tool. `HELP` and `VERSION` are not, because `tools/list` already lists the commands and every answer names the server's version, and neither are the toggle hotkeys or `GET_CONFIG_PARAM`, whose work `OPTION` does below. Nor is a hotkey that steps a selection. A person presses `STATE_SLOT_PLUS` while watching the slot on screen; for a program the command that takes the value outright is the tool, and stepping towards it is only a way to get the value wrong: `STATE save` over `STATE_SLOT_PLUS` and `SAVE_STATE`, `REPLAY seek` over `NEXT_REPLAY_CHECKPOINT`, `REPLAY play` over `PLAY_REPLAY`. Where nothing reports the selection either - which cheat is picked, which shader preset is loaded - there is nothing worth offering yet, and a tool that writes where it cannot read is worse than none. `READ_CORE_RAM` and `WRITE_CORE_RAM` are not tools either: they take an achievement address, which looks like `READ_CORE_MEMORY`'s system address and is not one, and `GET_MEMORY_MAP` answers the addresses `READ_CORE_MEMORY` takes. The disc is the exception: `DISK` steps blind, and a disc swap is part of playing a game. It is one tool taking a choice - `DISK next` - rather than a tool per hotkey; `MENU`, below, answers with where it landed. `REINIT`, `STATE`, `REPLAY`, `CORE`, `INPUT`, `OPTION` and `CORE_OPTION` stand for their families likewise: `STATE load 3` is `LOAD_STATE_SLOT 3`, `REPLAY seek 600` is `SEEK_REPLAY 600`, `CORE load ` is `LOAD_CORE `, `INPUT set 1 a 1` is `SET_INPUT 1 a 1`, and `OPTION show pause` is `GET_OPTION pause`. A reply that is rows - `INPUT`'s, `OPTION`'s - is the tool's answer as it is. Each answers under its own name - `STATE load 3`, `DISK next pressed`, `REPLAY ERROR no replay is playing or recording`, and `REINIT audio` for a restart that says nothing itself - while the commands sent by name answer as they always have. `DISK` is refused on a core with no disk control, where the hotkeys would do nothing. A word the tool does not take is invalid params naming the ones it does; on the line interfaces it is `STATE ERROR one of save|load|checkpoint|rollback`, and so is anything after a word that takes nothing. `REPLAY`'s slot or frame is its `number` parameter. `SAVE_FILES` and `LOAD_FILES` are not tools: the core writes its save files itself, and playing a game does not need them. All of them are still commands on the network and stdin interfaces, where a person is typing and can see what happened. ## The menu `MENU [index] [from ]` reads and drives RetroArch's own menu - settings, playlists, cores, the Quick Menu - and answers with what it shows once the action has run: its title, a page of 50 entries holding the selection, which entry is selected and how many there are. ``` MENU down MENU Quick Menu 0 Resume 1 Reset 2 Close Content 3 Save States ... SELECTED 1 COUNT 15 ``` The menu opens where it was left, so below the title `PATH` names the lists above it - `PATH Main Menu > Settings > Drivers` - and `b` goes back up them. Where the list runs past the page, `MORE 50` says where the next one starts, for `from`. XMB and Ozone keep their top level in tabs - Main Menu, Settings, History, the playlists - rather than in one list. On XMB, `left` and `right` at the top switch tabs. On Ozone, `left` moves to the tabs, `up` and `down` pick one, and `right` returns to its list; `a` there only returns too. A playlist's tab is titled with the playlist's name. Each entry is its index, its label and its value: a setting's value, `...` for an entry that opens a list, or `checked` for the current choice in a list of them - the driver in use, say. `title`, `rows`, `selected` and `count` are its structured fields. - `show` answers what the menu shows; `from` lists from that entry. - `open` and `close` open and close it. With it closed, `show` and `close` answer `CLOSED`, and the rest are refused. With no content running the menu cannot close, and `close` says so. - `select ` moves straight to an entry, rather than pressing `down` 137 times. - `up`, `down`, `left`, `right`, `a` and `b` press the menu's buttons: `left` and `right` change a value, `a` confirms, `b` goes back. `left`, `right` and `a` take an index too, acting on that entry: `MENU a 3` opens Save States. - `type ` answers a keyboard: one line, entered whole and confirmed, as a platform's own keyboard hands it over. What waits on the user comes as a line of its own after the title. A message - `MESSAGE Press again to close content...`, the confirmation Close Content, Reset and Quit ask for - is confirmed with `a` and dismissed with `b`. An entry that asks for text - a username, a search - answers `KEYBOARD Username`, and `type` or `b` ends it. The action runs on the menu's next frame as its own input would, and the answer comes a frame after that, so a list or a message an action opens is there to read. `MENU open` and `close` are the menu's switch: `menu` is not an `OPTION`. A second `MENU` while one waits replaces it, answered with an error; one whose list another hand changes first does nothing to the entry that took its place, and says so; and one whose menu closes first - a hotkey, another client - is answered `CLOSED`. `MENU` is marked destructive: its entries include Quit, Close Content and Delete. It is RetroArch's menu, not a game's: a game's menus are its screen and memory, played with `PRESS`, `STEPS` and `WATCH`. ## Options A hotkey toggle is of little use to an assistant: `FAST_FORWARD` turns fast-forward on or off depending on what it already was, which cannot be known without asking. `OPTION` replaces the toggles with something that can be asked and told: - `OPTION show [option]` reports every option and its value, name and value tab separated, one per line; with a name, that option's line alone. - `OPTION set