# The protocol

Anything you can do to your game by hand, a program can do too. A running game answers
commands: the editor, the command line and an AI agent all send the same ones, and none
of them has a private way in. About a hundred commands step the game, hold its input,
read and write its world, swap a script, capture a frame, explain a pixel, debug,
profile and test a change. [Every command](../reference/protocol-commands.md) is
listed in the reference.

## Three ways to connect

| Command | Serves |
| --- | --- |
| `frost serve game.toml` | JSON-RPC 2.0, one object a line, on standard input and output; `--port N` on a TCP port of 127.0.0.1 instead |
| `frost mcp game.toml` | The same commands as MCP tools for an AI agent (dots become underscores: `frame_capture`) |
| `frost dev game.toml` | A window to play in, with the protocol on a local port beside it, so an agent can read, drive and capture the game while a person plays |

`frost protocol` lists every command; `frost protocol world.get` describes one in full.

## A conversation

Against the basics example (from the engine's examples, shipped at launch), one request a
line in and one answer a line out:

```sh
frost serve basics/game.toml
```

```json
{"jsonrpc":"2.0","id":1,"method":"game.step","params":{"steps":60}}
{"id":1,"jsonrpc":"2.0","result":{"checksum":"a3728cc2465e2d08","reached":false,"step":60,"stopped":null}}
{"jsonrpc":"2.0","id":2,"method":"world.get","params":{"entity":"hero","component":"Transform"}}
{"id":2,"jsonrpc":"2.0","result":{"components":{"Transform":{"x":40.0,"y":90.0}},"entity":"e1.0"}}
{"jsonrpc":"2.0","id":3,"method":"game.seek","params":{"step":150}}
{"id":3,"jsonrpc":"2.0","result":{"checksum":"504a4a5a1e5ef03f","from":0,"replayed":150,"started":"load","step":150,...}}
{"jsonrpc":"2.0","id":4,"method":"script.state","params":{}}
{"id":4,"jsonrpc":"2.0","result":{"kinds":{},"states":{"main.luau":{"score":5}},"step":150}}
```

`game.step` advanced 60 steps on the input `input.set` holds (none here, so the hero
stood still); `game.seek` played the project's recording to step 150 instead, where the
coin has been picked up.

## The commands by what they are for

| For | Commands |
| --- | --- |
| Where the game stands | `game.info`, `world.entities`, `world.components`, `world.get`, `script.state` |
| Driving it | `input.set`, `game.step`, `game.seek`, `game.time`, `game.reset` |
| Changing it | `world.set`, `world.spawn`, `world.despawn`, `world.apply`, `script.reload`, `tuning.set` |
| Seeing it | `frame.capture`, `frame.at` (what is drawn at a pixel, and how it is lit), `render.passes` |
| Trying things | `game.snapshot`, `game.restore`, `game.try` (play a branch of input from a snapshot in one call) |
| Explaining it | `blame.on`, `blame.value`, `blame.pixel`, `events.since`, `log.since`, `profile.steps` |
| Debugging scripts | `debug.attach`, `debug.breakpoints`, `debug.step`, `debug.stack`, `debug.evaluate` |
| Changing files safely | `copy.make`, `change.test`, `copy.land`, `project.undo` |
| Who is connected | `session.hello`, `session.hands`, `session.mode` |

## You and an agent on one game

`frost mcp --join-file PATH` serves the tools for a session that is already running (the
editor's, or a `frost dev` window), so you and an agent act on one game. Each client
can say who it is (`session.hello`), and every write then names it: `blame.value` answers
that a client wrote a field, and which one. You can hold an agent to reads only in the editor
(mode `plan`): every command that would change the game is then refused with `E0447`,
naming what was tried. An agent that changes files works on a copy of the game, tests
the copy against what it said it would change (`change.test`), and lands it; a landing
can be undone on its own ([undoing a landing](../guides/undo-landing.md)).

Requests are carried out one at a time in the order they arrive, so two clients never
see half a step.
