---
catalog_id: "R-136"
kind: "repo"
domain: "tooling"
domain_label: "工程门禁 / Tooling & QA"
date: "2026-11-30"
title: "Coding-Solo/godot-mcp"
verdict: "零插件Headless桥接极简，刚堵RCE但缺实时编辑态"
summary: "零引擎插件依赖的轻量级 Godot MCP 服务器（v0.1.1，MIT）：通过单文件 TypeScript Stdio 服务按需调用 `godot --headless --script` 执行打包 GDScript 场景与资源操作，并在最新提交（PR #99）封堵了任意脚本实例化的 RCE 漏洞，但受限于无状态子进程架构仍存在缺少实时编辑态与属性加载绕过等局限。"
summary_en: "Zero-addon Node.js MCP server driving Godot via headless SceneTree CLI scripts; patches class_name RCE (#99) but lacks live editor state."
canonical_url: "https://oumuatown.com/repos/Coding-Solo__godot-mcp/"
markdown_url: "https://oumuatown.com/repos/Coding-Solo__godot-mcp.md"
og_image_zh: "https://oumuatown.com/og/zh/R-136.png"
og_image_en: "https://oumuatown.com/og/en/R-136.png"
cite_count: 34
repo: "coding-solo/godot-mcp"
github_url: "https://github.com/coding-solo/godot-mcp"
commit: "1209744"
tags:
  - "godot"
  - "mcp"
  - "gdscript"
  - "game-engine"
  - "typescript"
  - "security-audit"
github_repos:
  - "https://github.com/coding-solo/godot-mcp/tree/1209744"
---

# R-136 · Coding-Solo/godot-mcp

