Skip to main content
Glama
README.md
<p align="center"><img src="docs/icon.svg" width="128" height="128" alt="ps2mcp's icon: a console with a spark above it"></p>

# ps2mcp

**A PlayStation 2 that an AI agent can work with: ps2mcp is to an agent what ps2link is to a
developer.** It runs programs on a console and reports how they ended, reads and writes the
hardware's memory and registers, times what the hardware does, and takes pictures of what's on
the screen. It speaks the [Model Context Protocol](https://modelcontextprotocol.io), so any MCP
client can use it.

ps2link assumes a person: eyes on the television, output scrolling by, a finger on the reset
button. An agent has none of those, so ps2mcp gives it what they stood for:

| A developer has | An agent gets |
|---|---|
| Eyes on the television | `screenshot`: the picture, as an image |
| Output scrolling by | `run`: a program's outcome as data: what it printed, how it exited, or the exception and registers it died with |
| A feel for when it's hung | A bound on every wait, and `stop` and `reset` to recover |
| A controller in their hands | `controller`: buttons pressed and sticks moved, on a controller the program finds plugged in |
| A program written for each question | `read_memory`, `write_memory` and `measure`: the hardware asked directly |
| A notebook | A journal of every request to the hardware and its answer, with the console it came from |

It's meant for two kinds of work: **developing** software for the PS2, and **finding out what
the hardware does** so that it can be written down.

<p align="center"><img src="docs/screen.png" width="640" height="448" alt="A console running ps2mcp: what console it is, its address, the network's modules, how the last program ended, and that it's waiting for the next"></p>
<p align="center"><em>What a console running ps2mcp shows, as its own <code>screenshot</code> tool took it.</em></p>

## Status

This is version 1.0.0. Everything below has run on a PlayStation 2, a SCPH-30001, over its
network adapter, and on that one console only: another model, or another BIOS, may yet have
something to say. [The wire protocol](docs/protocol.md) is at version 1.0.

- **Programs.** An ELF for the EE or a module for the IOP is loaded from the host and started,
  a small one printing in a quarter of a second. Its `host:` files come from the host, and
  what it prints goes there, without what the console's own modules say of loading it.
- **How a program ended.** Its exit code, or the exception it died of with its registers. The
  console is ready for the next program 0.4 s after the last was asked for: 300 were run one
  after another.
- **Recovery.** `stop` takes the EE back from a program that's spinning or asleep in 0.1 s.
  `reset` starts the console's side afresh, IOP and all, in 6 s, wherever the loader is: a
  loader left waiting on the IOP between programs is brought back too.
- **Memory.** The EE's address space and the IOP's, the kernel's addresses and the hardware's
  registers included, in accesses of exactly the width asked for, while a program runs or
  none does. An access that faults is answered with FAULT.
- **Measuring.** `measure` runs a sequence of reads, writes, delays, waits and calls back to
  back on the EE, timed by its cycle counter at 61 cycles a step, or on the IOP, timed by its
  system clock. Interrupts are off if asked.
- **The picture.** `screenshot` reads back what's being shown, or any rectangle of the GS's
  memory, as it was at one moment: 640 by 448 in 2.4 s. `display` gives the GS's display
  registers, which can't be read from the GS: the loader follows each write to them.
- **Debugging.** A program is held at a `breakpoint`, at its first instruction, where it
  would have crashed, wherever it is when `halt` is called, or at the instruction about to
  touch an address a `watchpoint` is on, with everything of it kept: its `registers` read and changed, its
  memory too, `step` for an instruction at a time, `resume` to send it on.
- **The controller.** `controller` puts a DualShock 2 in a port and presses its buttons:
  a program reading it through the console's padman or PS2SDK's finds it there, sticks and
  pressures too, whatever is really plugged in.
- **Starting by itself.** From a memory card, with no ps2link and no host: `ps2mcp.elf` and
  an `IPCONFIG.DAT` beside it are all the console needs.
- **New builds.** `scripts/update-console` puts one on a running console over the link in
  about five seconds.

### What it can't do

- **A program that resets the IOP** takes ps2mcp's module with it, as it takes ps2link: the
  console's reset button is needed after. Most games do, so they're out of reach. So is the
  button needed after a program that keeps interrupts off and never ends, one that writes over
  the loader at the top of memory (0x01a00000 and up), and an IOP that dies of an exception
  outside a caught access.
- **The debugger is the EE's.** There's none for the IOP, and VU1's registers aren't given. A
  breakpoint or a crash inside a program's own interrupt handler can't be held, and hangs
  the console. `halt` holds code below 16 MiB, when one of the program's threads next runs.
- **The controller** is found by a program that reads it through the IOP's sio2man, as the
  console's padman and PS2SDK's do. There's no multitap, and the later XSIO2MAN and XPADMAN
  haven't been tried.
- **Speed.** Memory, sequences and pictures on the EE are answered at a vertical blank: 17 ms
  a request, half a megabyte a second for a block.
- **Starting from a USB drive hasn't been tried.** From a memory card it works, the address
  read from the `IPCONFIG.DAT` beside the program.
- **An emulator can't be a target yet**, and memory cards and discs aren't reached: see the
  plan.

## Getting started

### With no console

```sh
git clone https://github.com/ooPo/ps2mcp
cd ps2mcp
python3 -m venv .venv
.venv/bin/pip install -e '.[dev]'
.venv/bin/pytest
```

The mock target answers the protocol with no console behind it. To give it to an MCP client,
have the client start `.venv/bin/ps2mcp --target mock`. For Claude Code:

```sh
claude mcp add ps2mcp -- "$PWD/.venv/bin/ps2mcp" --target mock --root "$PWD"
```

### With a console

A PlayStation 2 with a network adapter, and some way of starting homebrew on it.

```sh
scripts/build-console        # needs Docker
```

builds these into `build/console`; [a release](https://github.com/ooPo/ps2mcp/releases) has
them already built, in one archive. The
first two are all the console needs:

| File | |
|---|---|
| `ps2mcp.elf` | ps2mcp, with the network's modules inside it |
| `IPCONFIG.DAT` | The console's address, netmask and gateway, as one line of text: `192.168.0.10 255.255.255.0 192.168.0.1`. Change it to the console's own |
| `icon.sys`, `ps2mcp.icn` | Only for a folder of ps2mcp's own at the top of a memory card: with these beside the other two, the console's browser shows the folder as ps2mcp, with its icon, where it would say the data is corrupted |

Put the two together where the console's programs are kept (a folder on a memory card, a USB
drive) and start `ps2mcp.elf` as any other program is started there. The television shows the
picture above, with the address the console is listening on and where it had it from. An
`IPCONFIG.DAT` that ps2link already uses, in `mc0:/SYS-CONF`, is found too if there's none
beside the program, and it's the same format.

Then give the console to an MCP client:

```sh
claude mcp add ps2mcp -- "$PWD/.venv/bin/ps2mcp" --target 192.168.0.10 --root "$PWD/build/console/tests"
```

and the agent can be asked to run `hello_ee.elf`, one of the test programs built into
`build/console/tests`.

A console that's running ps2link can be given ps2mcp over the network instead, with nothing
copied to it: `scripts/start-from-ps2link <address>` sends `ps2mcp.elf` to ps2link, which it
takes the place of, at the address the console already has. And `scripts/update-console
<address>` puts a new build on a console that's already running ps2mcp, without a reset; that
one lasts until the console is next switched off.

The build uses PS2SDK in the pinned `ps2dev/ps2dev` Docker image (`scripts/ps2dev` runs a
command in it).

### The server's arguments

| Argument | |
|---|---|
| `--target` | A target's address, `address[:port]`, or `mock`. It has no default: nothing is sent to a console that wasn't named |
| `--root` | The folder programs are run from and the target's `host:` files are served from |
| `--journal` | The journal's file: `~/.local/state/ps2mcp/journal.jsonl` by default, `none` for none |

## The tools

| Tool | What it does |
|---|---|
| `status` | What the target is, what it can do, and what the program on it is doing |
| `read_memory`, `write_memory` | Values of 1, 2, 4, 8 or 16 bytes, each with one access of exactly that width: for hardware registers, in the EE's address space or the IOP's |
| `dump_memory` | A block of memory as a hex dump, or saved to a file |
| `measure` | A sequence of reads, writes, delays, waits and readings of the cycle counter, run back to back on the target with no traffic to the host between them |
| `run` | Runs an ELF on the EE or a module on the IOP, and waits for it to end or to print a given text: exited, crashed (with the exception), loaded, or still running |
| `output` | What's been printed since last asked |
| `stop`, `reset` | Ends the program; puts the target back as it starts |
| `breakpoint`, `halt`, `resume`, `step` | Holds a program at an instruction, or wherever it is; sends it on; steps it an instruction at a time |
| `watchpoint` | Holds a program when it loads from or stores to an address, or only when it's a given value: what touches a variable, or a hardware register |
| `registers`, `set_register` | A held program's registers, read and changed: the general ones, the FPU's, COP0's, VU0's |
| `controller` | Presses buttons and moves sticks on a controller the program finds in a port, whatever is plugged in |
| `screenshot` | The picture being shown, or a rectangle of the GS's memory |
| `display` | The GS's display registers as the program has written them |

A target says which of these it can do. A console can't save its state, and an emulator can; the
mock can't call code. `status` lists them.

## On the console

`ps2mcp.elf`, the loader, restarts the IOP, loads the network's modules and `ps2mcp.irx` from
inside itself, and then stays, high in memory, to load the programs it's given and to take the
EE back when one ends, crashes or is stopped. `ps2mcp.irx`, the module resident on the IOP,
answers the protocol over TCP and serves the IOP's side itself. The comments at the top of
`console/ee/loader.c` and `console/iop/ps2mcp.c` say how each part works.

The console's address is the loader's arguments, or `IPCONFIG.DAT`'s, looked for beside the
loader and then in `mc0:/SYS-CONF`, where ps2link keeps its own.

The loader can be tried in an emulator before a console. One found a write through a null
pointer that a PS2 showed only as an exception on its screen. `build/console/tests/preview.elf`
is the loader's screen alone, for looking at in one.

## How it's put together

```
  MCP client  <--MCP, stdio-->  ps2mcp (Python, on the host)  <--the wire protocol, TCP-->  a target
  (an agent)                    tools, files, journal                                     console, emulator or mock
```

Anything that answers the wire protocol is a target, so the host has one way of talking to all
of them:

- **A console**, running the loader and the module in `console/`.
- **An emulator** with the protocol built in as a debug server, or running the console's side
  as a guest. Not yet written.
- **The mock** (`src/ps2mcp/mock.py`), for building the host's side and trying clients.

| File | What it is |
|---|---|
| `src/ps2mcp/protocol.py` | The protocol's numbers and framing |
| `src/ps2mcp/session.py` | The host's end of a link: requests, events, the journal |
| `src/ps2mcp/hostfiles.py` | The target's `host:` files, kept inside one folder |
| `src/ps2mcp/sequence.py` | `measure`'s steps, to bytes and back |
| `src/ps2mcp/server.py` | The MCP server and its tools |
| `src/ps2mcp/mock.py` | The mock target |
| `console/protocol.h` | The protocol's numbers, for C |
| `console/iop/ps2mcp.c` | The module resident on the IOP |
| `console/ee/loader.c`, `entry.S` | The loader, and what of it stays with a running program |
| `console/ee/screen.h`, `icon.h` | What the loader shows on the television |
| `console/ee/update.c` | Replaces a running ps2mcp with a new build |
| `console/tests/` | Small programs that exit, crash, hang, read a file, write to the display, read the controller, use the FPU and VU0, touch hardware registers and wait to be debugged, to try the tools with |
| `scripts/build-console`, `scripts/ps2dev` | Build the console's side in the pinned toolchain image |
| `scripts/start-from-ps2link` | Starts ps2mcp on a console running ps2link |
| `scripts/update-console` | Puts a new build on a console already running ps2mcp |
| `console/card/` | What the console's browser shows for ps2mcp's folder on a memory card |
| `scripts/make-icon` | Draws the icon, for this page, for the television and for a memory card |
| `scripts/make-release` | Gathers what a console needs into one archive |

## The plan

In 1.0, and in [the changelog](CHANGELOG.md):

1. **The protocol and the host's side**, against a mock.
2. **The console's side**: a loader and a module resident on the IOP with the network, programs
   run with their outcomes and crashes reported, `host:` files and console output as programs
   written for ps2link expect them.
3. **A resident on the EE**: memory and registers reached while a program runs, sequences, code
   called, the picture read back from the GS.
4. **A debugger**: breakpoints, steps, registers, a running program halted, a watch on an
   address or a value, and a crash held to be looked at.
5. **The controller** pressed from the host.

Not in 1.0:

- **An emulator as a target**, so the tools work end to end on PS2 code with no hardware, and
  what a console does can be set beside what an emulator does. It wants designing with an
  emulator's authors, not adding on.
- **Memory cards and discs** behind a switch that's off by default, and hardware notes
  served beside the tools.
- **More consoles.** Reports of other models are welcome: `status` says what a console is.

## Licence

[BSD 3-Clause](LICENSE).

TDQS

A3.9/5.0

Scored across 19 tools

Disambiguation4/5

Tools mostly target distinct operations, and descriptions explicitly separate easily confused pairs such as read_memory vs dump_memory and run vs resume. Minor overlap remains around execution control (halt/stop) and memory/register access, but boundaries are workable.

Naming Consistency4/5

All names are lower_snake_case with no casing or style collisions. The set mixes verb names (resume, step, read_memory) with resource nouns (registers, display, controller), so it is readable but not a strict verb_noun convention.

Tool Count4/5

Nineteen tools is somewhat heavy but justified for a full PS2 debug/emulation surface: execution control, memory, registers, break/watch, measurement, display, screenshot, and input are distinct responsibilities. It is above the typical 3-15 range but not bloated.

Completeness4/5

The surface covers the core lifecycle: status, run/resume/step/halt/stop/reset, breakpoints/watchpoints, register and memory access, screenshots, display state, and controller input. Minor gaps such as disassembly, memory search, or save-state management are workarounds rather than fatal omissions.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues