Skip to content

feat: add open_prefab_stage action to manage_editor#968

Merged
Scriptwonder merged 1 commit intobetafrom
feat/open-prefab-stage
Mar 23, 2026
Merged

feat: add open_prefab_stage action to manage_editor#968
Scriptwonder merged 1 commit intobetafrom
feat/open-prefab-stage

Conversation

@Scriptwonder
Copy link
Collaborator

@Scriptwonder Scriptwonder commented Mar 23, 2026

Summary

Rebased version of #947 (by @jiajunfeng) onto current beta, resolving merge conflicts with undo/redo additions.

  • Add manage_editor(action="open_prefab_stage") to open a prefab asset in Prefab Stage
  • Expose the new action through the Python MCP tool surface with prefab_path and path (alias) parameters
  • Update prefab resource docs to route prefab stage UI transitions through manage_editor
  • Add Python + Unity edit-mode test coverage

Changes from original PR

  • Rebased onto current beta (resolved conflicts with undo/redo in manage_editor)
  • Merged action Literal types, descriptions, error messages, and test files to include all actions

Test plan

  • cd Server && uv run pytest tests/test_manage_editor.py -v
  • Unity edit-mode tests in ManageEditorPrefabStageTests
  • Manual: manage_editor(action="open_prefab_stage", prefab_path="Assets/Prefabs/SomePrefab.prefab")

