Skip to content

Commit 4b2b963

Browse files
committed
fix(prefabs): wire missing C# handler for editor/prefab-stage resource
The mcpforunity://editor/prefab-stage resource was wired Python-side in PR #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.
1 parent da5de7a commit 4b2b963

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System;
2+
using MCPForUnity.Editor.Helpers;
3+
using Newtonsoft.Json.Linq;
4+
using UnityEditor.SceneManagement;
5+
6+
namespace MCPForUnity.Editor.Resources.Editor
7+
{
8+
/// <summary>
9+
/// Returns information about the currently open Prefab Stage (Isolation or
10+
/// In-Context mode), or { isOpen = false } when no prefab is being edited.
11+
///
12+
/// Wires up the existing <c>mcpforunity://editor/prefab-stage</c> resource
13+
/// (Server/src/services/resources/prefab_stage.py) which dispatches the
14+
/// <c>get_prefab_stage</c> command name expected by this handler.
15+
/// </summary>
16+
[McpForUnityResource("get_prefab_stage")]
17+
public static class GetPrefabStage
18+
{
19+
public static object HandleCommand(JObject @params)
20+
{
21+
try
22+
{
23+
var stage = PrefabStageUtility.GetCurrentPrefabStage();
24+
if (stage == null)
25+
return new SuccessResponse("No prefab stage open.", new { isOpen = false });
26+
27+
var root = stage.prefabContentsRoot;
28+
return new SuccessResponse("Retrieved prefab stage info.", new
29+
{
30+
isOpen = true,
31+
assetPath = stage.assetPath,
32+
prefabRootName = root != null ? root.name : null,
33+
mode = stage.mode.ToString(),
34+
isDirty = stage.scene.isDirty,
35+
});
36+
}
37+
catch (Exception e)
38+
{
39+
return new ErrorResponse($"Error getting prefab stage: {e.Message}");
40+
}
41+
}
42+
}
43+
}

MCPForUnity/Editor/Resources/Editor/GetPrefabStage.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)