Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

AI assistants and MCP

The Model Context Protocol (MCP) is an open standard that lets an AI assistant use tools offered by another program. The assistant’s side is called the MCP client. NNBuild can be the other side, the MCP server.

NNBuild offers MCP in two ways.

You want the assistant toUseStart NNBuild with
Join a live editing session as one more participantThe participant adapter--editor-mcp
Control a game, a server or the editor on this machineThe built-in control endpoint--mcp-stdio or --mcp-http

Both speak MCP over one of two transports:

  • stdio. The MCP client starts NNBuild itself and talks to it through the program’s standard input and output.
  • HTTP. NNBuild listens on a local web address and the client sends requests to it.

Join a live session as a participant

The participant adapter is a small process with no window. It joins a live session like a person would. The others see it in the Participants list with its own colour and the mark “(AI)”. Its pointer and its selection are visible in their Plan view. Its changes appear in the shared change history and can be undone like anyone else’s.

  1. A person hosts a session in the editor.
  2. The MCP client starts the adapter:
./vibebuild32 --editor-mcp 127.0.0.1:23514 --name "Layout Assistant"

The form of the command is:

vibebuild32 --editor-mcp [host[:port]] [--name name] [--mcp-http port]
PartMeaningIf left out
host[:port]Address of the session host127.0.0.1, port 23514
--name nameThe name the others seeAI Editor
--mcp-http portUse the HTTP transport on this portstdio is used

Good to know:

  • The adapter tries to join when it starts. If the session is not up yet, the assistant can join later with the editor_connect tool.
  • Use one adapter process for each AI participant.
  • The adapter does not choose a game and does not load game data. It starts at once and never asks a question. It may run on a different machine than the host.
  • An AI participant does not have to match the host’s game edition.
  • Only the parts shown above may follow --editor-mcp. Any other option after it makes the adapter stop with a usage message.

Example: stdio client for the adapter

Most MCP clients keep their servers in a JSON block like this one. Use the full path of the program.

{
  "mcpServers": {
    "nnbuild-live": {
      "command": "/full/path/to/vibebuild32",
      "args": [
        "--editor-mcp", "127.0.0.1:23514",
        "--name", "Layout Assistant"
      ]
    }
  }
}

The name of the file and of the keys can differ between MCP clients. Check your client’s documentation.

Control a game, a server or the editor

Add --mcp-stdio or --mcp-http PORT to a normal launch. The game then offers tools to read its state, type console commands, send input, and drive the editor and its projects.

./vibebuild32 -gamegrp /path/to/DUKE3D.GRP --editor --mcp-stdio
./vibebuild32 -gamegrp /path/to/DUKE3D.GRP --editor --mcp-http 8787
  • With --editor the program starts in the editor. Without it, the assistant can open the editor with editor_control and the action enter.
  • Add -sm to skip the startup window, if your setup shows one.
  • The assistant acts as the local user. Offline, its edits are listed in the change history under the name “Assistant”. In a live session, it uses the local participant’s place.
  • When the assistant points at something, a pointer labelled “Assistant (AI)” appears in Plan.
  • With --mcp-stdio, the program’s own text output goes to standard error. Standard output is kept for MCP.
  • The options also work on a multiplayer server. Add them to the server’s normal launch options. A dedicated server normally reads admin commands from standard input. With --mcp-stdio it does not, so send them with console_execute.

Name the game

When data for several games is installed and the command line names none of them, NNBuild normally asks on the console which game to start. It does not ask when --mcp-stdio is given. It also does not ask when its standard input is not a terminal, which is usual when another program starts it. In both cases it starts the first game it finds.

To be sure that the right game starts, name it in one of these ways:

  • Add --game with the game’s name, for example --game duke. Other names are worldtour, nam, napalm and ww2gi.
  • Give the game’s data file, for example -gamegrp /path/to/DUKE3D.GRP. NNBuild recognises the game from a known data file.

Example: stdio client for the game

