For AI coding agents
Envy is built so a coding agent can wire a UI into a game from the document and its contract. This page is for people who work with agents, and for the agents themselves. For the workflow from the outside (design the screens, export the handoff, paste the prompt), see Envy for coding agents.
If you are an agent
- Read
AGENTS.mdin the handoff package first. It lists the files, the rules, the integration steps for Godot, Unity and the web, and the acceptance checklist. - Load the document with the runtime. Never rebuild screens by hand. The
.envy.jsonfile (or a.envyproject) is the UI. - Your job is the integration: set data with
set_data/SetData/setData, and handle the events incontract.json. - Check your work against
screens/(one render per screen, and per scenario). - If you edit the document, validate it:
node tools/envy.mjs validate <file>, or call thevalidate_documenttool when the MCP server is connected. The JSON Schema is inschema/envy.schema.json.
What agents get
| Source | Use it for |
|---|---|
| AI handoff package | Everything for one UI: instructions, contract, renders, typed code, runtime, schema, CLI, MCP server |
contract.json |
Every event (and the layer that emits it) and every data path (type, sample, where it’s used) |
| CLI | validate, describe, contract, prompt, handoff, schema, pack, unpack, inline |
| MCP server (below) | Read and edit the document through tools, with validation before each write |
| /llms.txt | An index of these docs for language models |
| /llms-full.txt | All docs in one plain-text file |
/docs/<page>.md |
Each docs page as Markdown, for example /docs/data.md |
The MCP server
tools/envy-mcp.mjs is a Model Context Protocol server. It runs over stdio on Node 20.12 or newer, with no dependencies. An agent uses it to read and change a document with tools instead of raw JSON.
node tools/envy-mcp.mjs [file.envy.json | file.envy] [--root <folder>] [--readonly]
The server only opens .envy.json and .envy files inside its root folder, up to 256 MB each. The root is the folder it runs from, or the one --root names.
The AI handoff package includes the server with a ready mcp.json. It runs from the folder you unzipped the package into, with the package folder as the root:
{ "mcpServers": { "envy": { "command": "node", "args": ["my_ui_handoff/tools/envy-mcp.mjs", "ui/my_ui.envy.json", "--root", "my_ui_handoff"] } } }
To use it elsewhere, add it to the agent’s MCP settings. For example, this is .mcp.json for Claude Code in a game project:
{ "mcpServers": { "envy": { "command": "node", "args": ["tools/envy-mcp.mjs", "ui/menu.envy.json"] } } }
| Tool | What it does |
|---|---|
read_outline |
Screens and their layers, with ids. Start here |
describe_screen |
What a screen does: text, bindings, events and navigation |
get_node |
One layer as it is stored |
list_components |
The kit components: variants, size, properties and how often each is used |
patch_node |
Set or remove fields. All the changes apply, or none do. It also sets text.runs, text.fit and text.minSize, control, states, tooltip, events (click, enter, leave, hover) and sounds. A layer’s id, parent, children and type can’t be patched |
add_node, delete_node |
Add a layer to a frame or button, with its fields set at creation, or delete a layer and what is inside it |
add_instance |
Place a kit component, with property values and changes to its layers |
move_node, duplicate_node |
Move a layer into another frame or change its order; copy a layer with new ids and working references |
add_screen |
Add an empty screen |
import_svg |
Add an SVG as layers |
add_sound |
Add a .wav, .ogg or .mp3 file from the server’s folder (sound_file, and an optional name) to the document’s sounds, and return its id. 8 MB at most, and the file must be that format. The same file is added once |
patch_animation |
Change or create an animation: length, loop, autoplay and keyframes, including tracks on fill, radius, width, height and gradient stops (stop0 to stop7, stopAt0 to stopAt7) |
set_token, set_text_style |
Create or change a colour token (rename it everywhere, delete it when unused) or a text style |
set_translation |
Write one translation for one language |
list_contract |
The events, data paths, screens, animations and scenarios |
validate_document |
The same checks as envy validate, expression checks included, listing up to 60 issues |
render_screen_png |
A PNG of a screen, drawn by the web runtime in headless Chromium, optionally with a scenario, data, a language or a point in time |
To give a button a sound, call add_sound with a file in the server’s folder, then patch_node to set sounds.press to { "asset": "<the id it returned>" } on a button, or to add a sound action to its events.click. add_sound refuses a file that would take the embedded images and sounds past 64 MB. A .envy project stores the sound as a file.
Each edit is checked before anything is written. An edit that breaks the schema or adds a validation error is refused with the reasons, and the file stays as it was. Each call reads the file again, so changes made in the editor or by hand are never overwritten with stale data. Start the server with --readonly to hide the editing tools.
render_screen_png needs two things:
- The web runtime:
envy-runtime.jsnext to the server, in../web/(where the handoff package has it), or at the path in theENVY_RUNTIMEenvironment variable. - Playwright with Chromium: installed with the server, in the root folder’s
node_modules, or in the folder thatENVY_PLAYWRIGHTnames. Runnpm i playwright && npx playwright install chromiumto add it.
The render shows the screen at rest, with no animation unless you give a time, and loads nothing from the network. Images and fonts must be in the document or the .envy project; a font that isn’t embedded shows in a fallback font.
Changes land in the file itself, so review them the way you review other code, with version control and a diff.