diff --git a/Editor/Commands/EditorControlHandler.cs b/Editor/Commands/EditorControlHandler.cs
index 7525711..256a720 100644
--- a/Editor/Commands/EditorControlHandler.cs
+++ b/Editor/Commands/EditorControlHandler.cs
@@ -5,7 +5,7 @@ using Newtonsoft.Json.Linq;
using System;
using System.Reflection;
using System.Collections.Generic;
-using System.Linq; // Add LINQ namespace for Select extension method
+using System.Linq; // Add LINQ namespace for Select extension method
using System.Globalization;
///
@@ -39,6 +39,8 @@ public static class EditorControlHandler
return HandleExecuteCommand(commandParams);
case "READ_CONSOLE":
return ReadConsole(commandParams);
+ case "GET_AVAILABLE_COMMANDS":
+ return GetAvailableCommands();
default:
return new { error = $"Unknown editor control command: {command}" };
}
@@ -105,11 +107,7 @@ public static class EditorControlHandler
buildPlayerOptions.locationPathName = buildPath;
BuildReport report = BuildPipeline.BuildPlayer(buildPlayerOptions);
- return new
- {
- message = "Build completed successfully",
- summary = report.summary
- };
+ return new { message = "Build completed successfully", summary = report.summary };
}
catch (System.Exception e)
{
@@ -147,10 +145,14 @@ public static class EditorControlHandler
// Get filter parameters if provided
if (@params != null)
{
- if (@params["show_logs"] != null) showLogs = (bool)@params["show_logs"];
- if (@params["show_warnings"] != null) showWarnings = (bool)@params["show_warnings"];
- if (@params["show_errors"] != null) showErrors = (bool)@params["show_errors"];
- if (@params["search_term"] != null) searchTerm = (string)@params["search_term"];
+ if (@params["show_logs"] != null)
+ showLogs = (bool)@params["show_logs"];
+ if (@params["show_warnings"] != null)
+ showWarnings = (bool)@params["show_warnings"];
+ if (@params["show_errors"] != null)
+ showErrors = (bool)@params["show_errors"];
+ if (@params["search_term"] != null)
+ searchTerm = (string)@params["search_term"];
}
try
@@ -160,20 +162,50 @@ public static class EditorControlHandler
Type logEntryType = Type.GetType("UnityEditor.LogEntry,UnityEditor");
if (logEntriesType == null || logEntryType == null)
- return new { error = "Could not find required Unity logging types", entries = new List
private static Dictionary GetObjectValues(object obj)
{
- if (obj == null) return new Dictionary();
+ if (obj == null)
+ return new Dictionary();
var result = new Dictionary();
var type = obj.GetType();
// Get all property values
- var properties = type.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
+ var properties = type.GetProperties(
+ BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance
+ );
foreach (var prop in properties)
{
try
@@ -528,7 +682,9 @@ public static class EditorControlHandler
}
// Get all field values
- var fields = type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
+ var fields = type.GetFields(
+ BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance
+ );
foreach (var field in fields)
{
try
@@ -552,7 +708,14 @@ public static class EditorControlHandler
{
var result = new List();
- using (var stream = new System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite))
+ using (
+ var stream = new System.IO.FileStream(
+ filePath,
+ System.IO.FileMode.Open,
+ System.IO.FileAccess.Read,
+ System.IO.FileShare.ReadWrite
+ )
+ )
using (var reader = new System.IO.StreamReader(stream))
{
string line;
@@ -589,4 +752,42 @@ public static class EditorControlHandler
return result;
}
-}
\ No newline at end of file
+
+ ///
+ /// Gets a list of available editor commands that can be executed
+ /// the method should have a MenuItem attribute
+ ///
+ /// Object containing list of available command paths
+ [MenuItem("Window/Get Available Commands")]
+ private static object GetAvailableCommands()
+ {
+ var commands = new List();
+ Assembly assembly = Assembly.GetExecutingAssembly();
+ foreach (Type type in assembly.GetTypes())
+ {
+ MethodInfo[] methods = type.GetMethods(
+ BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic
+ );
+
+ foreach (MethodInfo method in methods)
+ {
+ // Look for the MenuItem attribute
+ object[] attributes = method.GetCustomAttributes(
+ typeof(UnityEditor.MenuItem),
+ false
+ );
+ if (attributes.Length > 0)
+ {
+ UnityEditor.MenuItem menuItem = attributes[0] as UnityEditor.MenuItem;
+ commands.Add(menuItem.menuItem);
+ }
+ }
+ }
+ Debug.Log($"commands.Count: {commands.Count}");
+ foreach (var command in commands)
+ {
+ Debug.Log($"Command: {command}");
+ }
+ return new { commands = commands };
+ }
+}
diff --git a/Python/tools/editor_tools.py b/Python/tools/editor_tools.py
index 38ab274..d3a634a 100644
--- a/Python/tools/editor_tools.py
+++ b/Python/tools/editor_tools.py
@@ -266,4 +266,30 @@ def register_editor_tools(mcp: FastMCP):
"type": "Error",
"message": f"Error reading console: {str(e)}",
"stackTrace": ""
- }]
\ No newline at end of file
+ }]
+
+ @mcp.tool()
+ def get_available_commands(ctx: Context) -> List[str]:
+ """Get a list of all available editor commands that can be executed.
+
+ This tool provides direct access to the list of commands that can be executed
+ in the Unity Editor through the MCP system.
+
+ Returns:
+ List[str]: List of available command paths
+ """
+ try:
+ unity = get_unity_connection()
+
+ # Send request for available commands
+ response = unity.send_command("EDITOR_CONTROL", {
+ "command": "GET_AVAILABLE_COMMANDS"
+ })
+
+ # Extract commands list
+ commands = response.get("commands", [])
+
+ # Return the commands list
+ return commands
+ except Exception as e:
+ return [f"Error fetching commands: {str(e)}"]
\ No newline at end of file