# Building game UI with AI coding agents and MCP

> AI coding agents are good at wiring UI to game code and bad at rebuilding layouts from screenshots. Give them a machine-readable description of the UI (screens, events, data paths), a schema to validate against, renders to compare with, and tools such as an MCP server to edit the UI safely. Then keep their job to integration: set data, handle events, and check against the renders.

Source: https://envyui.com/blog/ai-agents-game-ui
Published: 2026-11-02

AI coding agents are now part of how a lot of indie games get made. Ask one to "add a pause menu" in Godot or Unity and it will write something that runs. Whether it looks like the design, works with a controller and survives the next design change is another matter. The pattern that works is to give the agent a clear contract and a narrow job.

## Where agents do well with UI

Agents are good at wiring: connecting a button's event to game code, setting a label from a variable, opening and closing panels. They handle boilerplate well too, like signal connections, saving settings and input remapping screens built from data. Repetitive edits are a good fit (forty inventory slots from one, a translation key on every label), and so is checking, such as reading a scene file and listing buttons without focus neighbors.

## Where they struggle

The weakest spot is rebuilding a design from a screenshot. Agents place nodes at hard-coded positions that look right at one resolution and break at the next, because anchors, containers and size flags need intent the picture doesn't show. Spacing, hierarchy and contrast are hard to verify from code. Focus order, hover and pressed styles, and what the screen does at 0 HP aren't in a screenshot at all. And every design change pulls the hand-built scene a little further from the design.

What helps is information the agent can't misread: names, types and pictures of the expected result.

## Give the agent a contract

A UI contract is a short, machine-readable list of what the UI needs from the game and what it sends back. Simplified, it looks like this:

```json
{
  "events": [
    { "name": "new_hunt", "from": "Main menu › New hunt" },
    { "name": "resume", "from": "Pause › Resume" }
  ],
  "data": [
    { "path": "player.hp", "type": "number", "sample": 72 },
    { "path": "inventory.items", "type": "array" }
  ]
}
```

With that, the agent's job is clear and checkable: handle each event, set each data path. It doesn't need to understand the layout, and a redesign that keeps the same events and paths doesn't change its code.

The other pieces that help:

| Give the agent | So it can |
|---|---|
| A contract of events and data paths | Write integration code without guessing names |
| A JSON Schema for the UI file | Validate any edit it makes |
| A render of each screen | Compare its result with what the designer made |
| An instructions file (AGENTS.md) | Follow your rules: don't rebuild screens, where files go, how to test |
| Docs in plain Markdown, or `llms.txt` | Read the API without scraping a web page |
| A validate command | Fail loudly instead of shipping a broken file |

## MCP: tools instead of raw files

The [Model Context Protocol](https://modelcontextprotocol.io) lets an agent call tools that a program exposes, instead of editing files blind. For game development there are already several Godot MCP servers that let an agent inspect scenes, edit nodes, run the project and take screenshots. They're useful for general engine work. Check each one's supported Godot version, how actively it's maintained, and what it's allowed to touch.

For UI, a narrower server is safer. An agent that can only call `add_instance`, `patch_node` or `set_translation`, with every edit validated before it's written, can't leave a half-broken scene behind. See our [Godot MCP setup guide for Claude Code and Codex](/blog/godot-mcp-setup-claude-code-codex) for the full configuration and how to pair a scene server with a UI server.

## A workflow that holds up

1. **A person designs the UI** in a visual tool, with the states, focus order and sample data.
2. **The UI is a file the game loads.** The agent never rebuilds it by hand.
3. **The agent gets a handoff package:** the file, the contract, renders, a schema, and an AGENTS.md with the rules.
4. **The agent writes the integration:** sets data, handles events, adds tests.
5. **The agent checks its work** against the renders and runs validation.
6. **You review the diff,** as with any other code.

When the design changes, steps 1 and 2 happen again, and step 4 usually doesn't.

## How Envy does this

[Envy](/) was built around this workflow. **Hand off › AI handoff package** writes a zip with `AGENTS.md`, `contract.json` (every event, the layer that emits it, every data path with its type and sample), a render of every screen plus each scenario's changed screens (on by default, at half or full size, and you can [export without them](/docs/handoff)), typed controller code for Godot, Unity (C#) and TypeScript, the runtimes, the JSON Schema, a CLI and an MCP server with a ready `mcp.json`.

The MCP server runs on Node with no dependencies. Agents use tools like `read_outline`, `describe_screen`, `add_instance`, `patch_node`, `set_translation`, `validate_document` and `render_screen_png`. Each edit is checked against the schema and the document checks before it's written, and a failing edit is refused with the reasons, leaving the file as it was. For Claude Code in a game project, the setup is a few lines of `.mcp.json`:

```json
{ "mcpServers": { "envy": { "command": "node", "args": ["tools/envy-mcp.mjs", "ui/menu.envy.json"] } } }
```

The site also publishes [llms.txt](/llms.txt) and every docs page as Markdown, so an agent can read the docs directly. The [agents docs](/docs/agents) list every tool and the rules the handoff package gives the agent.

## Questions people ask

### Can Claude Code or Codex build a Godot UI?

They can write Control scenes and scripts, and Godot MCP servers let them inspect and edit a running editor. Connecting an existing UI to game logic is the safer job of the two: the event names and data paths are given, and the result either runs or doesn't. Rebuilding a visual design from an image is not checkable that way, because the anchoring and container rules it has to get right are not in the picture.

### What is an MCP server in game development?

The Model Context Protocol lets an AI agent call tools that a program exposes. A Godot or Unity MCP server can open scenes, edit nodes and run the game. A UI-specific one, like Envy's, can read and change a UI document with validation before each write.

### How do I stop an AI agent from breaking my UI?

Keep the UI in a file the agent loads rather than rebuilds, validate every edit against a schema, review changes as diffs in version control, and give the agent screenshots of the expected result to compare with.

### Which Godot MCP servers exist?

Several community servers exist for Godot 4, with different scopes: editor control, scene editing, running the game and taking screenshots. Check each one's Godot version, maintenance and permissions before connecting it to your project.
