fix(prefabs): wire missing C# handler for editor/prefab-stage resource#1136
fix(prefabs): wire missing C# handler for editor/prefab-stage resource#1136slikk66 wants to merge 1 commit into
Conversation
The mcpforunity://editor/prefab-stage resource was wired Python-side in PR CoplayDev#1013 ("Prefab stages integration") via Server/src/services/resources/prefab_stage.py, but its dispatched `get_prefab_stage` command name was never given a C# handler. Reading the resource hits CommandRegistry's not-found throw: Unknown or unsupported command type: get_prefab_stage This change adds GetPrefabStage at MCPForUnity/Editor/Resources/Editor/GetPrefabStage.cs, returning the 5 fields the Python PrefabStageResponse pydantic model expects (isOpen, assetPath, prefabRootName, mode, isDirty) via PrefabStageUtility.GetCurrentPrefabStage(). Mirrors the EditorState.cs sibling resource's shape. No Python-side or schema changes required.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughA new ChangesPrefab Stage Query Handler
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
Description
The
mcpforunity://editor/prefab-stageresource was wired Python-side in PR #1013 ("Prefab stages integration") viaServer/src/services/resources/prefab_stage.py, but its dispatchedget_prefab_stagecommand name was never given a C# handler. Reading the resource hitsCommandRegistry's not-found throw with:This change adds the missing handler at
MCPForUnity/Editor/Resources/Editor/GetPrefabStage.cs, returning the 5 fields the PythonPrefabStageResponsepydantic model expects (isOpen,assetPath,prefabRootName,mode,isDirty) viaPrefabStageUtility.GetCurrentPrefabStage(). Mirrors theEditorState.cssibling resource's shape exactly.No Python-side or schema changes required — the existing Python resource already dispatches the correct command name.
Type of Change
Changes Made
MCPForUnity/Editor/Resources/Editor/GetPrefabStage.cs— new[McpForUnityResource("get_prefab_stage")]static class withHandleCommand(JObject @params)methodPrefabStageUtility.GetCurrentPrefabStage(){ isOpen = false }when no stage openmode.ToString()produces"InIsolation"or"InContext")prefabContentsRootfor the (rare) domain-reload edge caseMCPForUnity/Editor/Resources/Editor/GetPrefabStage.cs.meta— Unity asset meta with fresh GUIDTesting/Screenshots/Recordings
Tested end-to-end against a local Unity 6 (Unity 6000.4.0f1) project running the patched package via UPM git URL pointing at this branch.
Test 1 — prefab open in isolation mode (
Assets/UI/Prefabs/Buttons/SmallCardFrame.prefabdouble-clicked):All 5 fields populate correctly.
mode="InIsolation"confirmsstage.mode.ToString()produces the string form the pydantic model expects. PythonPrefabStageResponse.datavalidates cleanly throughparse_resource_response.Test 2 — no prefab open: trivially covered by the single null-check branch (
if (stage == null) return new SuccessResponse(..., new { isOpen = false })); not exercised live in testing since no logic could differ from the inspection-evident path.Documentation Updates
tools/UPDATE_DOCS_PROMPT.md(recommended)tools/UPDATE_DOCS.mdRationale for unchecked docs sub-boxes: This is a bug-fix wiring a previously-shipped resource (
editor_prefab_stageis already listed inREADME.mdline 103's Available Resources, added by PR #1013). No new resource is introduced. Verified that recent bug-fix PRs (#1106, #1103) do not touchREADME.mdormanifest.json— those documents are reserved for feature releases per repo convention.manifest.jsontoolsarray doesn't list resources, so no entry to add.docs/i18n/README-zh.mdmirrors README and needs no change either. Happy to add a "Recent Updates" entry if reviewer prefers — current convention seems to reserve those for new tools/resources.Related Issues
No existing GitHub issue references this bug (searched via
gh search prs --repo CoplayDev/unity-mcp 'prefab stage'). Considered filing one but decided a direct PR with the fix is lower-friction since the root cause and remedy are both trivial to verify from the source.Additional Notes
Root cause analysis (in case it helps future maintainers): the orphan came from PR #1013. That PR introduced the prefab-stages feature, adding the Python resource (
Server/src/services/resources/prefab_stage.py) and three Unity-side action handlers inManagePrefabs.cs(open_prefab_stage,save_prefab_stage,close_prefab_stage). The fourth action —get_prefab_stage— was scoped as a read-state RESOURCE (not a tool action), so it sits inMCPForUnity/Editor/Resources/Editor/alongsideEditorState.csrather than as an action underManagePrefabs.HandleCommand. The resource description inmcpforunity://prefab-apidescribes the expected 5-field return shape, which this PR delivers.Tests: No test files added. Verified that none of the 19 sibling
[McpForUnityResource]handlers across the codebase have associated C# unit tests (MCPForUnity/Editor/Resources/**has no*Tests.csfiles for any handler;TestProjects/UnityMCPTests/Assets/Tests/EditMode/coversTools/only). No Python test exists forprefab_stage.pyeither. Following established precedent of no per-handler tests for resources.Compatibility:
PrefabStageUtility.GetCurrentPrefabStage()and thePrefabStage.assetPath/prefabContentsRoot/mode/scene.isDirtyAPI surface have all been stable since Unity 2018.3 and exist on the documented minimum supported version (Unity 2021.3 LTS+ perREADME.md). No backwards-compatibility shim needed.Summary by CodeRabbit