defold-mcp-server
An MCP server that gives AI coding agents first-class access to the Defold game engine: inspect and edit projects, build and bundle with bob, run games locally, hot-reload code into a live game, drive the running engine, and search the official API reference.
Everything works headlessly — no Defold editor required. A desktop app manages the server, streams its activity to a live console, and auto-configures your AI agents.
Features
- Project intelligence — parse
game.project, collections, game objects, GUI scenes, atlases and any other text-format resource into structured JSON; outline Lua scripts (functions,go.propertydefinitions, requires, handled messages); find references to any asset before renaming or deleting it. - Build pipeline — download/cache
bob.jarper Defold version, compile with structured error diagnostics (resource, line, message), bundle for all supported platforms, resolve dependencies. - Run & debug loop — download/cache the
dmenginedev binary, launch the game in the background, read its logs incrementally, stop it gracefully. - Live engine control — hot reload changed scripts/resources into the running game (the same mechanism the editor uses), toggle the profiler and physics debug, set frame cap and vsync, record gameplay video, reboot or exit the engine, and stream engine logs over TCP — including from editor-launched games and devices on the network.
- Visual feedback — screenshot the running game as an image the agent can actually look at, to verify rendering, layout and UI (not just logs).
- API documentation — search and read the official Defold API reference for the exact engine version you build with (go, gui, msg, sys, physics, render, editor scripting, native extension SDK, ...).
Requirements
- Node.js >= 18
- Java (JDK 17+, 21+ recommended) — only for the build tools (
defold_build,defold_bundle,defold_resolve_dependencies). Everything else works without Java. Install from Adoptium orbrew install openjdk. - Network access on first use of a Defold version (downloads
bob.jar,dmengine, API docs from official Defold servers into~/.defold-mcp).
Installation
git clone https://github.com/Fulviuus/defold-mcp.git && cd defold-mcp
npm install
npm run build # produces dist/index.js
npm test # optional: 46 unit + end-to-end tests
Desktop app (recommended for multi-agent setups)
A Tauri app in desktop/ manages the server for you: a live console of
everything the server does (every tool call, build output, engine logs), start/stop
with a chosen host/port, and one-click configuration of AI agents (Claude Code,
Claude Desktop, Codex CLI, Cursor, Gemini CLI, VS Code Copilot, Windsurf, Cline, Zed).
cd desktop
npm install
npm run dev # run the app (requires Rust toolchain)
npm run build # produce a distributable bundle (.app / .msi / .deb)
In the app: pick host/port → Start server → choose an agent from the dropdown →
Configure. The app merges a defold entry into that agent's own config file
(backing up the original) pointing at http://127.0.0.1:<port>/mcp. All connected
agents share this one server instance, and its activity streams into the console.
Transports
The server speaks both MCP transports:
- stdio (default) — the client spawns the server itself:
node dist/index.js - Streamable HTTP — one long-lived server many clients connect to:
node dist/index.js --transport http --host 127.0.0.1 --port 9810(MCP endpoint at/mcp, status at/health). This is what the desktop app runs. DNS-rebinding protection is enabled on loopback binds; binding0.0.0.0is possible for LAN use but exposes the endpoint to your network — only do this on trusted networks.
Claude Code
claude mcp add defold -- node /path/to/defold-mcp/dist/index.js
or in .mcp.json:
{
"mcpServers": {
"defold": {
"command": "node",
"args": ["/path/to/defold-mcp/dist/index.js"],
"env": { "DEFOLD_PROJECT_ROOT": "/path/to/your/game" }
}
}
}
OpenAI Codex CLI
codex mcp add defold \
--env DEFOLD_PROJECT_ROOT=/path/to/your/game \
--env JAVA_HOME=/opt/homebrew/opt/openjdk/libexec/openjdk.jdk/Contents/Home \
-- node /path/to/defold-mcp/dist/index.js
or in ~/.codex/config.toml:
[mcp_servers.defold]
command = "node"
args = ["/path/to/defold-mcp/dist/index.js"]
startup_timeout_sec = 30 # default 10
tool_timeout_sec = 600 # default 60 — too short for defold_build/defold_bundle
[mcp_servers.defold.env]
DEFOLD_PROJECT_ROOT = "/path/to/your/game"
JAVA_HOME = "/opt/homebrew/opt/openjdk/libexec/openjdk.jdk/Contents/Home"
Two Codex-specific gotchas:
- Raise
tool_timeout_sec(default 60 s): first builds download platform packages and can run for minutes; Codex kills slower tool calls. - Codex sanitizes the server environment (only
HOME,PATH,USER, ... survive).JAVA_HOMEandDEFOLD_PROJECT_ROOTare not inherited from your shell — set them in theenvtable, or whitelist shell vars withenv_vars = ["JAVA_HOME"].
Gemini CLI
gemini mcp add -s user \
-e DEFOLD_PROJECT_ROOT=/path/to/your/game \
-e JAVA_HOME=/opt/homebrew/opt/openjdk/libexec/openjdk.jdk/Contents/Home \
defold node /path/to/defold-mcp/dist/index.js
(or the same mcpServers JSON block as Claude Desktop in ~/.gemini/settings.json; note gemini mcp add defaults to project scope — -s user makes it global. Per-server "timeout" is in ms, default 600000.)
Cursor / Claude Desktop / Windsurf / Cline
All use the same mcpServers JSON shape — only the file location differs:
{
"mcpServers": {
"defold": {
"command": "node",
"args": ["/path/to/defold-mcp/dist/index.js"],
"env": {
"DEFOLD_PROJECT_ROOT": "/path/to/your/game",
"JAVA_HOME": "/opt/homebrew/opt/openjdk/libexec/openjdk.jdk/Contents/Home"
}
}
}
}
In Cursor, "DEFOLD_PROJECT_ROOT": "${workspaceFolder}" works. Cursor only forwards ~40 tools to the agent across all servers — disable unused servers if you hit the cap.
VS Code (GitHub Copilot agent mode)
.vscode/mcp.json — note the top-level key is servers, not mcpServers:
{
"servers": {
"defold": {
"type": "stdio",
"command": "node",
"args": ["/path/to/defold-mcp/dist/index.js"],
"env": { "DEFOLD_PROJECT_ROOT": "${workspaceFolder}" }
}
}
}
Zed
~/.config/zed/settings.json — Zed calls them context_servers:
{
"context_servers": {
"defold": {
"command": "node",
"args": ["/path/to/defold-mcp/dist/index.js"],
"env": { "DEFOLD_PROJECT_ROOT": "/path/to/your/game" }
}
}
}
Any other MCP client
The server is a standard stdio MCP server, so anything that speaks MCP works. You only ever configure three things:
- Launch:
node /path/to/defold-mcp/dist/index.js DEFOLD_PROJECT_ROOT(optional): if the agent's working directory is inside the game project, the server findsgame.projectby walking upward and no env var is needed.JAVA_HOME(optional): only needed fordefold_build/defold_bundle/defold_resolve_dependencieswhenjavais not on the PATH the client gives the server.
If the client enforces per-tool timeouts, raise them for the build tools (first builds can take minutes).
Environment variables
Tools
Project & settings
Resources
Build & toolchain
Run & live engine
API reference
Typical agent workflow
defold_setup # once: verify Java, fetch bob + engine + docs
defold_project_info # orient
defold_parse_resource /main/main.collection
... edit files with normal file tools ...
defold_build # structured compile errors
defold_run # launch
defold_hot_reload ["/main/player.script"] # iterate without restarting
defold_game_logs filter="ERROR" # observe
defold_stop
Defold-specific notes
- Trailing
cconvention:game.projectstores some bootstrap resources in compiled form —bootstrap.main_collection = /main/main.collectionc(note thec).defold_set_settingappends it automatically for the six affected keys (bootstrap.main_collection,bootstrap.render,bootstrap.debug_init_script,input.game_binding,input.gamepads,display.display_profiles). - Hot reload maps source paths to built paths (
.script→.scriptc,.atlas→.texturesetc, images →.texturec, ...) and posts them to the engine service (POST /post/@resource/reload, binary protobuf) — the same protocol the editor uses. It requires a debug build whosebuild/defaultoutput is in sync with the running game. - Engine service: debug builds listen on port 8001 (
/info,/ping,/post/...). For devices, pass the device IP ashost. - Native extensions: projects with native-code dependencies are compiled via Defold's cloud build servers when bob builds; this happens transparently but requires network access.
Security notes
- The server is a local development tool over stdio; it does not listen on any network port.
- File-writing tools resolve paths against the project root and reject traversal outside it.
- Toolchain artifacts are downloaded only from
d.defold.comandgithub.com/defold/defoldreleases, and cached locally. defold_engine_*tools talk to whatever host you point them at (defaultlocalhost); they send engine control messages, never project source.
Development
npm run dev # run from TypeScript sources
npm test # build + unit & e2e tests (no Java/network needed)
node test/live-smoke.mjs # live network smoke (downloads toolchain, queries real docs)
node test/live-smoke.mjs --full # + real build/run/hot-reload loop (needs Java)
Test layout: test/fixture is a minimal valid Defold project; test/server.test.mjs drives the server through a real MCP stdio client, with a fake engine HTTP/TCP service standing in for a running game.
License
MIT