Expand description
shuyi mcp: the tool contract as an MCP server over stdio (ADR-0005
§2, ADR-0031), and shuyi mcp install, which registers it with the
agents it finds (install).
Each operation of the contract is a tool, its input the operation’s
input (crate::contract::op_schemas), its answer the operation’s
Answer. The tools that run the game take
project, the game’s folder, from the session’s folder (the client’s
first root, or the server’s working folder); the session folder’s own
project if it is left out. A project in another cargo workspace than
the server’s is answered by that workspace’s own server (forward).
A session keeps one game running headless between calls, so an agent can play it, look at it and play on:
| Tool | Does | Answers as |
|---|---|---|
start | builds the game’s tool program and starts its game as its options say | StartOutput |
step | plays a script, then runs idle frames | run’s answer |
scene | the scene on screen now; with path one value of its data, with shape its shape | scene’s answer |
frame_png | a picture of the frame now, as an image | FramePngOutput and the PNG |
events | what happened since the start | EventsOutput |
perf | the frames’ records since a number, and their summary; a heap snapshot and a diff between two | PerfOutput |
reset | the game started again as start started it | StartOutput |
stop | the game stopped | StopOutput |
start with session starts from a session record instead, played to
its end, and reset plays it again.
start with link attaches the session to a debug build already
running in its window instead, over the live link (attached).
The one-off scene operation is the session’s scene here: run
answers with the scene of a one-off run.
The server runs no game itself. A tool that runs the game runs it in
the game’s tool program (shuyi.ron’s game), started with cargo run as shuyi mcp-host (host); the session keeps that program
running until stop, so start builds the game’s latest code. A
failed answer is an MCP error result with the answer as it is, its
code and its help.
Modules§
- aside
- A running server’s program moved aside, so the next build can write a fresh one (ticket 2545).
- attached
- The session over the live link (ADR-0047):
startwithlinkattaches the session to a debug build already running in its window, and the session tools play a player’s input on it and read it asattachdoes, throughattach’s own connection. Nothing else in the build changes:resetis refused, andstopdetaches and leaves it running. - child
- The game’s tool program as the server’s host:
cargo runof the programshuyi.ronnames, asshuyi mcp-host, with pipes to its stdin and stdout. What it writes to stderr (the compiler’s errors, a panic) goes on to the server’s stderr, and its last lines go into the error when it stops before it answers. - forward
- The projects’ own servers (ticket 2546): a call whose project is in
another cargo workspace than the server’s goes to a
shuyi mcpbuilt from that workspace’s engine, a forwarded server, so an agent in a worktree plays and checks the worktree’s code, whichever checkout the client started the server in. - host
- The game’s side of
shuyi mcp:shuyi mcp-host, run in the game’s tool program, answers the server’sRequests, one JSON line each on stdin, with aReplyline each on stdout, after the markREPLY. It answers the operations that run the game with the game’s tools, and keeps the session’s game (Host). - install
shuyi mcp install: registers the server with the agents it finds, in each one’s project file of MCP servers, in the project’s folder (or the working folder outside one). It shows what changes and asks before writing, and keeps each file it changes as<file>.bak, then runs the entry it wrote with--ready, so the server is built before an agent first connects and waits for it.--dry-runwrites nothing and prints each file as it would write it.- server
- The MCP server: JSON-RPC 2.0 messages, one per line (
Server::handle), the methodsinitialize,ping,tools/listandtools/call, and the session.
Structs§
- Events
Output - What
eventssaw. - Frame
PngInput - How
frame_pngpaints the frame. - Frame
PngOutput - What
frame_pngpainted (the picture itself is the tool’s image). - NoInput
- A session tool’s input that takes nothing.
- Perf
Input - Which of the session’s frames’ records
perfreads. - Perf
Output - What
perfread of the session’s frames. - Scene
Input - What the session’s
sceneanswers beyond the scene: one value of its data, or its data’s shape, either in place of the scene. - Start
Input - What
startstarts. - Start
Link - The running build
startattaches to: its log lineshuyi link: listening on <address>, token <token>gives both. - Start
Option - A start option the game offers.
- Start
Output - What
startandresetstarted. - Step
Input - What
stepplays. - Stop
Output - What
stopstopped.
Constants§
- KEPT_
SNAPSHOTS - How many heap snapshots a session keeps for
perf’sdiff_from: the last, by frame. - PERF_
MAX - How many records
perfanswers when its input doesn’t say.
Functions§
- base64
bytesin standard base64, with padding: how MCP carries an image.- main
shuyi mcpwithargs, in the working foldercwd: the server on this process’s stdin and stdout, orinstall. Returns the exit code.- serve
- Serves MCP messages from
input, one per line, writing each message the server has for one on a line of its own, and the notification that its tools changed when they do (server::Server::poll), untilinputends. - takes_
project - Whether the tool of
optakesproject: the operations that run the game, andlint,modulesandadd. - tool
- The tool named
name: its operation, and whether it is a session tool (Op::SESSION). - tools
- Every tool, as
tools/listlists them: the operations (Op::ALL, the one-offsceneleft out), then the session’s (Op::SESSION). - usage
- The usage of
shuyi mcp, withcommandas the tool’s name.