MCP Unity Editor (Game Engine)
以下摘录自该仓库的 README(片段) · 在 GitHub 读完整 README →
| 🇺🇸English | 🇨🇳简体中文 | 🇯🇵日本語 |
|----------------------|---------------------------------|----------------------|
MCP Unity is an implementation of the Model Context Protocol for Unity Editor, allowing AI assistants to interact with your Unity projects. This package provides a bridge between Unity and a Node.js server that implements the MCP protocol, enabling AI agents like Cursor, Windsurf, Claude Code, Codex CLI, GitHub Copilot, Google Antigravity, and OpenCode to execute operations within the Unity Editor.
Features
IDE Integration - Package Cache Access
MCP Unity provides automatic integration with VSCode-like IDEs (Visual Studio Code, Cursor, Windsurf, Google Antigravity) by adding the Unity Library/PackedCache folder to your workspace. This feature:
- Improves code intelligence for Unity packages
- Enables better autocompletion and type information for Unity packages
- Helps AI coding assistants understand your project's dependencies
MCP Server Tools
The following tools are available for manipulating and querying Unity scenes and GameObjects via MCP:
- execute_menu_item: Executes Unity menu items (functions tagged with the MenuItem attribute)
> **Example prompt:** "Execute the menu item 'GameObject/Create Empty' to create a new empty GameObject"
- select_gameobject: Selects game objects in the Unity hierarchy by path or instance ID
> **Example prompt:** "Select the Main Camera object in my scene"
- update_gameobject: Updates a GameObject's core properties (name, tag, layer, active/static state), or creates the GameObject if it does not exist
> **Example prompt:** "Set the Player object's tag to 'Enemy' and make it inactive"
- update_component: Updates component fields on a GameObject or adds it to the GameObject if it does not contain the component
> **Example prompt:** "Add a Rigidbody component to the Player object and set its mass to 5"
- add_package: Installs new packages in the Unity Package Manager
> **Example prompt:** "Add the TextMeshPro package to my project"
- run_tests: Runs tests using the Unity Test Runner
> **Example prompt:** "Run all the EditMode tests in my project"
- send_console_log: Send a console log to Unity
> **Example prompt:** "Send a console log to Unity Editor"
- add_asset_to_scene: Adds an asset from the AssetDatabase to the Unity scene
> **Example prompt:** "Add the Player prefab from my project to the current scene"
- create_prefab: Creates a prefab with optional MonoBehaviour script and serialized field values
> **Example prompt:** "Create a prefab named 'Player' from the 'PlayerController' script"
- create_scene: Creates a new scene and saves it to the specified path
> **Example prompt:** "Create a new scene called 'Level1' in the Scenes folder"
- load_scene: Loads a scene by path or name, with optional additive loading
> **Example prompt:** "Load the MainMenu scene"
- delete_scene: Deletes a scene by path or name and removes it from Build Settings
> **Example prompt:** "Delete the old TestScene from my project"
- get_gameobject: Gets detailed information about a specific GameObject including all components
> **Example prompt:** "Get the details of the Player GameObject"
- get_console_logs: Retrieves logs from the Unity console with pagination support
> **Example prompt:** "Show me the last 20 error logs from the Unity console"
- recompile_scripts: Recompiles all scripts in the Unity project
> **Example prompt:** "Recompile scripts in my Unity project"
- save_scene: Saves the current active scene, with optional Save As to a new path
> **Example prompt:** "Save the current scene" or "Save the scene as 'Assets/Scenes/Level2.unity'"
- get_scene_info: Gets information about the active scene including name, path, dirty state, and all loaded scenes
> **Example prompt:** "What scenes are currently loaded in my project?"
- unload_scene: Unloads a scene from the hierarchy (does not delete the scene asset)
> **Example prompt:** "Unload the UI scene from the hierarchy"
- duplicate_gameobject: Duplicates a GameObject in the scene with optional renaming and reparenting
> **Example prompt:** "Duplicate the Enemy prefab 5 times and rename them Enemy_1 through Enemy_5"
- delete_gameobject: Deletes a GameObject from the scene
> **Example prompt:** "Delete the old Player object from the scene"
- reparent_gameobject: Changes the parent of a GameObject in the hierarchy
> **Example prompt:** "Move the HealthBar object to be a child of the UI Canvas"
- move_gameobject: Moves a GameObject to a new position (local or world space)