{
  "mcpServers": {
    "nnbuild": {
      "command": "/full/path/to/vibebuild32",
      "args": [
        "--game", "duke",
        "-gamegrp", "/path/to/DUKE3D.GRP",
        "--editor",
        "--mcp-stdio"
      ]
    }
  }
}

Replace duke and the data file with those of the game you run.

Example: HTTP client

Start NNBuild yourself, with a token:

VIBEBUILD_MCP_TOKEN=change-this-token ./vibebuild32 -gamegrp /path/to/DUKE3D.GRP --editor --mcp-http 8787

Then point the client at the address and give it the same token:

{
  "mcpServers": {
    "nnbuild": {
      "type": "http",
      "url": "http://127.0.0.1:8787/mcp",
      "headers": {
        "Authorization": "Bearer change-this-token"
      }
    }
  }
}

The HTTP endpoint

With --mcp-http PORT, NNBuild listens at:

http://127.0.0.1:PORT/mcp

It listens on the local machine only. A program on another machine cannot reach it. If a remote client must connect, put your own HTTPS proxy with a login in front of it.

Environment variables

VariableEffect
VIBEBUILD_MCP_TOKENWhen set, every request must carry the header Authorization: Bearer followed by this value. Other requests get the answer 401.
VIBEBUILD_MCP_ORIGINOne extra value that is allowed in the Origin header of a request.

Token. Without a token, any program on the same machine can call the tools. The tools can run console commands and write files, so set a token.

Origin. Web browsers add an Origin header to requests. NNBuild accepts a request with no Origin header. If the header is present, it must be http://127.0.0.1:PORT, http://localhost:PORT, or exactly the value of VIBEBUILD_MCP_ORIGIN. Other origins get the answer 403.

Limits

  • Requests use POST /mcp. A GET is answered with 405.
  • Each request holds one JSON-RPC message of at most 128 KB and must state its Content-Length.
  • NNBuild answers and then closes the connection.
  • It serves up to eight connections at a time. A connection must finish within eight seconds.

Protocol notes

  • The server answers initialize, ping, tools/list and tools/call.
  • It accepts the protocol versions 2024-11-05, 2025-03-26 and 2025-06-18, and otherwise answers with 2025-11-25.
  • Over stdio, each message is one line of JSON.
  • A tool answers with JSON. When a tool fails, the answer is marked as an error and holds a sentence that says what to change.

Which tools are available

ToolWith --editor-mcpGame with --mcp-stdio or --mcp-http--build-editor with an MCP option
editor_statusYesYesNo
editor_connectYesNoNo
editor_disconnectYesNoNo
editor_inspectYesYesNo
editor_presenceYesYesNo
editor_editYesYesNo
editor_historyYesYesNo
editor_exportYesYesNo
editor_checkNoYesNo
editor_controlNoYesNo
project_statusNoYesNo
project_controlNoYesNo
game_statusNoYesYes
server_statusNoYesNo
console_executeNoYesYes
console_outputNoYesYes
ui_inputNoYesYes

In the game, the editor tools that read or change the map work only while the editor is open.

Rules that apply to all map tools

  • Positions are in map units. X and Y run from −524,288 to 524,288.
  • Z grows downward. One height unit is 256.
  • Angles run from 0 to 2047.
  • Sectors, walls and sprites are numbered from 0. A number is called an index.
  • The map has a revision number that rises with every change. An edit must name the current revision. If the map changed in the meantime, the edit is refused and the assistant must read the map again.
  • Adding or deleting sectors, walls or sprites can change the indexes of other objects. Read the map again after such an edit.

Editor tools

editor_status

Reads the state of the session and who is in it. No arguments.

Field in the answerMeaning
stateWith the adapter: offline, connecting, joined or hosting. In the game: closed, editing or playtest.
revisionThe current revision of the map
slotThis participant’s place in the session
tile_limitTile numbers must be below this value
playersOne entry for each participant: slot, name, ai, activity, and if present selection and cursor
noticeAdapter only. A message from the session, such as the reason for a refusal.

In the game, the answer also has session, name, path, view (plan, 3D or section), dirty, busy, can_undo and can_redo.