Credit: Original implementation by @jiajunfeng (#947)

Summary by Sourcery

Add support for opening Unity prefab stages via the manage_editor tool and wire it through the Unity editor backend and Python MCP surface.

New Features:

  • Introduce an open_prefab_stage action in the Unity ManageEditor handler to open a prefab in prefab editing mode.
  • Expose prefab_path and path parameters on the Python manage_editor MCP tool for triggering prefab stage opens.
  • Document manage_editor usage for prefab editing transitions in prefab resource and tools reference docs.

Enhancements:

  • Extend error messaging for unknown manage_editor actions to list open_prefab_stage and clarify behavior.
  • Add validation and safety checks around prefab paths before opening prefab stages in the Unity editor.

Tests:

  • Add Python tests validating manage_editor prefab_path/path parameters, description, forwarding behavior, and conflict handling.
  • Add Unity edit-mode tests covering open_prefab_stage prefab stage behavior, alias precedence, and error conditions.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added ability to open prefab editing stages by specifying prefab asset paths.
  • Documentation

    • Updated tool reference with examples of prefab editing stage operations.
  • Tests

    • Added comprehensive test coverage for prefab stage operations.

Copilot AI review requested due to automatic review settings March 23, 2026 20:44
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Mar 23, 2026

Reviewer's Guide

Adds a new manage_editor action open_prefab_stage that opens prefab assets in Unity’s Prefab Stage, wires it through the Python MCP tool with prefab_path/path parameters, updates prefab-related docs, and adds Python and Unity edit-mode tests to validate behavior and error handling.

Sequence diagram for manage_editor open_prefab_stage action

sequenceDiagram
    actor Client
    participant MCPServer
    participant ManageEditorTool as ManageEditorTool_manage_editor
    participant UnityConnection as UnityConnection_async_send_command_with_retry
    participant UnityEditor as ManageEditor_HandleCommand
    participant PrefabStage as PrefabStageUtility

    Client->>MCPServer: Call manage_editor(action=open_prefab_stage, prefab_path/path)
    MCPServer->>ManageEditorTool: Invoke manage_editor
    ManageEditorTool->>ManageEditorTool: Validate prefab_path vs path
    alt Both set and mismatch
        ManageEditorTool-->>Client: {success: False, message: conflict error}
    else Valid parameters
        ManageEditorTool->>ManageEditorTool: Build params with action and prefabPath/path
        ManageEditorTool->>UnityConnection: async_send_command_with_retry(params)
        UnityConnection->>UnityEditor: HandleCommand(params)
        UnityEditor->>UnityEditor: Read prefabPath = p.Get(prefabPath) ?? p.Get(path)
        UnityEditor->>UnityEditor: switch(action)
        UnityEditor->>UnityEditor: OpenPrefabStage(prefabPath)
        alt Invalid/missing path or load/open failure
            UnityEditor-->>UnityConnection: ErrorResponse
        else Prefab stage opened
            UnityEditor->>PrefabStage: PrefabStageUtility.OpenPrefab(sanitizedPath)
            PrefabStage-->>UnityEditor: prefabStage
            UnityEditor-->>UnityConnection: SuccessResponse(prefabPath, openedPrefabPath, rootName, enteredPrefabStage)
        end
        UnityConnection-->>ManageEditorTool: Response dict
        ManageEditorTool-->>Client: Response dict
    end
Loading

Class diagram for ManageEditor with new OpenPrefabStage action

classDiagram
    class ManageEditor {
        <<static>>
        +object HandleCommand(JObject params)
        -static object OpenPrefabStage(string requestedPath)
        -static object ClosePrefabStage()
    }

    class AssetPathUtility {
        +static string SanitizeAssetPath(string path)
    }

    class ErrorResponse {
        +ErrorResponse(string message)
    }

    class SuccessResponse {
        +SuccessResponse(string message, object data)
    }

    class AssetDatabase {
        +static GameObject LoadAssetAtPath~GameObject~(string path)
    }

    class PrefabStageUtility {
        +static PrefabStage OpenPrefab(string assetPath)
    }

    class PrefabStage {
        +string assetPath
        +GameObject prefabContentsRoot
    }

    class GameObject {
        +string name
    }

    ManageEditor --> AssetPathUtility : uses
    ManageEditor --> ErrorResponse : returns
    ManageEditor --> SuccessResponse : returns
    ManageEditor --> AssetDatabase : uses
    ManageEditor --> PrefabStageUtility : uses
    PrefabStageUtility --> PrefabStage : creates
    PrefabStage --> GameObject : has prefabContentsRoot
    SuccessResponse --> GameObject : includes rootName in data
Loading

File-Level Changes

Change Details Files
Support opening prefab assets in Prefab Stage via a new open_prefab_stage action in the Unity ManageEditor tool.
  • Parse prefabPath/path from incoming parameters when handling editor commands.
  • Route the new open_prefab_stage action in the ManageEditor command switch.
  • Implement OpenPrefabStage with validation for path presence, Assets folder restriction, .prefab extension enforcement, asset existence checking, and structured success/error responses.
  • Use PrefabStageUtility.OpenPrefab to enter the prefab stage and return metadata such as prefabPath, openedPrefabPath, rootName, and enteredPrefabStage.
MCPForUnity/Editor/Tools/ManageEditor.cs
Expose open_prefab_stage through the Python manage_editor MCP tool with prefab_path and path aliasing and conflict validation.
  • Expand the manage_editor tool description and action Literal to include open_prefab_stage and describe its behavior.
  • Add prefab_path and path parameters to manage_editor with appropriate annotations.
  • Introduce validation that rejects conflicting prefab_path and path values before sending Unity commands.
  • Map prefab_path to prefabPath and path to path in the outgoing params only when provided, keeping None values omitted.
  • Ensure open_prefab_stage is treated as a Unity-forwarded action in tests.
Server/src/services/tools/manage_editor.py
Server/tests/test_manage_editor.py
Update prefab resource documentation and skill references to reflect manage_editor as the entry point for prefab stage UI transitions.
  • Change prefab API docs workflow step to use manage_editor open_prefab_stage / close_prefab_stage for editing UI transitions instead of manage_prefabs.
  • Clarify related_tools section to distinguish manage_editor (UI stage control) from manage_prefabs (headless prefab manipulation).
  • Add an example invocation of manage_editor(action="open_prefab_stage", prefab_path=...) to the tools reference alongside close_prefab_stage.
Server/src/services/resources/prefab.py
unity-mcp-skill/references/tools-reference.md
Add test coverage for open_prefab_stage behavior in both Unity edit mode and the Python MCP layer.
  • Add Python tests to verify manage_editor exposes prefab_path/path parameters, updates tool description, forwards prefab_path/path correctly, and rejects conflicting aliases.
  • Create Unity edit-mode tests for OpenPrefabStage covering required prefabPath, non-prefab path rejection, successful stage opening with returned data, path alias support, and precedence of prefabPath over path.
  • Introduce utility-based prefab creation and cleanup in Unity tests using a temporary Assets/Temp folder.
Server/tests/test_manage_editor.py
TestProjects/UnityMCPTests/Assets/Tests/EditMode/Tools/ManageEditorPrefabStageTests.cs
TestProjects/UnityMCPTests/Assets/Tests/EditMode/Tools/ManageEditorPrefabStageTests.cs.meta

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 23, 2026

📝 Walkthrough

Walkthrough

This PR adds support for opening prefab editing stages directly through the MCP editor tooling interface. It introduces a new open_prefab_stage action in the Unity ManageEditor class, server-side parameter handling for prefab paths, comprehensive test coverage across both server and Unity test suites, and documentation updates demonstrating the new workflow.

Changes

Cohort / File(s) Summary
Unity Editor Prefab Stage Handler
MCPForUnity/Editor/Tools/ManageEditor.cs
Added OpenPrefabStage(string requestedPath) method that validates asset paths, sanitizes via AssetPathUtility.SanitizeAssetPath, enforces .prefab extension and Assets/ location, opens prefab stages via PrefabStageUtility.OpenPrefab, and returns success/error responses. Updated HandleCommand to route open_prefab_stage actions and extract prefabPath parameter.
Server Tool Definition
Server/src/services/tools/manage_editor.py
Added prefab_path and path (alias) optional parameters with validation: rejects conflicting values and returns structured failure. Updated action Literal to include "open_prefab_stage". Constructs command parameters conditionally using prefabPath or path when provided.
Server API Documentation
Server/src/services/resources/prefab.py
Updated prefab_api documentation to reflect new workflow: step 3 now directs to manage_editor actions (open_prefab_stage/close_prefab_stage) for stage operations instead of manage_prefabs. Added manage_editor to related_tools mapping.
Server Tool Tests
Server/tests/test_manage_editor.py
Added assertions verifying prefab_path and path parameters exist with None defaults. Added tests for open_prefab_stage action forwarding, parameter mapping (prefab\_path→prefabPath, path→path), and conflict validation (returns failure when both provided).
Unity Test Suite
TestProjects/UnityMCPTests/Assets/Tests/EditMode/Tools/ManageEditorPrefabStageTests.cs
Added comprehensive test suite covering error cases (missing prefabPath, non-prefab files), successful stage opening with returned stage data, path alias behavior, parameter precedence, and stage closure verification.
Test Metadata & Documentation
TestProjects/UnityMCPTests/Assets/Tests/EditMode/Tools/ManageEditorPrefabStageTests.cs.meta, unity-mcp-skill/references/tools-reference.md
Added Unity serialization metadata for test class. Added example usage demonstrating open_prefab_stage followed by close_prefab_stage.

Sequence Diagram

sequenceDiagram
    participant Client as MCP Client
    participant Server as manage_editor Service
    participant Unity as ManageEditor.HandleCommand
    participant Util as PrefabStageUtility

    Client->>Server: open_prefab_stage<br/>(prefab_path="Assets/...")
    
    Server->>Server: Validate parameters<br/>(ensure single path provided)
    Server->>Server: Construct params<br/>(map to prefabPath)
    Server->>Unity: Forward command<br/>action + params
    
    Unity->>Unity: OpenPrefabStage()<br/>Sanitize & validate path
    Unity->>Util: OpenPrefab(sanitizedPath)
    Util->>Util: Load asset & enter stage
    
    Util-->>Unity: Stage created
    Unity->>Unity: Verify stage entry<br/>(assetPath, prefabContentsRoot)
    
    alt Success
        Unity-->>Server: Success response<br/>(stage/root details)
        Server-->>Client: Success payload
    else Failure
        Unity-->>Server: ErrorResponse
        Server-->>Client: Error details
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Suggested reviewers

  • msanatan
  • justinpbarnett

Poem

🐰 Hops through the Assets, paths held high,
Opening prefab stages to the sky,
Sanitized, validated, tried and true,
Stage by stage, a bunny's-eye view! 🌟

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 23.08% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: add open_prefab_stage action to manage_editor' directly and clearly summarizes the main feature being added across all modified files.
Description check ✅ Passed The pull request description is comprehensive, covering summary, type of change, specific changes, testing instructions, and documentation updates; however, the documentation update checklist boxes are unchecked despite documentation being updated.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/open-prefab-stage

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new manage_editor action for opening Unity Prefab Stage, wiring it through the Python MCP tool surface and updating prefab documentation and tests to reflect the new UI transition flow.

Changes:

  • Add open_prefab_stage handling to Unity ManageEditor plus prefab-path validation and structured response data.
  • Expose prefab_path (and path alias) on the Python manage_editor tool and add Python + Unity edit-mode tests.
  • Update prefab resource docs and tools reference to direct prefab-stage UI transitions through manage_editor.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
unity-mcp-skill/references/tools-reference.md Documents the new open_prefab_stage usage example.
TestProjects/UnityMCPTests/Assets/Tests/EditMode/Tools/ManageEditorPrefabStageTests.cs.meta Adds Unity meta file for the new edit-mode test.
TestProjects/UnityMCPTests/Assets/Tests/EditMode/Tools/ManageEditorPrefabStageTests.cs Adds Unity edit-mode coverage for open/close prefab stage and alias behavior.
Server/tests/test_manage_editor.py Adds Python tests for tool surface parameters, description, forwarding, and conflict handling.
Server/src/services/tools/manage_editor.py Adds open_prefab_stage action + prefab_path/path parameter forwarding.
Server/src/services/resources/prefab.py Updates prefab API docs to route prefab-stage UI transitions via manage_editor.
MCPForUnity/Editor/Tools/ManageEditor.cs Implements open_prefab_stage action with path sanitization and stage-opening logic.

💡 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.");
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

open_prefab_stage now accepts both 'prefabPath' and the compatibility alias 'path' (see HandleCommand extracting prefabPath = p.Get("prefabPath") ?? p.Get("path")), but the validation error still says only "'prefabPath' parameter is required". This is misleading for callers using the alias; update the message to mention both accepted keys (e.g., prefabPath or path).

Suggested change
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.");

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@MCPForUnity/Editor/Tools/ManageEditor.cs`:
- Around line 47-50: Before collapsing aliases, validate that callers do not
supply conflicting prefab/path values: read both p.Get("prefabPath") and
p.Get("path") into temporaries (treat empty string as missing via
string.IsNullOrEmpty), and if both are present (non-empty) reject/return an
error the same way the Python service does; only after this guard set prefabPath
= non-empty prefabPath if present else path. Reference the variables prefabPath,
p.Get("prefabPath"), p.Get("path") and the handler method in ManageEditor.cs
(e.g., the OpenPrefabStage dispatch) to locate where to add the guard.

In `@Server/tests/test_manage_editor.py`:
- Around line 150-161: The test
test_open_prefab_stage_rejects_conflicting_path_inputs must also assert that no
Unity command was sent: ensure mock_unity (the fixture) did not have
send_with_unity_instance invoked when manage_editor is called with both
prefab_path and path; after calling manage_editor, add an assertion that
mock_unity.send_with_unity_instance was not called (or use
mock_unity.assert_not_called()/mock_unity.send_with_unity_instance.assert_not_called())
to guarantee the failure occurs before dispatch to Unity.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c064c07a-b5b5-40a9-bf69-d6ba21752ce7

📥 Commits

Reviewing files that changed from the base of the PR and between 8accc74 and fb97d6c.

📒 Files selected for processing (7)
  • MCPForUnity/Editor/Tools/ManageEditor.cs
  • Server/src/services/resources/prefab.py
  • Server/src/services/tools/manage_editor.py
  • Server/tests/test_manage_editor.py
  • TestProjects/UnityMCPTests/Assets/Tests/EditMode/Tools/ManageEditorPrefabStageTests.cs
  • TestProjects/UnityMCPTests/Assets/Tests/EditMode/Tools/ManageEditorPrefabStageTests.cs.meta
  • unity-mcp-skill/references/tools-reference.md

Comment on lines 47 to +50
// Parameters for specific actions
string tagName = p.Get("tagName");
string layerName = p.Get("layerName");
string prefabPath = p.Get("prefabPath") ?? p.Get("path");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Reject mismatched prefabPath/path in the Unity handler too.

Line 50 collapses the aliases before validation, so a direct manage_editor caller that sends both values will silently prefer prefabPath instead of failing. It also lets prefabPath="" mask a valid path alias because ?? only falls back on null. The Python surface already rejects conflicting values in Server/src/services/tools/manage_editor.py at Lines 44-48, so the editor layer should enforce the same contract. If you take this route, the new OpenPrefabStage_PrefabPathTakesPrecedenceOverPath test should flip to a rejection case as well.

🛡️ Add the guard before dispatch
-            string prefabPath = p.Get("prefabPath") ?? p.Get("path");
+            string prefabPathParam = p.Get("prefabPath");
+            string pathParam = p.Get("path");
+            if (
+                !string.IsNullOrWhiteSpace(prefabPathParam)
+                && !string.IsNullOrWhiteSpace(pathParam)
+                && !string.Equals(prefabPathParam, pathParam, StringComparison.Ordinal)
+            )
+            {
+                return new ErrorResponse("Provide only one of 'prefabPath' or 'path', or ensure both match.");
+            }
+            string prefabPath = !string.IsNullOrWhiteSpace(prefabPathParam)
+                ? prefabPathParam
+                : pathParam;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@MCPForUnity/Editor/Tools/ManageEditor.cs` around lines 47 - 50, Before
collapsing aliases, validate that callers do not supply conflicting prefab/path
values: read both p.Get("prefabPath") and p.Get("path") into temporaries (treat
empty string as missing via string.IsNullOrEmpty), and if both are present
(non-empty) reject/return an error the same way the Python service does; only
after this guard set prefabPath = non-empty prefabPath if present else path.
Reference the variables prefabPath, p.Get("prefabPath"), p.Get("path") and the
handler method in ManageEditor.cs (e.g., the OpenPrefabStage dispatch) to locate
where to add the guard.

Comment on lines +150 to +161
def test_open_prefab_stage_rejects_conflicting_path_inputs(mock_unity):
"""Conflicting aliases should fail fast before sending a Unity command."""
result = asyncio.run(
manage_editor(
SimpleNamespace(),
action="open_prefab_stage",
prefab_path="Assets/Prefabs/Primary.prefab",
path="Assets/Prefabs/Alias.prefab",
)
)
assert result["success"] is False
assert "Provide only one of prefab_path or path" in result.get("message", "")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Assert that the conflicting alias case never reaches Unity.

This test verifies the error message, but not the promised "fail before dispatch" behavior. Without checking mock_unity, it would still pass if send_with_unity_instance were called and the failure were synthesized afterward.

🧪 Tighten the expectation
 def test_open_prefab_stage_rejects_conflicting_path_inputs(mock_unity):
     """Conflicting aliases should fail fast before sending a Unity command."""
     result = asyncio.run(
         manage_editor(
             SimpleNamespace(),
             action="open_prefab_stage",
             prefab_path="Assets/Prefabs/Primary.prefab",
             path="Assets/Prefabs/Alias.prefab",
         )
     )
     assert result["success"] is False
     assert "Provide only one of prefab_path or path" in result.get("message", "")
+    assert "params" not in mock_unity
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def test_open_prefab_stage_rejects_conflicting_path_inputs(mock_unity):
"""Conflicting aliases should fail fast before sending a Unity command."""
result = asyncio.run(
manage_editor(
SimpleNamespace(),
action="open_prefab_stage",
prefab_path="Assets/Prefabs/Primary.prefab",
path="Assets/Prefabs/Alias.prefab",
)
)
assert result["success"] is False
assert "Provide only one of prefab_path or path" in result.get("message", "")
def test_open_prefab_stage_rejects_conflicting_path_inputs(mock_unity):
"""Conflicting aliases should fail fast before sending a Unity command."""
result = asyncio.run(
manage_editor(
SimpleNamespace(),
action="open_prefab_stage",
prefab_path="Assets/Prefabs/Primary.prefab",
path="Assets/Prefabs/Alias.prefab",
)
)
assert result["success"] is False
assert "Provide only one of prefab_path or path" in result.get("message", "")
assert "params" not in mock_unity
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Server/tests/test_manage_editor.py` around lines 150 - 161, The test
test_open_prefab_stage_rejects_conflicting_path_inputs must also assert that no
Unity command was sent: ensure mock_unity (the fixture) did not have
send_with_unity_instance invoked when manage_editor is called with both
prefab_path and path; after calling manage_editor, add an assertion that
mock_unity.send_with_unity_instance was not called (or use
mock_unity.assert_not_called()/mock_unity.send_with_unity_instance.assert_not_called())
to guarantee the failure occurs before dispatch to Unity.

@Scriptwonder Scriptwonder merged commit e2c30b0 into beta Mar 23, 2026
7 of 8 checks passed
@Scriptwonder Scriptwonder deleted the feat/open-prefab-stage branch March 23, 2026 21:21
zaferdace added a commit to zaferdace/unity-mcp that referenced this pull request Mar 26, 2026
Adds save_prefab_stage to manage_editor to complete the prefab stage
workflow alongside the existing open_prefab_stage and close_prefab_stage.

- C#: SavePrefabStage() uses EditorSceneManager.MarkSceneDirty +
  SaveScene on the prefab stage scene, returns ErrorResponse when no
  stage is open or save fails
- Python: adds save_prefab_stage to action Literal and tool description
- Tests: 3 new tests covering forwarding, description, and clean params

open_prefab_stage was already merged in CoplayDev#968. This PR only adds
save_prefab_stage.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants