Skip to content

MCP & AI Agents

DownDraft includes a built-in MCP (Model Context Protocol) server that enables AI agents to design, build, debug, and manage game assets via natural language prompts.

The MCP server runs as a JSON-RPC server over stdio, providing AI agents with tools, resources, and prompt templates for interacting with the engine.

MCP tools allow AI agents to perform actions:

ToolDescription
SceneCreate, modify, and remove scenes
EntitySpawn, modify, and remove entities
ComponentAdd/remove components on entities
MaterialCreate/modify materials and shaders
MeshImport, generate, and modify meshes
AnimationCreate and modify animation clips
LightingSet up lights, shadows, and GI
CameraCamera placement and framing
PhysicsConfigure physics, colliders, and forces
AudioAudio sources, listeners, and mixing
ScriptGame logic scripting (TypeScript)
AssetImport, convert, and manage assets
DebugInspect state, profile, and visualize
CheckpointCreate/restore checkpoints, undo/redo
InspectRich object inspection (deep component dump, hierarchy traversal, query by path)
BuildBuild, package, and export game

Resources provide read-only data to AI agents:

ResourceDescription
Scene TreeLive scene hierarchy (parent/child tree)
Entity StateEntity component dump (rich, recursive)
PerformanceFrame timings, system timings
GPU InfoAdapter info, buffer sizes, draw calls
Asset ListAsset inventory
Checkpoint ListAvailable checkpoints and undo/redo history

Pre-defined prompt templates guide AI agents through common tasks:

  • Create Scene — Scaffold a new scene with entities and components
  • Add Entity — Add an entity to an existing scene
  • Debug Frame — Diagnose rendering or performance issues

In dev mode or with --debug flag, telemetry is exposed via MCP tools:

  • profile_frame() — Profile a single frame
  • get_telemetry(duration) — Get telemetry for a duration

All threads and processes report GC pause duration, memory usage, and CPU time. Telemetry has zero overhead in prod mode (instrumentation is compiled out).

Separate from the editor server above, every running game exposes an in-process MCP automation endpoint (JSON-RPC over HTTP on 127.0.0.1) for testing and scripted verification: capture_screenshot, inject_input, wait_for_condition, get_player_state, get_world_state, set_test_state, and game-specific tools. Each instance writes ~/.downdraft/port/<pid> with its bound port; clients discover the newest live instance automatically.

The endpoint is dev/test infrastructure — draft release / scripts/package-native.mjs compile it out of distributed binaries (--mcp retains it, still runtime-gated by DOWNDRAFT_MCP=1).

Three ways to talk to it:

Terminal window
draft mcp instances # list live game instances
draft mcp tools # list tools (name + description)
draft mcp call get_world_state # call a tool, JSON args optional
draft mcp screenshot shot.png # capture_screenshot → file
draft mcp run verify.ts --game my-game # launch game → run script → kill
draft mcp stdio # stdio→HTTP bridge for MCP clients
import { GameClient, launchGame } from "@downdraft/engine/mcp/client";
const game = await launchGame({ game: "my-game", deterministic: true });
const state = await game.client.callJson("get_world_state");
await game.client.screenshot("shot.png");
await game.kill();

draft mcp prints tool text output to stdout (capped at --max-bytes, default 256 KiB); image/binary blocks are never inlined — pass --out <file> or --json.