From d97329e504b8f7265f3e189bab9094e41d27da0d Mon Sep 17 00:00:00 2001 From: Joywayer Date: Thu, 28 May 2026 11:00:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=95=B4=20Unity=20MCP=20=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E7=99=BD=E5=90=8D=E5=8D=95=20+=20=E4=B8=A4=E7=BA=A7?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E6=9E=B6=E6=9E=84=E6=96=87=E6=A1=A3=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - deploy.ps1: 自动写入 allowedTools 白名单至 ~/.claude/settings.json - 包含 Claude 内置工具 (Bash/Read/Write/Edit/Glob/Grep 等) - 包含全部 66 个核心 Unity MCP 工具 (mcp__unity-mcp__ 前缀) - 包含 unity_list_advanced_tools + unity_advanced_tool 代理 (200+ 高级工具) - 包含 6 个 Unity Hub 工具 - 包含 multi-instance 和 project context 工具 - 同步写入 WSL2 ~/.claude/settings.json 和 Windows %USERPROFILE%\.claude\settings.json - README: 重写工具列表,反映两级架构 (288 工具),说明高级工具分类与用法 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- claude-dev-stack/README.md | 63 ++++++++++++++++++++++++--------- claude-dev-stack/deploy.ps1 | 70 +++++++++++++++++++++++++++++++++++-- 2 files changed, 113 insertions(+), 20 deletions(-) diff --git a/claude-dev-stack/README.md b/claude-dev-stack/README.md index 9d6ffca..d3d168a 100644 --- a/claude-dev-stack/README.md +++ b/claude-dev-stack/README.md @@ -249,23 +249,52 @@ claude ### 可用 MCP 工具列表 -| 工具 | 功能 | -|------|------| -| `execute_menu_item` | 执行 Unity 菜单项 | -| `select_gameobject` | 选中场景中的 GameObject | -| `update_gameobject` | 更新/创建 GameObject 属性 | -| `update_component` | 更新/添加组件 | -| `add_package` | 通过 Package Manager 安装包 | -| `run_tests` | 运行 Unity Test Runner 测试 | -| `add_asset_to_scene` | 将 Asset 添加到场景 | -| `create_prefab` | 创建 Prefab | -| `create_scene` / `load_scene` / `delete_scene` | 场景管理 | -| `get_gameobject` | 获取 GameObject 详细信息 | -| `get_console_logs` | 读取 Unity Console 日志 | -| `recompile_scripts` | 重新编译脚本 | -| `create_material` / `assign_material` | 材质管理 | -| `move/rotate/scale_gameobject` | Transform 操作 | -| `batch_execute` | 批量执行多个操作 | +AnkleBreaker Unity MCP 采用**两级工具架构**,共 **288 个工具**: + +- **核心工具(~70个)**:直接暴露,无需中转 +- **高级工具(200+)**:通过 `unity_advanced_tool` 代理访问(避免 MCP 客户端工具过多失效) + +#### 核心工具(直接可用) + +| 分类 | 工具名 | 功能 | +|------|--------|------| +| **编辑器状态** | `unity_editor_ping` / `unity_editor_state` / `unity_project_info` | 检测连接、获取编辑器/项目状态 | +| **场景** | `unity_scene_info/open/save/new/hierarchy/stats` | 场景完整生命周期管理 | +| **GameObject** | `unity_gameobject_create/delete/info/set_transform/duplicate/set_active/reparent` | 对象增删改查 | +| **组件** | `unity_component_add/remove/get_properties/set_property/set_reference/batch_wire` | 组件与属性操作 | +| **资产** | `unity_asset_list/import/delete/create_prefab/instantiate_prefab` | 资产管理 | +| **脚本** | `unity_script_create/read/update` + `unity_execute_code` | C# 脚本读写与运行时执行 | +| **材质** | `unity_material_create` / `unity_renderer_set_material` | 材质创建与赋值 | +| **构建/运行** | `unity_build` / `unity_play_mode` | 多平台构建、Play Mode 控制 | +| **控制台** | `unity_console_log/clear` + `unity_get_compilation_errors` | 日志读取与编译错误 | +| **编辑器操作** | `unity_execute_menu_item` / `unity_undo/redo/undo_history` | 菜单执行、撤销重做 | +| **选择/搜索** | `unity_selection_*` / `unity_search_by_*` / `unity_search_assets` | 对象查找与选中 | +| **截图** | `unity_screenshot_game/scene` + `unity_graphics_*_capture` | 场景/游戏视图截图 | +| **Prefab** | `unity_prefab_info` / `unity_set_object_reference` | Prefab 信息与引用 | +| **包管理** | `unity_packages_list/add/remove/search/info` | Package Manager 操作 | +| **Multi-Agent** | `unity_queue_info` / `unity_agents_list` / `unity_agent_log` | 多代理会话管理 | +| **高级工具代理** | `unity_list_advanced_tools` / `unity_advanced_tool` | 访问 200+ 高级工具 | +| **Unity Hub** | `unity_hub_list_editors/available_releases/install_editor/install_modules` | Hub 版本管理 | +| **多实例** | `unity_list_instances` / `unity_select_instance` | 多 Unity 实例切换 | +| **项目上下文** | `unity_get_project_context` | AI 代理项目文档注入 | + +#### 高级工具分类(通过 `unity_advanced_tool` 访问) + +动画、Prefab 模式、物理、光照、音频、地形、导航网格、粒子、UI、标签与层、输入系统、Shader Graph、VFX Graph、Amplify Shader Editor、性能分析器、帧调试器、内存分析器、ScriptableObject、约束、LOD、MPPM 多人 PlayMode、UMA Avatar 等 30+ 分类。 + +```bash +# 列出所有高级工具 +> 使用 unity_list_advanced_tools 查看所有高级工具 + +# 按分类过滤 +> unity_list_advanced_tools { "category": "animation" } +> unity_list_advanced_tools { "category": "terrain" } + +# 执行高级工具 +> unity_advanced_tool { "tool": "unity_animation_create_controller", "params": {...} } +``` + +`deploy.ps1` 会自动将所有工具写入 `~/.claude/settings.json` 的 `allowedTools` 白名单,**无需每次手动确认**。 --- diff --git a/claude-dev-stack/deploy.ps1 b/claude-dev-stack/deploy.ps1 index 40705ff..8dac13d 100644 --- a/claude-dev-stack/deploy.ps1 +++ b/claude-dev-stack/deploy.ps1 @@ -447,11 +447,75 @@ true Write-OK "Claude Code 安装完成" } -# 写入 Claude 配置(WSL2 侧) +# 写入 Claude 配置(WSL2 侧)— 含 allowedTools 完整白名单(自动信任,无需每次确认) +$mcpAllowedTools = @( + # Claude 内置工具 + "Bash","Read","Write","Edit","MultiEdit","Glob","Grep","LS","WebFetch","TodoRead","TodoWrite", + # Editor State + "mcp__unity-mcp__unity_editor_ping","mcp__unity-mcp__unity_editor_state","mcp__unity-mcp__unity_project_info", + # Scene + "mcp__unity-mcp__unity_scene_info","mcp__unity-mcp__unity_scene_open","mcp__unity-mcp__unity_scene_save", + "mcp__unity-mcp__unity_scene_new","mcp__unity-mcp__unity_scene_hierarchy","mcp__unity-mcp__unity_scene_stats", + # GameObject + "mcp__unity-mcp__unity_gameobject_create","mcp__unity-mcp__unity_gameobject_delete", + "mcp__unity-mcp__unity_gameobject_info","mcp__unity-mcp__unity_gameobject_set_transform", + "mcp__unity-mcp__unity_gameobject_duplicate","mcp__unity-mcp__unity_gameobject_set_active", + "mcp__unity-mcp__unity_gameobject_reparent", + # Component + "mcp__unity-mcp__unity_component_add","mcp__unity-mcp__unity_component_remove", + "mcp__unity-mcp__unity_component_get_properties","mcp__unity-mcp__unity_component_set_property", + "mcp__unity-mcp__unity_component_set_reference","mcp__unity-mcp__unity_component_batch_wire", + "mcp__unity-mcp__unity_component_get_referenceable", + # Asset + "mcp__unity-mcp__unity_asset_list","mcp__unity-mcp__unity_asset_import", + "mcp__unity-mcp__unity_asset_delete","mcp__unity-mcp__unity_asset_create_prefab", + "mcp__unity-mcp__unity_asset_instantiate_prefab", + # Script & Code + "mcp__unity-mcp__unity_script_create","mcp__unity-mcp__unity_script_read", + "mcp__unity-mcp__unity_script_update","mcp__unity-mcp__unity_execute_code", + # Material + "mcp__unity-mcp__unity_material_create","mcp__unity-mcp__unity_renderer_set_material", + # Build & Play Mode + "mcp__unity-mcp__unity_build","mcp__unity-mcp__unity_play_mode", + # Console & Compilation + "mcp__unity-mcp__unity_console_log","mcp__unity-mcp__unity_console_clear", + "mcp__unity-mcp__unity_get_compilation_errors", + # Editor Actions + "mcp__unity-mcp__unity_execute_menu_item","mcp__unity-mcp__unity_undo", + "mcp__unity-mcp__unity_redo","mcp__unity-mcp__unity_undo_history", + # Selection & Search + "mcp__unity-mcp__unity_selection_get","mcp__unity-mcp__unity_selection_set", + "mcp__unity-mcp__unity_selection_focus_scene_view","mcp__unity-mcp__unity_selection_find_by_type", + "mcp__unity-mcp__unity_search_by_component","mcp__unity-mcp__unity_search_by_tag", + "mcp__unity-mcp__unity_search_by_layer","mcp__unity-mcp__unity_search_by_name", + "mcp__unity-mcp__unity_search_assets","mcp__unity-mcp__unity_search_missing_references", + # Screenshots & Graphics + "mcp__unity-mcp__unity_screenshot_game","mcp__unity-mcp__unity_screenshot_scene", + "mcp__unity-mcp__unity_graphics_scene_capture","mcp__unity-mcp__unity_graphics_game_capture", + # Prefab + "mcp__unity-mcp__unity_prefab_info","mcp__unity-mcp__unity_set_object_reference", + # Packages + "mcp__unity-mcp__unity_packages_list","mcp__unity-mcp__unity_packages_add", + "mcp__unity-mcp__unity_packages_remove","mcp__unity-mcp__unity_packages_search", + "mcp__unity-mcp__unity_packages_info", + # Queue & Multi-Agent + "mcp__unity-mcp__unity_queue_info","mcp__unity-mcp__unity_agents_list","mcp__unity-mcp__unity_agent_log", + # Advanced Tools proxy(200+ 工具通过此代理访问) + "mcp__unity-mcp__unity_list_advanced_tools","mcp__unity-mcp__unity_advanced_tool", + # Unity Hub + "mcp__unity-mcp__unity_hub_list_editors","mcp__unity-mcp__unity_hub_available_releases", + "mcp__unity-mcp__unity_hub_install_editor","mcp__unity-mcp__unity_hub_install_modules", + "mcp__unity-mcp__unity_hub_get_install_path","mcp__unity-mcp__unity_hub_set_install_path", + # Multi-Instance & Project Context + "mcp__unity-mcp__unity_list_instances","mcp__unity-mcp__unity_select_instance", + "mcp__unity-mcp__unity_get_project_context" +) +$claudeSettingsJson = [ordered]@{ model = $CLAUDE_MODEL; allowedTools = $mcpAllowedTools } | + ConvertTo-Json -Depth 3 $writeClaudeSettingsCmd = @" mkdir -p ~/.claude cat > ~/.claude/settings.json << 'SETTINGS' -{"model": "$CLAUDE_MODEL"} +$claudeSettingsJson SETTINGS true "@ @@ -472,7 +536,7 @@ Invoke-WSL $addEnvCmd -IgnoreError | Out-Null # Windows 侧 Claude 配置 $claudeDir = "$env:USERPROFILE\.claude" if (-not (Test-Path $claudeDir)) { New-Item -ItemType Directory -Path $claudeDir | Out-Null } -@{ model = $CLAUDE_MODEL } | ConvertTo-Json | Set-Content "$claudeDir\settings.json" -Encoding UTF8 +$claudeSettingsJson | Set-Content "$claudeDir\settings.json" -Encoding UTF8 if ($ANTHROPIC_API_KEY) { [System.Environment]::SetEnvironmentVariable("ANTHROPIC_API_KEY", $ANTHROPIC_API_KEY, "User") [System.Environment]::SetEnvironmentVariable("ANTHROPIC_BASE_URL", $ANTHROPIC_BASE_URL, "User")