Prefab stages integration#1013
Conversation
Reviewer's GuideMoves prefab stage open/save/close functionality from the generic editor tool into the prefab management tool, updates CLI/API/docs/tests to route prefab stage workflows through manage_prefabs instead of manage_editor, and extends ManagePrefabs to support interactive prefab stage workflows alongside headless editing. Sequence diagram for prefab stage open/save/close via manage_prefabssequenceDiagram
actor Developer
participant CLI as prefab_CLI_commands
participant Server as manage_prefabs_tool_python
participant UnityInstance
participant ManagePrefabsCS as ManagePrefabs_CSharp
participant PrefabStageUtility
participant EditorSceneManager
participant StageUtility
Developer->>CLI: prefab open-stage path
CLI->>Server: manage_prefabs(action=open_prefab_stage, prefab_path)
Server->>UnityInstance: async_send_command_with_retry(tool=manage_prefabs, params)
UnityInstance->>ManagePrefabsCS: HandleCommand(params)
ManagePrefabsCS->>ManagePrefabsCS: OpenPrefabStage(prefabPath)
ManagePrefabsCS->>PrefabStageUtility: OpenPrefab(sanitizedPath)
PrefabStageUtility-->>ManagePrefabsCS: PrefabStage(assetPath, prefabContentsRoot)
ManagePrefabsCS-->>UnityInstance: SuccessResponse(prefabPath, rootName, enteredPrefabStage)
UnityInstance-->>Server: result
Server-->>CLI: result
CLI-->>Developer: "Opened prefab stage" message
Developer->>CLI: prefab save-stage
CLI->>Server: manage_prefabs(action=save_prefab_stage)
Server->>UnityInstance: async_send_command_with_retry(tool=manage_prefabs, params)
UnityInstance->>ManagePrefabsCS: HandleCommand(params)
ManagePrefabsCS->>ManagePrefabsCS: SavePrefabStage()
ManagePrefabsCS->>PrefabStageUtility: GetCurrentPrefabStage()
PrefabStageUtility-->>ManagePrefabsCS: PrefabStage(assetPath, scene)
ManagePrefabsCS->>EditorSceneManager: MarkSceneDirty(scene)
ManagePrefabsCS->>EditorSceneManager: SaveScene(scene)
EditorSceneManager-->>ManagePrefabsCS: saved=true
ManagePrefabsCS-->>UnityInstance: SuccessResponse(prefabPath, saved)
UnityInstance-->>Server: result
Server-->>CLI: result
CLI-->>Developer: "Saved prefab stage" message
Developer->>CLI: prefab close-stage --save
CLI->>Server: manage_prefabs(action=close_prefab_stage, saveBeforeClose=true)
Server->>UnityInstance: async_send_command_with_retry(tool=manage_prefabs, params)
UnityInstance->>ManagePrefabsCS: HandleCommand(params)
ManagePrefabsCS->>ManagePrefabsCS: ClosePrefabStage(saveBeforeClose=true)
ManagePrefabsCS->>ManagePrefabsCS: SavePrefabStage()
ManagePrefabsCS->>PrefabStageUtility: GetCurrentPrefabStage()
PrefabStageUtility-->>ManagePrefabsCS: PrefabStage(assetPath, scene)
ManagePrefabsCS->>EditorSceneManager: MarkSceneDirty(scene)
ManagePrefabsCS->>EditorSceneManager: SaveScene(scene)
EditorSceneManager-->>ManagePrefabsCS: saved=true
ManagePrefabsCS->>StageUtility: GoToMainStage()
StageUtility-->>ManagePrefabsCS: mainStageEntered
ManagePrefabsCS-->>UnityInstance: SuccessResponse("Exited prefab stage", prefabPath)
UnityInstance-->>Server: result
Server-->>CLI: result
CLI-->>Developer: "Prefab stage closed" message
Updated class diagram for ManagePrefabs prefab stage methodsclassDiagram
class ManagePrefabs {
<<static>>
+string ACTION_CREATE_FROM_GAMEOBJECT
+string ACTION_GET_INFO
+string ACTION_GET_HIERARCHY
+string ACTION_MODIFY_CONTENTS
+string ACTION_OPEN_PREFAB_STAGE
+string ACTION_SAVE_PREFAB_STAGE
+string ACTION_CLOSE_PREFAB_STAGE
+string SupportedActions
+object HandleCommand(JObject params)
-object GetInfo(JObject params)
-object GetHierarchy(JObject params)
-object ModifyContents(JObject params)
-object CreateFromGameObject(JObject params)
-object OpenPrefabStage(string requestedPath)
-object SavePrefabStage()
-object ClosePrefabStage(bool saveBeforeClose)
}
class ErrorResponse {
+string message
+ErrorResponse(string message)
}
class SuccessResponse {
+string message
+object data
+SuccessResponse(string message)
+SuccessResponse(string message, object data)
}
class AssetPathUtility {
+string SanitizeAssetPath(string requestedPath)
}
class AssetDatabase {
+GameObject LoadAssetAtPath~GameObject~(string path)
}
class PrefabStageUtility {
+PrefabStage OpenPrefab(string assetPath)
+PrefabStage GetCurrentPrefabStage()
}
class PrefabStage {
+string assetPath
+GameObject prefabContentsRoot
+Scene scene
}
class EditorSceneManager {
+void MarkSceneDirty(Scene scene)
+bool SaveScene(Scene scene)
}
class StageUtility {
+void GoToMainStage()
}
class JObject
class GameObject
class Scene
ManagePrefabs --> ErrorResponse : returns_on_failure
ManagePrefabs --> SuccessResponse : returns_on_success
ManagePrefabs --> AssetPathUtility : uses_for_path_sanitization
ManagePrefabs --> AssetDatabase : loads_prefab_asset
ManagePrefabs --> PrefabStageUtility : opens_and_queries_prefab_stage
ManagePrefabs --> EditorSceneManager : saves_prefab_stage_scene
ManagePrefabs --> StageUtility : exits_prefab_stage
PrefabStageUtility --> PrefabStage : returns
PrefabStage --> GameObject : prefabContentsRoot
PrefabStage --> Scene : scene
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughPrefab-stage lifecycle actions (open/save/close) were removed from ManageEditor and moved into a dedicated ManagePrefabs tool; CLI, server tool definitions, Unity editor code, tests, and docs were updated to route and handle prefab-stage workflows via manage_prefabs. Changes
Sequence Diagram(s)sequenceDiagram
participant CLI as CLI
participant Server as Server
participant Tool as ManagePrefabs Tool
participant Editor as Unity Editor (MCPForUnity)
CLI->>Server: run_command("manage_prefabs", {action:"open_prefab_stage", prefab_path})
Server->>Tool: dispatch manage_prefabs action (prefab_path)
Tool->>Editor: HandleCommand -> OpenPrefabStage(prefabPath)
Editor->>Editor: PrefabStageUtility.OpenPrefab(prefab asset)
Editor-->>Tool: response {success: true, metadata}
Tool-->>Server: forward result
Server-->>CLI: return result
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
Moves Unity Prefab Stage open/save/close actions from manage_editor into manage_prefabs to improve tool organization and discoverability.
Changes:
- Added
open_prefab_stage/save_prefab_stage/close_prefab_stagehandling to the Unity-sidemanage_prefabstool and removed them frommanage_editor. - Updated server tooling + CLI to route prefab stage operations through
manage_prefabsinstead ofmanage_editor. - Updated documentation and tests to reflect the new tool/action routing.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| unity-mcp-skill/references/tools-reference.md | Updates docs/examples to use manage_prefabs for prefab stage actions. |
| TestProjects/UnityMCPTests/Assets/Tests/EditMode/Tools/ManagePrefabsStageTests.cs | Renames/updates Unity edit-mode tests to target ManagePrefabs prefab stage actions. |
| TestProjects/UnityMCPTests/Assets/Tests/EditMode/Tools/ManageEditorPrefabStageTests.cs.meta | Removes old Unity meta for the prior test script name (potential rename fallout). |
| Server/tests/test_manage_prefabs.py | Adds server-side tests for prefab stage actions on manage_prefabs. |
| Server/tests/test_manage_editor.py | Removes prefab stage actions from manage_editor forwarded-actions coverage. |
| Server/tests/test_cli_commands_characterization.py | Updates CLI characterization expectation to open_prefab_stage. |
| Server/src/services/tools/manage_prefabs.py | Documents/exposes prefab stage actions in tool description and allowed actions. |
| Server/src/services/tools/manage_editor.py | Removes prefab stage actions/params from manage_editor API surface and docs. |
| Server/src/services/resources/prefab.py | Updates prefab resource docs to reference manage_prefabs for stage transitions. |
| Server/src/cli/commands/prefab.py | Routes prefab open/save/close CLI commands through manage_prefabs and renames actions. |
| MCPForUnity/Editor/Tools/Prefabs/ManagePrefabs.cs | Implements prefab stage open/save/close actions (incl. optional save-before-close) in manage_prefabs. |
| MCPForUnity/Editor/Tools/ManageEditor.cs | Removes prefab stage routing and related methods from manage_editor. |
| MCPForUnity/Editor/Tools/GameObjects/ManageGameObject.cs | Updates guidance text to reference manage_prefabs (not manage_editor) for closing prefab stage. |
Comments suppressed due to low confidence (2)
Server/src/services/tools/manage_prefabs.py:66
manage_prefabsdoesn't currently expose the same optional inputs that the Unity-side tool supports for prefab stage workflows. In particular, the Unity command handler accepts apathalias forprefabPath, andclose_prefab_stagesupportssaveBeforeClose, but this Python tool signature/mapping only allowsprefab_pathand never forwardssaveBeforeClose. Consider addingpath: str | Noneas a compatibility alias (and validating conflicts withprefab_pathlike the oldmanage_editorimplementation did), plus an optionalsave_before_close: bool | Nonethat maps tosaveBeforeClosewhenaction == "close_prefab_stage".
async def manage_prefabs(
ctx: Context,
action: Annotated[
Literal[
"create_from_gameobject",
"get_info",
"get_hierarchy",
"modify_contents",
"open_prefab_stage",
"save_prefab_stage",
"close_prefab_stage",
],
"Prefab operation to perform.",
],
prefab_path: Annotated[str, "Prefab asset path (e.g., Assets/Prefabs/MyPrefab.prefab)."] | None = None,
target: Annotated[str, "Target GameObject: scene object for create_from_gameobject, or object within prefab for modify_contents (name or path like 'Parent/Child')."] | None = None,
allow_overwrite: Annotated[bool, "Allow replacing existing prefab."] | None = None,
search_inactive: Annotated[bool, "Include inactive GameObjects in search."] | None = None,
unlink_if_instance: Annotated[bool, "Unlink from existing prefab before creating new one."] | None = None,
TestProjects/UnityMCPTests/Assets/Tests/EditMode/Tools/ManagePrefabsStageTests.cs:16
- This test script file appears to be missing its corresponding Unity
.metafile (there is noManagePrefabsStageTests.cs.metain the directory, and the PR deletes the oldManageEditorPrefabStageTests.cs.meta). In Unity projects,.metafiles should be committed for scripts to keep stable GUIDs and avoid reimport churn; consider renaming the existing.metaalongside the.csrename (preserving the GUID) or adding the new.metafile.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| { | ||
| if (string.IsNullOrWhiteSpace(requestedPath)) | ||
| { | ||
| return new ErrorResponse("'prefabPath' parameter is required for open_prefab_stage."); |
There was a problem hiding this comment.
OpenPrefabStage accepts both prefabPath and the path alias, but the validation error message only mentions 'prefabPath' parameter is required. This is misleading for callers using the alias; consider updating the message to mention both accepted parameter names.
| return new ErrorResponse("'prefabPath' parameter is required for open_prefab_stage."); | |
| return new ErrorResponse("Either 'prefabPath' or 'path' parameter is required for open_prefab_stage."); |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@Server/src/services/resources/prefab.py`:
- Line 60: The resource payload text references stage lifecycle actions under
manage_prefabs but the related_tools field still lists manage_editor, causing
inconsistency; update the related_tools entries that refer to "manage_editor"
(the ones associated with the prefab stage guidance string "Use manage_prefabs
action=open_prefab_stage / save_prefab_stage / close_prefab_stage") to
"manage_prefabs" in the prefab resource definition (also fix the same mismatch
at the other occurrence around lines 83–85) so callers are guided to the correct
action owner.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 71131d7f-e046-4d05-87e5-33b142d647cd
📒 Files selected for processing (13)
MCPForUnity/Editor/Tools/GameObjects/ManageGameObject.csMCPForUnity/Editor/Tools/ManageEditor.csMCPForUnity/Editor/Tools/Prefabs/ManagePrefabs.csServer/src/cli/commands/prefab.pyServer/src/services/resources/prefab.pyServer/src/services/tools/manage_editor.pyServer/src/services/tools/manage_prefabs.pyServer/tests/test_cli_commands_characterization.pyServer/tests/test_manage_editor.pyServer/tests/test_manage_prefabs.pyTestProjects/UnityMCPTests/Assets/Tests/EditMode/Tools/ManageEditorPrefabStageTests.cs.metaTestProjects/UnityMCPTests/Assets/Tests/EditMode/Tools/ManagePrefabsStageTests.csunity-mcp-skill/references/tools-reference.md
💤 Files with no reviewable changes (1)
- TestProjects/UnityMCPTests/Assets/Tests/EditMode/Tools/ManageEditorPrefabStageTests.cs.meta
| "1. Use manage_asset action=search filterType=Prefab to find prefabs", | ||
| "2. Use the asset path to access detailed data via resources below", | ||
| "3. Use manage_editor action=open_prefab_stage / save_prefab_stage / close_prefab_stage for prefab editing UI transitions" | ||
| "3. Use manage_prefabs action=open_prefab_stage / save_prefab_stage / close_prefab_stage for prefab editing UI transitions" |
There was a problem hiding this comment.
Fix contradictory prefab tool guidance in this resource payload.
Line 60 correctly routes stage lifecycle to manage_prefabs, but related_tools still says manage_editor owns open/save/close stages. This inconsistency can send callers to unsupported actions.
Suggested doc fix
"related_tools": {
- "manage_editor": "Open/save/close prefab stages in the Unity Editor UI",
- "manage_prefabs": "Headless prefab inspection and modification without opening prefab stages",
+ "manage_editor": "Editor controls (play/pause/stop, active tool, tags/layers, package deploy/restore)",
+ "manage_prefabs": "Prefab stage lifecycle (open/save/close) and headless prefab inspection/modification",
"manage_asset": "Search for prefab assets, get asset info",
"manage_gameobject": "Modify GameObjects in open prefab stage",
"manage_components": "Add/remove/modify components on prefab GameObjects"
}Also applies to: 83-85
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@Server/src/services/resources/prefab.py` at line 60, The resource payload
text references stage lifecycle actions under manage_prefabs but the
related_tools field still lists manage_editor, causing inconsistency; update the
related_tools entries that refer to "manage_editor" (the ones associated with
the prefab stage guidance string "Use manage_prefabs action=open_prefab_stage /
save_prefab_stage / close_prefab_stage") to "manage_prefabs" in the prefab
resource definition (also fix the same mismatch at the other occurrence around
lines 83–85) so callers are guided to the correct action owner.
Moving Open/Close prefab stage from Manage_editor into Manage_prefab for better file discovery and management.
Summary by Sourcery
Route prefab stage editing through the manage_prefabs tool instead of manage_editor, and update APIs, CLI commands, and documentation to reflect the new workflow.
New Features:
Enhancements:
Tests:
Summary by CodeRabbit
New Features
Refactor
Documentation
Tests