# CrystalBattle Unity MCP This local MCP server exposes selected CrystalBattle 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 `CrystalBattle_Client` in Unity. The bridge starts automatically after scripts compile. Manual controls are available from the bridge panel: ```text 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: ```powershell pnpm install ``` If `pnpm` is not on `PATH`, use the Codex bundled runtime: ```powershell & "C:\Users\admin\.cache\codex-runtimes\codex-primary-runtime\dependencies\bin\pnpm.cmd" install ``` ## Tools - `unity_health` - `unity_refresh_assets` - `unity_execute_menu_item` - `unity_get_console_logs` - `unity_generate_ui_prefab` - `unity_export_prefab_to_json` ## Environment Optional: ```text UNITY_MCP_BRIDGE_URL=http://127.0.0.1:17777 ``` ## Codex Config The workspace includes `.codex/config.toml` with a `crystalbattle-unity` MCP server entry. Restart Codex after dependency installation so the new MCP server is discovered. --- ## 文档关联 > 当本文档发生变更时,应同步检查以下关联文档,避免信息不一致。 | 文档 | 关联原因 | |---|---| | [MCP 工具](../../modules/frameworks/编辑器工具/MCP工具/README.md) | Codex ↔ Unity MCP 工具说明 | | [CrystalBattle Codex ↔ Unity MCP 使用规则](../../modules/frameworks/编辑器工具/MCP工具/CrystalBattle_Codex_Unity_MCP使用规则.md) | 具体使用规则 | | [modules/模块索引.md](../../modules/模块索引.md) | 模块索引是项目知识总入口 |