Files
Shutong Wu 7f8ca2a3bd [FEATURE] Custom Tool Fix and Add inspection window for all the tools (#414)
* Update .Bat file and Bug fix on ManageScript

* Update the .Bat file to include runtime folder
* Fix the inconsistent EditorPrefs variable so the GUI change on Script Validation could cause real change.

* Further changes

String to Int for consistency

* [Custom Tool] Roslyn Runtime Compilation

Allows users to generate/compile codes during Playmode

* Fix based on CR

* Create claude_skill_unity.zip

Upload the unity_claude_skill that can be uploaded to Claude for a combo of unity-mcp-skill.

* Update for Custom_Tool Fix and Detection

1. Fix Original Roslyn Compilation Custom Tool to fit the V8 standard
2. Add a new panel in the GUI to see and toggle/untoggle the tools. The toggle feature will be implemented in the future, right now its implemented here to discuss with the team if this is a good feature to add;
3. Add few missing summary in certain tools

* Revert "Update for Custom_Tool Fix and Detection"

This reverts commit ae8cfe5e256c70ac4a16c79d50341a39cbac18ba.

* Update README.md

* Reapply "Update for Custom_Tool Fix and Detection"

This reverts commit f423c2f25e9ccff4f3b89d1d360ee9cf13143733.

* Update ManageScript.cs

Fix the layout problem of manage_script in the panel

* Update

To comply with the current server setting

* Update on Batch

Tested object generation/modification with batch and it works perfectly! We should push and let users test for a while and see

PS: I tried both VS Copilot and Claude Desktop. Claude Desktop works but VS Copilot does not due to the nested structure of batch. Will look into it more.

* Revert "Merge pull request #1 from Scriptwonder/batching"

This reverts commit 55ee76810be161d414e1f5f5abaa5ee30ddd0052, reversing
changes made to ae2eedd7fb2c6a66ff008bacac481aefb1b0d176.
2025-12-07 19:38:32 -05:00

54 lines
2.1 KiB
C#

using System;
using System.Collections.Generic;
using MCPForUnity.Editor.Helpers;
using Newtonsoft.Json.Linq;
using UnityEditor;
namespace MCPForUnity.Editor.Tools
{
[McpForUnityTool("execute_menu_item", AutoRegister = false)]
/// <summary>
/// Tool to execute a Unity Editor menu item by its path.
/// </summary>
public static class ExecuteMenuItem
{
// Basic blacklist to prevent execution of disruptive menu items.
private static readonly HashSet<string> _menuPathBlacklist = new HashSet<string>(
StringComparer.OrdinalIgnoreCase)
{
"File/Quit",
};
public static object HandleCommand(JObject @params)
{
McpLog.Info("[ExecuteMenuItem] Handling menu item command");
string menuPath = @params["menu_path"]?.ToString() ?? @params["menuPath"]?.ToString();
if (string.IsNullOrWhiteSpace(menuPath))
{
return new ErrorResponse("Required parameter 'menu_path' or 'menuPath' is missing or empty.");
}
if (_menuPathBlacklist.Contains(menuPath))
{
return new ErrorResponse($"Execution of menu item '{menuPath}' is blocked for safety reasons.");
}
try
{
bool executed = EditorApplication.ExecuteMenuItem(menuPath);
if (!executed)
{
McpLog.Error($"[MenuItemExecutor] Failed to execute menu item '{menuPath}'. It might be invalid, disabled, or context-dependent.");
return new ErrorResponse($"Failed to execute menu item '{menuPath}'. It might be invalid, disabled, or context-dependent.");
}
return new SuccessResponse($"Attempted to execute menu item: '{menuPath}'. Check Unity logs for confirmation or errors.");
}
catch (Exception e)
{
McpLog.Error($"[MenuItemExecutor] Failed to setup execution for '{menuPath}': {e}");
return new ErrorResponse($"Error setting up execution for menu item '{menuPath}': {e.Message}");
}
}
}
}