Files
UnityAI/Tools/CodexUnityMcp

StrayFog Unity MCP

This local MCP server exposes selected StrayFog Unity Editor commands to Codex.

Architecture

  • Codex connects to this MCP server over stdio.
  • The MCP server calls the Unity Editor bridge at http://127.0.0.1:17777.
  • The Unity Editor bridge executes Unity API work on the editor main thread.

Unity Setup

Open the target StrayFog Unity project. The bridge starts automatically after scripts compile; use unity_health to confirm that the returned project path matches the current task.

Manual controls are available from the bridge panel:

Tools/Codex Unity MCP/Bridge Panel

The panel shows the current connection status, endpoint, listener thread state, pending command count, total request count, recent command, and cached log count. It also includes buttons to start, stop, restart, copy the endpoint, and print status to the Unity Console.

Install Dependencies

From this directory:

pnpm install

If pnpm is not on PATH, locate the configured Codex bundled runtime for the current machine instead of copying a user-specific absolute path.

Tools

  • unity_health
  • unity_refresh_assets
  • unity_execute_menu_item
  • unity_get_console_logs
  • unity_generate_ui_prefab
  • unity_export_prefab_to_json

Operational Notes

  • Start every automation run with unity_health and verify that the returned project path is the intended Unity project.
  • unity_refresh_assets can trigger compilation and a domain reload. The bridge may be temporarily unavailable; reconnect with unity_health before continuing.
  • A unity_execute_menu_item timeout means the result is unknown, not that the menu failed. Do not retry immediately; reconnect and inspect Unity Console logs or Editor.log first.
  • Bridge log caching starts again after a domain reload. Use Editor.log when evidence from the previous bridge lifetime is required.
  • A successful command proves Editor-side execution only. Prefab structure, animation sampling, Game View, Play Mode, build and device behavior require separate validation.

The canonical Chinese workflow and troubleshooting rules are maintained in Codex 与 Unity MCP 使用规则.

Environment

Optional:

UNITY_MCP_BRIDGE_URL=http://127.0.0.1:17777

Codex Config

Register this server in the workspace .codex/config.toml and restart Codex after dependency installation so the MCP server is discovered. The configured server name is workspace-owned and does not affect the MCP tool names below.


文档关联

当本文档发生变更时,应同步检查以下关联文档,避免信息不一致。

文档 关联原因
MCP 工具 Codex ↔ Unity MCP 工具说明
Codex ↔ Unity MCP 使用规则 具体使用规则
modules/模块索引.md 模块索引是项目知识总入口