Skip to content

MCP server

Julien Clauzel edited this page Nov 11, 2026 · 5 revisions

The MCP server — let an AI agent drive ZX Next Unite

Since 9.7.57. Settings → Enable MCP server starts a Model Context Protocol server on this PC. An AI agent — Claude Code, Claude Desktop, Cursor, any MCP client — then gets tools for what the app does and can chain them into a workflow: build the game, put it on the card, boot MAME on it, push the build to the Next on the desk, verify it, run it, or — since 9.7.58 — find the latest Spectrum Next games and put them on the card or on the Next.

Every tool is the same operation a button performs, through the same code, so an agent can do what you can and nothing more. The server is off by default, binds 127.0.0.1 only (never reachable from another machine) and can require a bearer token. Nothing extra to install: it is part of the app.

Contents

Enabling it

Settings → NextSync section → Enable MCP server. The row carries:

Control What it does
Enable MCP server Starts the server now and at every launch while ticked.
Port 2050 by default (2048 is NextSync's, 2222 the RS232 ESP emulation's, 2051 CSpect's MCP server — see below). A running server is restarted on a new port a moment after you stop typing.
Require bearer token Every request must carry Authorization: Bearer <token> (or the ZXNEXTUNITE-MCP-TOKEN header); anything else gets HTTP 401. Ticking it mints a random 64-character token; Generate makes a new one; the field is editable.
Connect Claude Code with: … The one-line setup for the current port and token, selectable, with a Copy to clipboard button beside it.

The NextSync console logs MCP server listening on http://127.0.0.1:2050/mcp when it starts, and every tool call after that (MCP: next_deploy -> ok (12.4s)).

Connecting a client

Claude Code talks Streamable HTTP directly — no shim. Paste the command from Settings (the Copy to clipboard button has it) in a terminal:

claude mcp add --transport http zx-next-unite http://127.0.0.1:2050/mcp

With Require bearer token on, the copied command already carries --header "Authorization: Bearer <token>". Check with claude mcp list, then ask Claude Code to "load C:\images\next.img and list /games".

Claude Desktop (and any client that can only spawn a process) runs a small stdio shim that relays each request to the app already running. In claude_desktop_config.json:

{
  "mcpServers": {
    "zx-next-unite": {
      "command": "zx-next-unite-mcp",
      "args": ["--port", "2050"]
    }
  }
}

zx-next-unite-mcp is the console script of a pipx / pip install. A source checkout uses "command": "python", "args": ["C:\\path\\zx-next-unite.py", "--mcp-stdio"]; the portable Windows build zx-next-unite.exe --mcp-stdio. The shim takes --url, --port, --token, --timeout, or the environment variables ZX_NEXT_UNITE_MCP_URL, ZX_NEXT_UNITE_MCP_PORT, ZX_NEXT_UNITE_MCP_TOKEN. When the app is not running (or its server is off) every request is answered with a JSON-RPC error that says so, not a dead pipe.

Anything else: POST JSON-RPC 2.0 to http://127.0.0.1:2050/mcp; GET http://127.0.0.1:2050/ prints a help line with the tool names.

Getting started: your first session

Five minutes from a cold start to an agent driving the app.

1. Start the app from this checkout and switch the server on

python zx-next-unite.py

(or the portable zx-next-unite.exe, or the zx-next-unite command of a pipx install). On the Settings tab tick Enable MCP server. The NextSync console answers:

MCP server listening on http://127.0.0.1:2050/mcp

The setting persists, so from now on the server starts with the app.

2. Register the server with Claude Code

Press Copy to clipboard beside the hint line in Settings and paste it in a terminal — or type it:

claude mcp add --transport http zx-next-unite http://127.0.0.1:2050/mcp
Added HTTP MCP server zx-next-unite with URL: http://127.0.0.1:2050/mcp to local config

Check it:

claude mcp list

zx-next-unite: http://127.0.0.1:2050/mcp (HTTP) - ✓ Connected is what you want. ✘ Failed to connect means the app is not running, the toggle is off, or the port in the command differs from the one in Settings — re-copy the command.

3. Open a fresh Claude Code session in this folder

Claude Code discovers a server's tools when a session starts (in a session that is already open, /mcp reconnects). The 57 tools appear as mcp__zx-next-unite__<name>, and Claude picks them from plain requests — you never type a tool name unless you want to.

4. Try these prompts

You type What runs
What is ZX Next Unite doing right now? app_status
Load C:\temp\cspect-next-2gb.img and list /games image_load, image_ls
Put C:\projects\mygame\mygame.nex into /games on the image and start MAME with it image_put, then emulator_start with file and image_dir
Start CSpect on the image with its own MCP server on port 2051 emulator_start emulator=CSpect cspect_mcp=true
Start the NextSync listener with sync root C:\temp\sync and tell me when a Next connects nextsync_listener_start, then next_sessions
Deploy C:\projects\mygame\mygame.nex to the Next and run it next_deploy — upload, CRC-32 verify on the Next, leave listen mode; with autoexec.bas on the card the Next runs it
Show the last 20 lines of the NextSync console app_log_tail console=nextsync lines=20
What are the latest ZX Spectrum Next games? catalog_latest source=getit category=game
Search every catalogue for "knight" catalog_search query=knight — the Unite! global search
Put the three newest Next games on the card, in /games catalog_latest, then catalog_send_to_image for each
Send the newest Next game to the Next that is connected catalog_latest, then catalog_send_to_next (CRC-verified)
Stop the emulator you started emulator_processes, emulator_stop

To name a tool directly: call the app_status tool of zx-next-unite.

5. A build-and-run loop, as one prompt

Build my game with its build.ps1, then put the .nex on the loaded image under /games and start MAME with it; if MAME refuses, tell me why.

Claude runs the build, then image_put, then emulator_start; on a refusal it reads the reason from the result (no image loaded, the image held by a running emulator, the file missing) and tells you. Swap the last step for deploy it to the Next and run it and the same loop lands the build on real hardware through next_deploy.

6. What you see in the app meanwhile

Every call is a line on the NextSync console — MCP: image_put -> ok (0.1s), MCP: next_ls -> refused (0.0s): no Next is seated on the listener… — and in the file log. A refusal always comes back to the agent as readable text, so you can simply ask Claude what went wrong.

Two workflows

Deploy to the Next on the desk

The push-to-hardware loop of extra/Send-ToNext.ps1, in one tool call. Install extra/autoexec.bas in /nextzxos on the card once: it boots the Next into .sync5 -L (or ZX Next Remote's Listener) and runs whatever lands at /home/incoming.nex. Then the agent:

  1. nextsync_listener_start (optionally sync_root=…) — the Next dials in, next_sessions lists it;
  2. next_deploy local_path=build/game.nex — upload, CRC-32 verify on the Next, then leave listen mode; the loop soft-resets and .nexloads it. A build that does not verify is never run.

Deploy to an emulator

image_load (or image_download_nextzxos, or since 9.7.65 image_create_nextzxos for a fresh FAT32 card holding the latest System/Next distribution), then emulator_start emulator=MAME file=build/game.nex image_dir=/home: the file is put into the image, MAME boots the card and NextZXOS is typed the .nexload command. For CSpect: emulator_start emulator=CSpect file=build/game.nex. emulator_processes / emulator_stop end the run afterwards.

An emulated Next can be a seated Next too. With RS232 ESP Emulation ticked in Settings — the (Mame) box, or since 9.7.58 the (CSpect) box, which installs the UARTRS232 plugin — the Next inside the emulator has network: run .sync5 -L in it and it dials nextsync_listener_start's listener like a real one, so every next_* tool and catalog_send_to_next work against the emulator. esp_emulation_status shows the emulation, how many emulators share it and both Settings toggles.

Find software and put it on a Next (9.7.58)

  1. catalog_latest source=getit category=game limit=10 — the newest games written for the Next (or catalog_search query=… for the Unite! global search across GetIt, ZXDB, zxArt and your itch.io library);
  2. catalog_send_to_image source=getit id=… image_dir=/games — download, unpack, put the game's folder on the loaded card; or catalog_send_to_next source=getit id=… — the same to the Next seated on the listener, verified by the Next's own CRC-32.

In plain words: "put the three newest Next games on the card", or "send the newest Next game to the Next that is connected".

Every tool

57 tools, seven families. A ? marks an optional argument; every next_* tool also takes session (a sid from next_sessions) to target one seated Next — without it, the active one answers. A refused operation (no image loaded, no Next seated, hdfmonkey said no, the bytes on the Next differ) comes back as an isError result carrying the reason, so the agent reads it and tries something else.

App

Tool Arguments What it does
app_status — What ZX Next Unite is doing right now: version, data folder, the loaded disk image and its usage, the tools found (hdfmonkey, CSpect, MAME), the emulators started from the app, the RS232 ESP emulation, the NextSync listener / classic server / HTTP bridge and the Nexts seated on the listener.
app_log_tail console? (sdcard / nextsync / file), lines? (default 50) The last lines of one of the app's consoles: 'sdcard' (the SD Card Utility log: hdfmonkey, emulator launches, downloads), 'nextsync' (the NextSync console: listener, transfers, protocol diagnostics) or 'file' (the rotating zx-next-unite.log).

Disk image (SD Card Utility)

Tool Arguments What it does
image_status — The disk image loaded on the SD Card tab: path, whether it exists, FAT usage (used %, free bytes), whether an emulator started from the app holds it, and the write verdict.
image_load path Load a NextZXOS SD-card image (.img or .hdf) on the SD Card tab, as 'Select NextZXOS disk Image' does: it becomes the image every image_* tool and emulator_start work on. Waits for the root listing.
image_unload — Unload the disk image from the SD Card tab (clears the image box).
image_recent — The disk images remembered in the SD Card tab's image box (most recent first), with whether each file still exists and the cached write verdict.
image_download_nextzxos size? (2gb / 4gb / 8gb), dest_dir?, load? (default True), overwrite? (default False) Download a stock NextZXOS distribution SD-card image from zxnext.uk (the 'Download NextZXOS Image' button), extract the .img next to the zip and, by default, load it. Hundreds of MB: this can take minutes. Both files are named after the size (cspect-next-2gb.zip and .img), and since 9.7.60 an existing one is never replaced: when dest_dir already holds either, nothing is downloaded and the error says what is there — image_load that image, pass another dest_dir, or pass overwrite: true to replace both. An image an emulator started by the app is running on is never replaced, whatever overwrite says.
image_ls path? (default /) List a folder inside the loaded disk image (hdfmonkey ls).
image_get image_path, local_path Copy one file OUT of the loaded disk image to this PC.
image_put local_path, image_dir? (default /) Copy a local file or a whole folder INTO the loaded disk image (hdfmonkey put; folders are created as needed). Refused while an emulator started from the app holds the image.
image_mkdir path Create a folder inside the loaded disk image.
image_rm path, recursive? (default False) Delete a file - or, with recursive=true, a whole folder - inside the loaded disk image. No confirmation, no Recycle Bin.
image_rename old_path, new_path Rename or move a file or folder inside the loaded disk image. hdfmonkey has no rename: the entry is copied out, written back under the new name, checked, and only then is the original deleted (a folder recursively).
image_create_nextzxos (9.7.65) path, size? (2 GB / 4 GB / 8 GB, default 2 GB), load? (default True), overwrite? (default False) Create a fresh SD-card image holding the latest System/Next distribution from specnext.com (the 'Create NextZXOS Image' button): reads the latest-distribution page, downloads the distribution zip it names (checked against the SHA-1 the page prints, cached under downloads/nextzxos), creates the image with hdfmonkey as FAT32 — whatever the size, so MAME boots it as well as CSpect — copies the distribution in and, by default, loads it. Minutes: a ~75 MB download plus a 2–8 GB image. Needs hdfmonkey. An existing file at path is never replaced unless overwrite is true.
image_mame_check (9.7.65) path? (default: the loaded image) Whether MAME can boot an SD-card image: its FAT type and cluster count. A FAT32 image under 65,525 clusters (the official 26.11a "image for emulators": 1 GB with 32 KB clusters) is read as FAT16 by the Next firmware's card driver under MAME and never gets past Error opening menu.ini/.def; CSpect, which never runs that firmware, boots it. Verdict ok, fat32-small (rebuild it with image_make_mame_bootable) or unknown.
image_make_mame_bootable (9.7.65) target, source? (default: the loaded image), size? (2 GB / 4 GB / 8 GB, default 2 GB), load? (default False), overwrite? (default False) Rebuild an SD-card image as a fresh FAT32 image MAME boots (the 'Make this image MAME-bootable' action): lists the source with hdfmonkey, copies every file out, creates target at the chosen size and copies them in. Run image_mame_check first — an image whose verdict is ok needs no rebuild. target is never replaced unless overwrite is true. Minutes for a full card.

Emulators

Tool Arguments What it does
emulator_list — The emulators ZX Next Unite found (MAME, CSpect) and whether each can start right now; a non-empty 'blocked' says why not (no image loaded, the image held by a running emulator...).
emulator_start emulator (MAME / CSpect), file?, image_dir?, cspect_mcp?, cspect_mcp_port? Start MAME or CSpect on the loaded disk image, as the Launch buttons do. With file (a local .nex/.tap/.sna/.z80 ...) the emulator starts that program: CSpect loads it directly; MAME needs it ON the card, so it is put into image_dir first (default: the app stages it under /zxnu-start) and NextZXOS is typed the .nexload command. CSpect 4.2.0+ can start its OWN MCP server (-mcp=<port>): the Settings toggle decides, cspect_mcp / cspect_mcp_port override it for this launch, and the answer names the port so you can connect to CSpect's server as well. Returns the process id (see emulator_processes / emulator_stop).
emulator_processes — The emulators started from ZX Next Unite that are still running (pid, emulator, the image they hold).
emulator_stop pid Stop an emulator started from ZX Next Unite (its whole process tree), by pid from emulator_processes.

RS232 ESP emulation (MAME and CSpect)

Tool Arguments What it does
esp_emulation_status — The RS232 ESP emulation for MAME (the Wi-Fi module an emulated Next talks to): running, port, sessions, the address it reports, how many emulators share it (mame_users: MAMEs and, since 9.7.58, CSpects through the UARTRS232 plugin), and the two Settings toggles (enabled_in_settings for MAME, cspect_enabled_in_settings for CSpect).
esp_emulation_start port?, verbose? Start the RS232 ESP emulation (and turn its (Mame) Settings toggle on so MAME launches wire to it), optionally on another port. A CSpect launched with RS232 ESP Emulation (CSpect) ticked starts or joins the same emulation by itself. A worker already held by a running MAME keeps its port; the answer says which port is live.
esp_emulation_stop force? (default False) Stop the RS232 ESP emulation. Refused while a MAME started from the app still uses it, unless force=true (that MAME loses its Wi-Fi).

Online catalogues (9.7.58)

The app's catalogue tabs as tools. A search here is the tab's own Search / Latest / Random button, so the agent gets the list you would see — and you see its search arrive in the tabs. source is unite (the default: the Unite! global search, every catalogue at once), getit (software written for the Next), zxdb, zxart or itchio (your own itch.io library). Every entry carries the source and id the other tools take.

Tool Arguments What it does
catalog_sources — Which catalogues can be reached right now and what each allows: search, latest, random, download.
catalog_search query, source?, limit? (default 20), category? Search by title (3 characters or more), as the tab's Search does. itch.io searches your library, not the whole site.
catalog_latest source?, limit?, category? The tab's Latest. ZXDB and zxArt are newest-first by their servers; GetIt returns its own listing order and its entries carry no date (catalog_detail has it). itch.io has no Latest.
catalog_random source?, limit?, category? The tab's Random. itch.io has none.
catalog_detail source, id Description, author, date, version, size and the file(s) the entry offers; for itch.io, the uploads your account can download.
catalog_download source, id, dest_dir?, unzip? (default True) Download the entry's file(s) to this PC, into a folder named after it (by default under the app's downloads folder). GetIt always downloads; itch.io entries you own download through the itch.io API; ZXDB and zxArt are refused — the app does not offer their downloads.
catalog_send_to_image source, id, image_dir? (default /games), unzip? catalog_download then image_put: the entry's folder lands on the loaded card. Refused while an emulator started from the app holds the image.
catalog_send_to_next source, id, remote_dir? (default /games), verify? (default True), unzip?, session? catalog_download then next_put: the entry's folder is uploaded to a seated Next, every file verified by the CRC-32 the Next computes. Checks that a Next is seated before downloading.

category keeps entries whose category, genre or kind contains the text (game, demo, platform…). unzip unpacks a downloaded .zip into the entry's folder — GetIt serves most games zipped and a Next cannot run a zip; unzip=false keeps the archive, as the tab's own Send does. Only download what you have the right to use.

NextSync servers

Tool Arguments What it does
nextsync_status — The NextSync side: the Remote Explorer listener (running, port, sync root, the Nexts seated), the classic Sync3/Sync4 server, and the HTTP bridge.
nextsync_listener_start sync_root? Start the Remote Explorer's NextSync listener (TCP 2048): a Next running .sync5 -L or ZX Next Remote's Listener then dials this PC and is seated for the next_* tools. Optionally sets the sync root first (the local folder the Remote Explorer's left pane shows). The classic server must not be running.
nextsync_listener_stop — Stop the Remote Explorer's NextSync listener: every seated Next is told to leave listen mode (the .sync5 dot returns to BASIC).
nextsync_set_sync_root path Set the NextSync sync root: the local folder the classic server sends and the Remote Explorer's left pane shows. Persisted.
nextsync_classic_start mode? (once / always) Start the classic NextSync server (Jari Komppa's protocol, TCP 2048): the Next runs .sync5 and pulls every changed file under the sync root. 'once' serves one sync and stops; 'always' keeps serving until nextsync_classic_stop. The listener must not be running. Returns at once; the transfer runs in the background.
nextsync_classic_stop — Stop the classic NextSync server.
nextsync_http_bridge_start port? Start the NextSync HTTP bridge (Flask; the web routes the Next's .http command, curl and the PowerShell module use), optionally on another port. Not persisted: the Settings toggle is left alone.
nextsync_http_bridge_stop — Stop the NextSync HTTP bridge.

The Nexts seated on the listener

Tool Arguments What it does
next_sessions — The Nexts seated on the listener: sid, address, friendly name and which one is active (the one next_* tools target by default).
next_select session Make a seated Next the active one (the Remote Explorer switches to it); the others idle on.
next_version session? Which program answers on a seated Next and its build: type 'sync' (the .sync5 dot), 'httpbridge' / 'n2n' / 'zxnt' (ZX Next Remote flavors), 'qlnextremote' / 'qlnt' (the QL jobs), plus its version number.
next_drives session? The drive letters mounted on a seated Next and the current one.
next_free drive?, session? Free space on a drive of a seated Next (bytes).
next_ls path? (default /), session? List a folder on a seated Next.
next_get remote_path, local_dir, session? Download a file - or a whole folder, recreated intact - from a seated Next into a local folder.
next_put local_path, remote_path, verify? (default True), session? Upload a local file - or a whole folder, recursively - to a seated Next, verifying each file by the CRC-32 the Next computes of it (or a read-back when the listener predates the crc op). A file whose bytes differ is reported as an error.
next_mkdir path, session? Create a folder on a seated Next.
next_rmdir path, session? Remove an EMPTY folder on a seated Next.
next_rm path, session? Delete a file on a seated Next.
next_rmtree path, session? Delete a folder and everything in it on a seated Next. No confirmation.
next_rename old_path, new_path, session? Rename or move a file or folder on a seated Next.
next_copy src, dst, session? Copy a file ON a seated Next (also across its drives, e.g. c:/a -> m:/a); ZX Next Remote copies files only, the dot and the QL jobs also folders.
next_size path, session? Total size of a file or folder tree on a seated Next (the .sync5 dot and the QL jobs answer; ZX Next Remote declines).
next_crc path, session? CRC-32 of one file computed ON a seated Next (8 hex digits; needs .sync5 5.9.2 / ZX Next Remote 1.0.8 / QLNextRemote 0.1.0).
next_exit session? Make a seated Next leave listen mode and exit its program (the .sync5 dot returns to BASIC; ZX Next Remote saves its settings and soft-resets into NextZXOS). With the autoexec loop on the card this is what RUNS a pushed build. The seat is freed.
next_deploy local_path, remote_path? (default /home/incoming.nex), verify? (default True), run? (default True), session? Push a build to a seated Next and run it - the extra/Send-ToNext.ps1 workflow in one call: upload local_path to remote_path, verify it (CRC-32 computed on the Next, else a read-back), then make the Next leave listen mode; with extra/autoexec.bas installed in /nextzxos the Next soft-resets, finds the file at /home/incoming.nex and .nexloads it. A build that does not verify is never run.

Paths on the Next and inside an image use forward slashes: /games/a.nex, c:/dot, m:/. Local paths are this PC's.

CSpect's own MCP server

CSpect 4.2.0 and later carries an MCP server behind -mcp[=port] (see its ReadMe.txt; in 4.5.0 it is a Patreon-build feature, so the public build opens no port for it yet). Settings → Start CSpect with its MCP server (under the CSpect launch parameters) makes every CSpect launch add -mcp=<port> — 2051 by default, next to the app's 2050 — and emulator_start accepts cspect_mcp / cspect_mcp_port to override it for one launch. The answer and emulator_processes name the port, so an agent can register CSpect's server as a second MCP server and drive the emulator itself (breakpoints, memory, keys) while driving the app through this one: two servers, two ports, at the same time. A -mcp typed into the launch parameters is replaced while the toggle is on; with it off, a typed one is yours and stays.

Options and files

Where What
hdfg.cfg mcp_server (true/false), mcp_port, mcp_token_enabled, mcp_token; cspect_mcp, cspect_mcp_port. Read by the tools: mame_rs232_esp, cspect_rs232_esp (9.7.58), mame_rs232_esp_port, the itch.io API key.
Downloads catalog_download puts GetIt entries under downloads/<title>/ in the app's data folder (or under dest_dir), itch.io entries under downloads/itchio/ — the folders the app's own buttons use.
Shim zx-next-unite-mcp [--url …] [--port N] [--token T] [--timeout S], or ZX_NEXT_UNITE_MCP_URL / ZX_NEXT_UNITE_MCP_PORT / ZX_NEXT_UNITE_MCP_TOKEN; zx-next-unite --mcp-stdio is the same shim from the app's launcher.
Help tab The MCP server (AI agents) section of the built-in Help repeats the setup in the UI's language.
Source zxnu_mcp.py (dispatcher, transport, shim, tools — stdlib only), zxnu_mcp_ops.py (the app side), docs/MCP_SERVER.md, tests/test_mcp_server.py.

Security

  • Loopback only; never reachable from another machine.
  • A browser page cannot reach it: an Origin header that is not loopback is refused (403).
  • The optional bearer token is compared in constant time; like the HTTP bridge's, it is stored in hdfg.cfg in plain text.
  • What an agent can do is what you can do from the app on this PC: it reads and writes local files you name, writes into the loaded image, and moves files to and from the Nexts seated on the listener. image_rm, next_rm and next_rmtree ask no confirmation.

Troubleshooting

Symptom Cause / fix
Claude Code says the server failed to connect The app is not running, or Enable MCP server is off, or the port differs from the one in the command — re-copy the command from Settings.
MCP server not started: port 2050 is already in use Another program holds the port: change Port (the server restarts a moment later) and re-copy the command.
Every tool answers HTTP 401 Require bearer token is on and the client's token is stale — re-copy the command, or untick it.
next_* tools say the NextSync listener is not running Call nextsync_listener_start first (a sync root is needed; pass sync_root=).
next_* tools say no Next is seated The listener is up but no Next has dialed in: run .sync5 -L (or ZX Next Remote's Listener) on the Next, pointed at this PC.
image_* tools say no disk image is loaded image_load (or image_download_nextzxos) first.
image_put is refused An emulator started from the app holds the image — emulator_stop it, or wait for it to exit.
catalog_* says itchio: not connected Enter your itch.io API key in the itch.io tab (the tab needs the optional itch-dl package). catalog_sources says what each catalogue allows right now.
catalog_download says the app does not offer downloads from ZXDB / zxArt Those catalogues can be searched, not downloaded — as in the app. catalog_detail gives the entry's page. GetIt and the itch.io items you own do download.
A catalog_search says it did not finish The catalogue did not answer in time, or a search started in the app at the same moment replaced the agent's. Retry. A source missing from the result's by_source simply did not answer.
The game landed on the card as a .zip unzip=false was passed, or the archive could not be unpacked (the result's notes say why). By default a downloaded zip is unpacked into the entry's folder.
catalog_send_to_next says no Next is seated Same as for next_*: start the listener and run .sync5 -L on the Next (real or emulated) first. Nothing is downloaded until a Next is there.
A tool waits and then says the app's window did not answer A modal dialog is open in the app (a confirm, a file picker); close it and retry.

Clone this wiki locally