Godot MCP 在無顯示環境下 run_project 失敗的原因與修正方法
The Godot MCP server installs cleanly. Then every run_project call fails on a headless box
作者排查發現,Godot MCP 的 run_project 在無顯示環境下未指定 headless 顯示驅動,Godot 因而在啟動時退出,get_debug_output 只回報沒有活動中的程序。
You add the server the way its README says:
claude mcp add godot \
-e GODOT_PATH=/usr/local/bin/godot \
-- npx @coding-solo/godot-mcp
tools/list comes back with 14 tools. run_project answers like it worked:
Godot project started in debug mode. Use get_debug_output to see output.
Then get_debug_output answers, every single time:
No active Godot process.
No stack trace, no stderr, nothing in the client log. The project never started, and nothing in the response says why.
The README does not cover this
Its troubleshooting section has four entries: Godot Not Found, Connection Issues, Invalid Project Path, Build Issues. None of them is "the engine started and died". The word headless appears zero times in the README (I re-fetched main today to be sure). So the reasonable thing is to go check your own setup first.
Ruling out your setup
Check the binary before you suspect the MCP layer:
./godot-headless --version
4.7.2.stable.official.ed1daf0bf
The engine runs. The MCP server answers tools/list, so Node and the client config are fine. What's left is the hand-off between the two.
Read the source
In index.js, handleRunProject builds the command like this:
const cmdArgs = ['-d', '--path', args.projectPath];
No --headless. -d is debug mode, and debug mode wants a display. On a box with no display server the engine exits on startup, handleGetDebugOutput finds no active process, and returns that string. The message is accurate — there really is no process. It just doesn't tell you why there isn't one.
The fix: point GODOT_PATH at a wrapper, not at the binary
#!/bin/sh
# /opt/godot/godot-headless
exec /opt/godot/Godot_v4.7.2-stable_linux.x86_64 --display-driver headless "$@"
chmod +x it, then restart the MCP client with GODOT_PATH pointing at the wrapper. The server still sends -d --path …; the wrapper adds the display driver before exec. Client config, for reference:
{
"mcpServers": {
"godot": {
"command": "npx",
"args": ["@coding-solo/godot-mcp"],
"env": { "GODOT_PATH": "/opt/godot/godot-headless" }
}
}
}
The trade you are making: every Godot invocation from that client is now headless, including editor launches. On a server or CI box that is the right trade. On your laptop it is the wrong one, and you probably never need the wrapper at all.
What success looks like, in numbers
Same client, same project, one env var different:
-
run_project→Godot project started in debug mode. Use get_debug_output to see output.(a 154-byte JSON response) -
get_debug_output→ 1,949 bytes. First line:Godot Engine v4.7.2.stable.official.ed1daf0bf - https://godotengine.org. Inside the output array, the project's own print:CD10I_HELLO from cd10i-demo. - Running the wrapper directly, outside MCP —
./godot-headless -d --path proj, exit 0 — prints the same line. That is how you know the MCP path isn't adding or hiding anything.
The demo project is three files: project.godot (148 B), main.tscn (149 B), main.gd (131 B). The whole loop — write project, run, read output — takes minutes, which matters when you are debugging the tool wrapper rather than the game.
The next trap: the process is gone before you read it
get_debug_output reads from a live process, and the server clears its active process handle when the project quits by itself. A project that prints one line and calls get_tree().quit() gives you a real response if you read at ~3 seconds, and No active Godot process. again at 10. Our test project lives about 8 seconds for exactly that reason.
So: read the output while the thing is still running, or make the project wait. A polling loop that retries every 20 seconds will look like the server is broken when it is just late.
Make your check fail once, on purpose
If you build a pass/fail check on top of this, prove it can go red before you trust a green:
run_project {"projectPath": "/root/nope"}
→ Not a valid Godot project: /root/nope
isError: true
Possible solutions: …
(The path in that output is whatever you passed — in our first run it was /root/cd10i/gd_missing, and the message echoed it back.)
A success check that has never returned false isn't measuring anything. The same applies to the fix above: keep one project path that fails so you can test the harness itself.
What I did not test
- Linux x86_64 only. Not macOS, not Windows — different asset names, different
--display-driverbehaviour, and I have no run to show. - Godot
4.7.2.stable.officialonly. Older versions may not accept the same flags. -
@coding-solo/godot-mcp0.1.1 — the version current when this was written. - One project, one session. Reconnects, concurrency and long-lived sessions are untested.
If your machine has a display server, none of this fires. The wrapper is for the box that doesn't.
The four-step version of this, with the exact commands and the copy buttons, is here: Game development · step by step.
來源:DEV Community · dev.to