-
-
Notifications
You must be signed in to change notification settings - Fork 84
Refactoring/mcp tools optimization #355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Changed Tool_GameObject.Find from an async method returning a ResponseCallValueTool to a synchronous method returning GameObjectFindResponse directly. Updated all related tests to remove coroutine/yield logic and use standard [Test] attributes, simplifying assertions and response handling. This improves test clarity and aligns the API with synchronous usage patterns.
…ling and serialization; introduce GameObjectData and SceneData models
…nse structure - Updated GameObject.Destroy to throw exceptions on errors instead of returning error messages. - Refactored GameObject.DestroyComponents to return a structured response with destroyed components and errors. - Changed GameObject.Duplicate to return a list of duplicated GameObject references instead of a success message. - Enhanced GameObject.Modify to handle errors more gracefully and return a detailed modification result. - Added new SceneRef and SceneData classes for better scene management and data handling. - Introduced ComponentDataShallow for lightweight component data representation. - Updated various extension methods to utilize new constructors for ObjectRef and GameObjectRef. - Removed obsolete Models.meta file and cleaned up unused imports in tests. - Improved test validation methods to allow for optional success message checks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request refactors the Unity MCP Plugin's Editor scripting API to improve UI feedback, error handling, and API design. The changes move away from string-based returns and error messages toward structured responses and exception-based error handling, while adding immediate UI refresh calls after operations that modify Unity Editor state.
Key Changes:
- Added UI refresh calls (RepaintProjectWindow, RepaintHierarchyWindow, RepaintAllViews) after all operations that modify assets or GameObjects to ensure immediate visual feedback
- Refactored GameObject API methods to return structured data types (GameObjectRef, AddComponentResponse) and throw exceptions instead of returning error strings
- Introduced new data classes (SceneRef, SceneData, GameObjectData) to provide richer structured responses
Reviewed changes
Copilot reviewed 47 out of 48 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| TestToolGameObject.ModifyComponent.cs | Updated test helper to support optional success message validation for new API behavior |
| TestToolGameObject.GetComponents.cs | Simplified test to work with synchronous Find method that now returns GameObjectData directly |
| TestToolGameObject.Find.cs | Converted async tests to synchronous, updated to work with new Find method that returns GameObjectData instead of ResponseCallValueTool |
| TestJsonSchema.cs | Updated test to reference renamed ComponentDataShallow class |
| ExtensionsRuntimeObjectRef.cs | Simplified ToObjectRef to use new ObjectRef constructor overload |
| ExtensionsRuntimeGameObjectRef.cs | Simplified ToGameObjectRef to use new GameObjectRef constructor overload |
| ExtensionsRuntimeAssetObjectRef.cs | Updated ToAssetObjectRef to use new AssetObjectRef constructor overload |
| SceneRef.cs.meta | Added Unity meta file for new SceneRef class |
| SceneRef.cs | New class providing scene reference functionality |
| SceneData.cs.meta | Added Unity meta file for new SceneData class |
| SceneData.cs | New class providing structured scene data with hierarchy information |
| ObjectRef.cs | Added constructor overload accepting UnityEngine.Object for easier instantiation |
| GameObjectRef.cs | Added constructor overload that extracts name and path from GameObject |
| GameObjectData.cs.meta | Added Unity meta file for new GameObjectData class |
| GameObjectData.cs | New class providing structured GameObject data with serialization options |
| ComponentRef.cs | Added constructor overload that extracts component metadata automatically |
| ComponentDataShallow.cs.meta | Added Unity meta file for renamed class |
| ComponentDataShallow.cs | Renamed from ComponentDataLight, added constructor, reordered fields |
| ComponentData.cs | Updated base class reference to ComponentDataShallow, added constructor |
| AssetObjectRef.cs | Added constructor overload that extracts asset path and GUID |
| Scene.cs | Added LoadedScenes property and renamed LoadedScenesText |
| Scene.Unload.cs | Updated to use LoadedScenesText property |
| Scene.Save.cs | Added UI refresh calls after saving scenes |
| Scene.Load.cs | Added UI refresh calls after loading scenes |
| Scene.GetLoaded.cs | Changed return type from string to SceneData[] for structured response |
| Scene.GetHierarchy.cs | Changed return type to SceneMetadata and throws exceptions on errors |
| Scene.Create.cs | Added UI refresh calls after creating scenes |
| GameObject.SetParent.cs | Added UI refresh calls after parenting operations |
| GameObject.Modify.cs | Added UI refresh call after modifications |
| GameObject.Find.cs | Simplified to return GameObjectData directly, removed async operation |
| GameObject.Duplicate.cs | Changed return type to List and throws exceptions on errors |
| GameObject.DestroyComponents.cs | Changed return type to DestroyComponentsResponse with structured data |
| GameObject.Destroy.cs | Changed to void method that throws exceptions |
| GameObject.Create.cs | Changed return type to GameObjectRef, uses nullable PrimitiveType enum |
| GameObject.AddComponent.cs | Changed return type to AddComponentResponse with structured component data |
| Editor.Selection.Set.cs | Added UI refresh call after selection changes |
| Component.cs | Made AllComponentTypes public for external access |
| Assets.Prefab.Save.cs | Added UI refresh calls after prefab save |
| Assets.Prefab.Open.cs | Added UI refresh calls after prefab open |
| Assets.Prefab.Instantiate.cs | Added UI refresh calls after prefab instantiation |
| Assets.Prefab.Create.cs | Added UI refresh calls after prefab creation |
| Assets.Prefab.Close.cs | Added UI refresh calls after prefab close |
| Assets.Move.cs | Added UI refresh calls after asset moves |
| Assets.Modify.cs | Added UI refresh calls after asset modifications |
| Assets.Material.Create.cs | Added UI refresh calls after material creation |
| Assets.Delete.cs | Added UI refresh calls after asset deletion |
| Assets.CreateFolders.cs | Added UI refresh calls (but has critical bug - see comments) |
| Assets.Copy.cs | Added UI refresh calls after asset copying |
Comments suppressed due to low confidence (1)
Unity-MCP-Plugin/Assets/root/Runtime/Data/ComponentDataShallow.cs:46
- The extension class names still reference "ComponentDataLight" but should be updated to "ComponentDataShallow" to match the renamed class. This creates a naming inconsistency where the class is named ComponentDataShallow but its extension classes reference the old name.
Unity-MCP-Plugin/Assets/root/Editor/Scripts/API/Tool/GameObject.DestroyComponents.cs
Outdated
Show resolved
Hide resolved
Unity-MCP-Plugin/Assets/root/Editor/Scripts/API/Tool/Scene.Create.cs
Outdated
Show resolved
Hide resolved
…rror handling and asset type management
…hensive schema checks; add conversion function for MCP tools to OpenAI format and improve error handling.
- Updated tool titles for better organization and clarity in the MCP Plugin: - Changed "Instantiate prefab" to "Assets / Prefab / Instantiate" - Changed "Open prefab" to "Assets / Prefab / Open" - Changed "Save prefab" to "Assets / Prefab / Save" - Changed "Assets Refresh" to "Assets / Refresh" - Changed "List all shader names" to "Assets / List Shaders" - Changed "Get list of all Components" to "Components / List" - Changed "Get Unity Console Logs" to "Console / Get Logs" - Removed obsolete Assets.Read.cs file to streamline the codebase. - Introduced new tools for managing Unity Editor application state: - Added Editor.Application.GetState.cs to retrieve the current state of the Unity Editor. - Added Editor.Application.SetState.cs to control the Unity Editor application state (play, pause, stop). - Enhanced Editor.Selection tools: - Updated Editor.Selection.Get.cs and Editor.Selection.Set.cs to provide more detailed selection data. - Introduced SelectionData class to encapsulate selection information. - Added utility functions for editor asset loading and window repainting in EditorUtils.cs. - Improved material reflection converters to ensure editor state is updated after property changes. - Cleaned up unnecessary using directives and improved code readability across various files.
…from InstanceID description keywords
…jectRef description to include Packages folder.
- Updated titles for various tools to follow a consistent naming convention. - Introduced new Scene.GetData tool to retrieve root GameObjects in a specified scene. - Added Scene.ListOpened tool to return currently opened scenes in the Unity Editor. - Removed obsolete Scene.Load tool and replaced it with Scene.Open for better clarity. - Enhanced Scene.Save tool to allow saving of the active scene or a specified scene. - Implemented Scene.SetActive tool to set a specified scene as the active scene. - Updated Scene.Unload tool to correctly reference opened scenes instead of loaded scenes. - Created SceneData and SceneDataShallow classes for better scene data management. - Refactored AssetObjectRef and GameObjectRef to improve asset handling. - Added utility methods for checking if an object is an asset and retrieving its path. - Removed deprecated SceneMetadata class to streamline the codebase.
- Changed tool identifiers from uppercase and underscore format to lowercase and hyphenated format across multiple scripts for consistency and improved readability. - Updated identifiers in the following files: - Assets.Copy.cs - Assets.CreateFolders.cs - Assets.Delete.cs - Assets.Find.cs - Assets.GetData.cs - Assets.Material.Create.cs - Assets.Modify.cs - Assets.Move.cs - Assets.Prefab.Close.cs - Assets.Prefab.Create.cs - Assets.Prefab.Instantiate.cs - Assets.Prefab.Open.cs - Assets.Prefab.Save.cs - Assets.Prefab.cs - Assets.Refresh.cs - Assets.Shader.ListAll.cs - Component.GetAll.cs - Console.GetLogs.cs - Editor.Application.GetState.cs - Editor.Application.SetState.cs - Editor.Selection.Get.cs - Editor.Selection.Set.cs - GameObject.Component.Add.cs - GameObject.Component.Destroy.cs - GameObject.Create.cs - GameObject.Destroy.cs - GameObject.Duplicate.cs - GameObject.Find.cs - GameObject.Modify.cs - GameObject.SetParent.cs - Reflection.MethodCall.cs - Reflection.MethodFind.cs - Scene.Create.cs - Scene.GetData.cs - Scene.ListOpened.cs - Scene.Open.cs - Scene.Save.cs - Scene.SetActive.cs - Scene.Unload.cs - Script.Delete.cs - Script.Execute.cs - Script.Read.cs - Script.UpdateOrCreate.cs - TestRunner.Run.cs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 94 out of 104 changed files in this pull request and generated 5 comments.
…thod signatures and responses
…d identifiers to use hyphenated format
This pull request introduces several improvements and refactorings to the Unity MCP plugin's asset management tools. The main focus is on standardizing API method names and titles, improving response structures for asset operations, enhancing UI feedback by repainting editor windows after asset changes, and adding new functionality for asset data retrieval. Additionally, there is a shift from string-based responses to structured data models for better integration and error handling.
API Standardization and Naming Consistency:
"Assets_Copy") to kebab-case (e.g.,"assets-copy") and updating titles for clarity and consistency across the codebase. [1] [2] [3] [4] [5] [6]Improved Asset Operation Responses:
CopyandFindasset methods to return structured response types (CopyAssetsResponseandList<AssetObjectRef>) instead of plain strings, allowing for more robust error reporting and data handling. [1] [2] [3]Editor UI Feedback Enhancements:
New Functionality:
GetDatamethod to retrieve all serializable fields and properties of a specified asset, returning aSerializedMemberfor introspection or further processing.Code Cleanup and Deprecation:
Assets.Loadtool, likely replaced by the newGetDataapproach.These changes collectively improve the maintainability, usability, and integration potential of the asset management tools in the Unity MCP plugin.