editor_connect

Adapter only. Joins a session, or joins again after a disconnect.

ArgumentMeaning
addressOptional. Host address. The default is the address the adapter was started with.
nameOptional. Name to show. The default is the name the adapter was started with.

editor_disconnect

Adapter only. Leaves the session. The adapter keeps running. No arguments.

editor_inspect

Reads a summary of the map, or a range of its records.

ArgumentMeaning
kindmap for the summary only, or sectors, walls or sprites. The default is map.
indexFirst record to read. The default is 0.
countHow many records to read, from 1 to 80. The default is 32.

Every answer holds revision, sector_count, wall_count, sprite_count and start (the player start with x, y, z, angle and sector).

A record holds the property names listed under Properties for set, and these read-only fields:

RecordRead-only fields
Sectorindex, first_wall, wall_count
Wallindex, x, y, point2 (the next wall of the outline), next_wall and next_sector (the other side of a portal, or −1), sector
Spriteindex, x, y, sector

editor_presence

Moves the assistant’s visible pointer and selects an object, so that people can follow what it is doing.

ArgumentMeaning
x, yWhere to point. Give both.
kindWhat to select: none, sector, wall, vertex, sprite or start
indexThe index of that object. Not needed for none and start.
cleartrue removes the pointer and the selection

editor_edit

Makes one change to the map. See Edit operations.

ArgumentMeaning
revisionRequired. The revision the assistant last read.
operationRequired. One of the operations below.
labelOptional. A short text for the change history, up to 64 characters.
otherThe arguments of the chosen operation

After a successful edit, the assistant’s pointer and selection move to the object it changed. The answer is the same as for editor_status.

editor_history

Reads the most recent changes.

ArgumentMeaning
countHow many changes to read, from 1 to 24. The default is 8.

Each change has revision, author, slot, label, ai, structure_changed, and the lists touched and removed with the kind and index of each object. The lists show up to 80 objects each. touched_count and removed_count give the full numbers.

editor_export

Saves the current map as a classic version 7 .map file. The file is written on the machine where the adapter or the game runs.

ArgumentMeaning
pathRequired. Must end in .map. Use a full path.
overwritetrue to replace an existing file. The default is false.

With the adapter, this saves the adapter’s own copy. It does not save the map in the host’s editor.

editor_check

Game only. Runs the map check on the local map.

ArgumentMeaning
indexFirst finding to read. The default is 0.
countHow many findings to read, from 1 to 80. The default is 40.

The answer has finding_count and a list findings. Each finding has kind, index and message.

editor_control

Game only. Controls the editor window. The answer is the same as for editor_status.

ActionWhat it doesArguments
enterOpens the editor from the title menu
newStarts a new mapdiscard
openOpens a mappath (required), target, discard
saveSaves the mappath, overwrite
undo, redoTakes back or repeats the last change
playtestStarts a playtestnone, or spawn, or x, y, sector with optional angle and platform
stop_playtestReturns from the playtest to the editor
closeLeaves the editor and returns to the title menudiscard
plan, perspective, sectionSwitches to the Plan, 3D or Section view
frameBrings the selection into view
hostHosts a live sessionport, name
joinJoins a live sessionaddress (required), name, discard
leaveLeaves the live session
build_toolsOpens the classic Build tools on the mapport
ArgumentMeaning
pathA map file. For open it can also be the file name of a level in the game data. For save, leave it out to save to the current file.
targetFor open: the game the map is for. One of inherit, duke13, duke_atomic, nam, napalm, ww2gi, standalone.
discardtrue allows the action to throw away unsaved changes. Without it, the action is refused while the map is unsaved.
overwriteFor save: true allows replacing another existing file.
spawnFor playtest: the index of a player start sprite to start from
x, y, sectorFor playtest: a temporary start position. Give all three.
angleFor playtest: the direction to face, from 0 to 2047
platformFor playtest: the index of a catwalk sprite to stand on at that position
portFor host: the UDP port, 23514 if left out. For build_tools: a TCP port on which the classic tools offer their own MCP endpoint.
nameFor host and join: the name to show
addressFor join: the host’s address