> **结论 / Verdict**: 零插件Headless桥接极简，刚堵RCE但缺实时编辑态
> **EN Summary**: Zero-addon Node.js MCP server driving Godot via headless SceneTree CLI scripts; patches class_name RCE (#99) but lacks live editor state.

## Provenance & Evidence

- Primary Repository: https://github.com/coding-solo/godot-mcp (@1209744)
- Verified Source Citations (#Lxx): 34
- Web Reader: https://oumuatown.com/repos/Coding-Solo__godot-mcp/

# Coding-Solo/godot-mcp

> 仓库地址：https://github.com/Coding-Solo/godot-mcp · 审计版本：`Coding-Solo/godot-mcp@1209744`（`v0.1.1`） · 审计日期：2026-11-30
> 来源文章：[关联文章](../articles/2026-11-30-archiveexplorer-rea-reverse-anything.md)

## 定位与解决的真问题

- **核心定位与目标用户**：面向 Claude Desktop、Cline、Cursor 等 MCP 客户端的零侵入 Godot 引擎桥接器（`package.json#L1-L47`, `src/index.ts#L1-L9`）。
- **相比常规做法解决的关键痛点**：
  1. **目标 Godot 工程零插件安装（Zero-Addon Footprint）**：不同于需要在每个游戏工程 `addons/` 下拷贝并启用 EditorPlugin + WebSocket 服务器的重型方案，本仓将单个通用 `SceneTree` 脚本 `godot_operations.gd` 随 npm 包内置分发，每次工具调用直接拉起外部 `godot --headless --path <project> --script` 完成 `.tscn` 场景创建、节点挂载、`MeshLibrary` 导出与 Godot 4.4+ `.uid` 维护（`src/index.ts#L134-L136,L509-L530`, `src/scripts/godot_operations.gd#L1-L79`）。
  2. **跨命名风格容错与进程日志捕获**：内置双向 `camelCase <-> snake_case` 递归参数转换器消除 LLM 传参命名抖动，并用常驻子进程管道捕获 `godot -d` 调试运行的 `stdout`/`stderr`（`src/index.ts#L76-L105,L424-L475,L1096-L1132`）。

## 技术栈与核心目录结构

- **语言 / 运行时 / 关键依赖**：Node.js `>=18.0.0` + TypeScript `^5.3.3`（ESM 模块），运行时依赖 `@modelcontextprotocol/sdk`（`0.6.0`）、`fs-extra`（`^11.2.0`）与 `axios`（`^1.7.9`，注：`src/index.ts` 实际未引用 `axios`），引擎侧要求本机安装 Godot 4.x（UID 工具要求 `4.4+`）；开源协议为 **MIT**（`LICENSE`, `package.json#L17-L46`）。
- **极简全仓结构（全仓共 11 个跟踪文件）**：
  - `src/index.ts`（2,221 行）：`GodotServer` 单类完整实现，含跨平台 Godot 可执行文件探测、参数清洗、进程生命周期管理及全部 **14 个 MCP 工具**的 Schema 与 Handler（`src/index.ts#L64-L968`）。
  - `src/scripts/godot_operations.gd`（1,186 行）：继承 `SceneTree` 的无头批处理 GDScript，承接 `create_scene`、`add_node`、`load_sprite`、`export_mesh_library`、`save_scene`、`get_uid`、`resave_resources` 7 类引擎内部资源读写操作（`src/scripts/godot_operations.gd#L59-L78`）。
  - `scripts/build.js`（29 行）：构建后置脚本，给 `build/index.js` 赋予 `755` 可执行权限并将 `godot_operations.gd` 拷贝至 `build/scripts/`（`scripts/build.js#L9-L26`）。

## 核心实现源码级剖析（附文件路径与行号）

1. **无插件 Headless `SceneTree` 命令行桥接与防 Shell 注入执行流**（`src/index.ts#L484-L543`, `src/scripts/godot_operations.gd#L7-L79`）：
   - Node 侧 `executeOperation` 先将入参统一转为 `snake_case` 并序列化成单条 JSON 字符串，随后通过 `child_process.execFile`（参数数组直传 OS `execve`，完全不经过 Shell 解析从而阻断命令注入）执行：`godot --headless --path <projectPath> --script <godot_operations.gd> <operation> <paramsJson> --debug-godot`（`src/index.ts#L506-L529`）。
   - GDScript 侧继承 `SceneTree` 在 `_init` 中通过 `OS.get_cmdline_args.find("--script")` 定位偏移（`script_index + 2` 为操作名、`+ 3` 为 JSON 参数），由 `JSON.new.parse` 反序列化后分发执行并在末尾立即 `quit`（`src/scripts/godot_operations.gd#L7-L79`）。
2. **PR #99 任意脚本实例化 RCE 修复双层护栏**（`src/index.ts#L217-L225,L1500-L1506,L1582-L1587`, `src/scripts/godot_operations.gd#L91-L163`）：
   - 在 `1209744` 之前的版本中，Agent 或受污染提示词向 `create_scene.rootNodeType` 或 `add_node.nodeType` 传入 `res://evil.gd` 或任意路径时，GDScript 会直接 `load` 并 `.new` 触发任意代码执行。
   - 当前版本构建了 Node + GDScript 双重校验：Node 侧新增 `validateClassName` 强制匹配 `/^[A-Za-z_][A-Za-z0-9_]*$/`，拒绝一切含冒号、斜杠或点号的路径输入（`src/index.ts#L222-L225`）；GDScript 侧 `instantiate_class` 仅允许 `ClassDB.class_exists` 内置节点类，或通过 `ProjectSettings.get_global_class_list` 精确匹配工程已注册的全局 `class_name` 再加载对应脚本（`src/scripts/godot_operations.gd#L95-L156`）。
3. **跨平台可执行文件探测与 Godot 4.4+ `.uid` 兼容门禁**（`src/index.ts#L247-L366,L409-L417,L2019-L2031`, `src/scripts/godot_operations.gd#L889-L1088`）：
   - `detectGodotPath` 按「构造器配置 → `GODOT_PATH` 环境变量 → `PATH` 中的 `godot` → macOS（含 `/Applications/Godot.app` 与 Steam 安装路径）/ Windows / Linux 常见安装位置」依次用 `execFileAsync(path, ['--version'])` 验证并缓存至 `validatedPaths` Map（`src/index.ts#L247-L343`）。
   - `get_uid` 与 `update_project_uids` 先调 `--version` 用 `isGodot44OrLater` 拦截低于 4.4 的引擎版本，再由 `resave_resources` 递归扫描全部 `.tscn`、`.gd`、`.shader`、`.gdshader` 调用 `ResourceSaver.save` 补齐缺失的 `.uid` 伴生文件（`src/index.ts#L2019-L2040`, `src/scripts/godot_operations.gd#L962-L1087`）。

## 亮点设计 vs 局限/坑点

- **值得借鉴的设计**：
  - **全仓 ~3,400 行源码零侵入跑通核心场景流水线**：无需改动目标项目的 `project.godot` 插件列表，特别适合批量处理外部开源/逆向恢复出来的 Godot 工程（例如配合 `GDRE Tools` 恢复工程后直接批处理场景与 `MeshLibrary`）。
  - **面向 Agent 自愈的结构化报错提示**：`createErrorResponse` 统一附带 `Possible solutions` 列表，引导模型自行调用 `list_projects` 或检查前置步骤（`src/index.ts#L177-L202`）。
- **局限、隐含假设与潜在坑点（源码审计发现 5 处硬伤）**：
  1. **【安全盲区】`add_node.properties` 仍残留 `res://` 任意资源 `load` 与 `script` 属性挂载路径**：尽管 PR `#99` 锁死了 `nodeType`，但 `src/scripts/godot_operations.gd#L513-L526` 遍历 `params.properties` 时，凡字符串值以 `"res://"` 开头即无条件执行 `value = load(value)` 再调用 `new_node.set(property, value)`——传入 `{"script": "res://payload.gd"}` 或恶意 `.tres` 资源仍可在 `PackedScene.pack` / 后续运行期触发脚本加载，且 `validatePath` 仅检查 `!path.includes('..')` 未拦截符号链接或特殊绝对路径（`src/index.ts#L207-L215`）。
  2. **【架构局限】每次操作冷启动一次 Headless Godot 且与打开的编辑器争抢文件**：无持久守护连接意味着每添加一个节点都要重新冷启动 Godot 进程、重加载整棵 `PackedScene` 再覆盖写盘；若用户同时在 Godot GUI 编辑器中打开同一 `.tscn`，外部静默改盘会导致编辑器内存状态与磁盘冲突甚至被保存覆盖。
  3. **【调试常设】硬编码 `GODOT_DEBUG_MODE = true` 拖慢每次 `create_scene` >500ms**：`src/index.ts#L27,L522-L524` 将 `GODOT_DEBUG_MODE` 写死为常量 `true`，导致每次 `create_scene` 在 GDScript 侧无条件创建并删除两次临时探测文件（`godot_mcp_test_write.tmp`、`test_write_access.tmp`）且硬睡 `OS.delay_msec(500)`（`src/scripts/godot_operations.gd#L208-L229,L260-L281,L353-L357`）。
  4. **【ESM Bug】`type: "module"` 下残留 CommonJS `require('fs')`**：`package.json#L20` 声明 ESM，文件顶部也仅按名导入了 `existsSync/readdirSync/mkdirSync`（`src/index.ts#L12`），但 `handleGetProjectInfo` 在 `src/index.ts#L1438` 写了 `const fs = require('fs')`——在 Node ESM 下每次必抛 `ReferenceError: require is not defined`，被 `catch` 静默吞掉后导致永远无法从 `project.godot` 读取真实 `config/name`，只能回退返回文件夹名。
  5. **【多会话覆盖】单槽位 `activeProcess` 与无上限日志数组**：`this.activeProcess` 仅维护单个子进程且 `output`/`errors` 数组无限 `push` 不截断（`src/index.ts#L66,L1098-L1115`），长时运行高频日志游戏后调 `get_debug_output` 会一次性吐出巨量 JSON 撑爆上下文。

## 可复用的模块或设计模式

- **如何迁移到未来项目**：
  - **离线批处理 vs 实时交互选型准则**：若任务是「无界面批量生成 `.tscn` / 转换 `MeshLibrary` / 刷 Godot 4.4 UID」，`godot --headless --script` 单文件 `SceneTree` 模式是最轻量的范式；若需要实时读写编辑器当前选中节点、实时调参或截图视口，则应改用常驻 EditorPlugin WebSocket 架构（参看同批 `CoplayDev/unity-mcp`）。
  - **落地自用前的 3 处必打补丁**：① 将 `src/index.ts#L27` 的 `GODOT_DEBUG_MODE` 改为读取环境变量默认关闭，去掉 500ms 死等与项目根目录临时文件写入；② 将 `#L1438` `require('fs')` 改为顶层 ESM `readFileSync`；③ 在 `godot_operations.gd#L517-L525` 拦截 `property == "script"` 并校验 `res://` 资源类型白名单（如仅允许 `Texture2D`/`Shape3D`/`Material`）。
- **关联 Pattern**：（由 `synthesizer` 补全）

## Cross-Referenced Specimens

- [A-031 · REA + Gemini 4 Neon 速配与「万物逆向重建」十赛道证据工程教程拆解](https://oumuatown.com/articles/2026-11-30-archiveexplorer-rea-reverse-anything.md) — 证据工作区加外部核验闭环可复用，但1M无分块宣传失实
- [P-029 · 跨领域逆向重建桥接与验证矩阵：Web UI、音视频/3D、游戏、硬件与增长策略（Multi-Domain Reconstruction Bridges）](https://oumuatown.com/patterns/multi-domain-reconstruction-bridges-ui-media-game-hw-growth.md) — 五大领域表征升级桥接选型与安全坑点总图