Project tools

project_status

Game only. Reads the open project and the settings of the current map.

ArgumentMeaning
indexFirst asset to list. The default is 0.
countHow many assets to list, from 1 to 80. The default is 40.
Field in the answerMeaning
rootThe project folder. Empty when no project is open.
name, entry, target, modernThe project settings
requires_vibebuild32true when Modern Mode is in effect
compatibility_warningThe Modern Mode warning text, when it applies
mapThe current map’s target, effective_target, modern (−1 inherit, 0 off, 1 on), effective_modern and scripts
asset_countNumber of files and folders in the project
assetsFor each listed asset: path, directory, target, icon, and type (folder, map, script, prefab or file)

project_control

Game only. Manages the project. The editor must be open. The answer is the same as for project_status.

ActionWhat it doesArguments
createCreates a project folder and opens itpath (required), name, target, modern
openOpens a project folderpath (required)
closeCloses the project
import_zipUnpacks a project ZIP into a new folder and opens itpath (the ZIP), destination (the new folder)
export_zipWrites the project to a ZIPpath (required), overwrite
add_assetCopies a file into the projectpath (the file), destination, overwrite
settingsChanges the project settingsname, target, modern, entry
map_settingsChanges the settings of the current maptarget, modern
attachAttaches a script component to an objectkind, index, script
detachRemoves a script component from an objectkind, index, script
export_mapWrites the current map as a plain classic mappath (required), target, overwrite
create_componentCreates a starter script and attaches itpath (the new script), kind, index
save_prefabSaves sprites as a prefabpath (required), sprites, overwrite
place_prefabPlaces a prefab in the mappath (required), x, y, sector, floor_z
ArgumentMeaning
pathA file or folder. For create_component, save_prefab and place_prefab it is a path inside the project.
destinationFor import_zip: the new folder. For add_asset: the path inside the project. If left out, the file keeps its name at the top of the project.
nameThe project’s name
entryFor settings: the entry map, as a path inside the project. An empty text clears it.
targetA game target: duke13, duke_atomic, nam, napalm, ww2gi, standalone, or inherit for a map
modernon or off. For map_settings also inherit.
kindsector, wall or sprite
indexThe index of that object
scriptPath of the script inside the project
spritesFor save_prefab: a list of sprite indexes
x, yFor place_prefab: where to place it
sectorFor place_prefab: optional. The sector to prefer at that spot.
floor_zFor place_prefab: optional. The Z of the floor level to place on.
overwritetrue allows replacing an existing file

Script components and prefabs need Modern Mode. See Modern Mode.

Game and server tools

game_status

Reads what the program is doing. No arguments.

Field in the answerMeaning
modemenu, game, editor, playtest or build_tools
menutrue while a menu is open
headlesstrue when the program runs without a window
width, heightSize of the picture in pixels
episode, level, level_name, user_mapThe level being played
playerThe local player’s x, y, z, angle, sector and health

The last two rows are present only during a game.

server_status

Reads the multiplayer state. No arguments. The answer has everything from game_status, and:

Field in the answerMeaning
roleoffline, host, client or dedicated
local_slotThis machine’s player number
portThe network port
slotsNumber of player slots
late_join, asynchronous, changing_mapServer settings and state
playersFor each connected player: slot, name, host, spectator and bot

console_execute

Runs one line in the game console. Server commands use the same console.

ArgumentMeaning
commandRequired. One line of up to 4,096 characters.

The answer holds the console text that the command produced, in the same form as console_output.

Useful commands: listsymbols lists every command, and help NAME explains one. On a server, listplayers, changemap, mapcycle and kick manage the match.

console_output

Reads recent console text.

ArgumentMeaning
afterOptional. A cursor value from an earlier answer. Only newer lines are returned.
limitHow many lines to read, from 1 to 80. The default is 32.

The answer has lines, cursor (pass it as after next time) and latest. The program keeps the last 256 lines.

ui_input

Sends keyboard, mouse or text input to the game window, as if a person had made it. The game’s window must have the keyboard focus.

ArgumentMeaning
eventsRequired. A list of 1 to 32 events.
Event typeOther fields
key_down, key_upkey: an SDL key name such as F5, Return, Escape or Left Shift
texttext: up to 31 characters to type
movex, y: pointer position in the window. Optional dx, dy: relative movement.
button_down, button_upbutton: left, middle or right. x, y: pointer position.
wheeldy: wheel steps, from −32 to 32

Send a key or button release in a later call than the press, so that the game has time to see the key held down.

Edit operations

These are the values of operation for editor_edit.

OperationArgumentsWhat it does
roompoints: a list of at least three [x, y] pairsAdds a sector with that outline. An edge with the same two end points as an existing solid wall becomes a portal.
extendindex: a solid wall. Optional depth, from 128 to 32768. The default is 1536.Adds a rectangular room behind the wall
splitindex: a wallAdds a vertex at the middle of the wall
move_vertexindex: the wall that starts at the vertex. x, y.Moves the vertex, together with the corners joined to it
spritetile, x, y. Optional sector to prefer.Places a sprite on the floor
move_spriteindex: a sprite. x, y.Moves the sprite. It keeps its height above the floor.
startx, y. Optional sector and angle.Sets the player start
setkind: sector, wall, sprite or start. index (not for start). properties: names and whole numbers.Sets properties
deletekind: sector or sprite. index.Deletes the object
batchedits: a list of 1 to 64 operationsApplies several operations as one change

Batch edits

Use batch for changes that belong together, such as a room with its furniture.

{
  "revision": 12,
  "operation": "batch",
  "label": "Add storage room",
  "edits": [
    { "operation": "extend", "index": 1, "depth": 1024 },
    { "operation": "sprite", "tile": 28, "x": 2560, "y": 0 }
  ]
}

On a new map, this adds a room behind the right-hand wall of the starter room and places a shotgun in it. Replace 12 with the revision from your last read.

  • Each entry of edits uses the arguments of its own operation. Entries do not carry a revision.
  • The entries run in order. An index in a later entry refers to the map as it is after the earlier entries.
  • If any entry fails, the whole batch is dropped and nothing changes. The message names the entry that failed.
  • A successful batch is one revision and one undo step.
  • A batch is never merged with other people’s edits. If the map changed since the given revision, the batch is refused.

Properties for set

set changes the listed properties and leaves the others alone. Every name must be one of those below and every value must be a whole number in range. Otherwise nothing is changed.

KindProperty names
sectorfloor_z, ceiling_z, floor_tile, ceiling_tile, floor_flags, ceiling_flags, floor_slope, ceiling_slope, floor_shade, ceiling_shade, floor_palette, ceiling_palette, floor_pan_x, floor_pan_y, ceiling_pan_x, ceiling_pan_y, visibility, lotag, hitag, extra
walltile, overlay_tile, flags, shade, palette, repeat_x, repeat_y, pan_x, pan_y, lotag, hitag, extra
spritez, tile, flags, angle, shade, palette, repeat_x, repeat_y, offset_x, offset_y, clip_distance, status, lotag, hitag, extra
startangle, z

For example, this darkens the floor of sector 2:

{
  "revision": 13,
  "operation": "set",
  "kind": "sector",
  "index": 2,
  "properties": { "floor_shade": 16 }
}

The positions of walls and sprites are not properties. Use move_vertex, move_sprite and start to change them.

A good working order for an assistant

  1. Call editor_status to check the connection and see who else is there.
  2. Call editor_inspect with kind set to map, then read the sectors and walls of the area to work on.
  3. Call editor_presence to point at that area, so people can see where the assistant is about to work.
  4. Call editor_edit with the latest revision.
  5. If the edit is refused, read the map again before trying again.
  6. Read the changed records to confirm the result. In the game, run editor_check and try the map with editor_control and the action playtest.
  7. Call editor_presence with clear set to true when the work is done.