[Add] Unity MCP

This commit is contained in:
2026-02-27 03:43:41 +07:00
parent 9557633ff3
commit 15608d4994
457 changed files with 50433 additions and 55 deletions
@@ -0,0 +1,64 @@
using System;
using MCPForUnity.Editor.Helpers;
using Newtonsoft.Json.Linq;
using UnityEditor;
namespace MCPForUnity.Editor.Resources.Editor
{
/// <summary>
/// Provides information about the currently active editor tool.
/// </summary>
[McpForUnityResource("get_active_tool")]
public static class ActiveTool
{
public static object HandleCommand(JObject @params)
{
try
{
Tool currentTool = UnityEditor.Tools.current;
string toolName = currentTool.ToString();
bool customToolActive = UnityEditor.Tools.current == Tool.Custom;
string activeToolName = customToolActive ? EditorTools.GetActiveToolName() : toolName;
var toolInfo = new
{
activeTool = activeToolName,
isCustom = customToolActive,
pivotMode = UnityEditor.Tools.pivotMode.ToString(),
pivotRotation = UnityEditor.Tools.pivotRotation.ToString(),
handleRotation = new
{
x = UnityEditor.Tools.handleRotation.eulerAngles.x,
y = UnityEditor.Tools.handleRotation.eulerAngles.y,
z = UnityEditor.Tools.handleRotation.eulerAngles.z
},
handlePosition = new
{
x = UnityEditor.Tools.handlePosition.x,
y = UnityEditor.Tools.handlePosition.y,
z = UnityEditor.Tools.handlePosition.z
}
};
return new SuccessResponse("Retrieved active tool information.", toolInfo);
}
catch (Exception e)
{
return new ErrorResponse($"Error getting active tool: {e.Message}");
}
}
}
// Helper class for custom tool names
internal static class EditorTools
{
public static string GetActiveToolName()
{
if (UnityEditor.Tools.current == Tool.Custom)
{
return "Unknown Custom Tool";
}
return UnityEditor.Tools.current.ToString();
}
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 6e78b6227ab7742a8a4f679ee6a8a212
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 329908
packageName: MCP for Unity | AI Driven Development
packageVersion: 9.0.3
assetPath: Assets/MCPForUnity/Editor/Resources/Editor/ActiveTool.cs
uploadId: 855486
@@ -0,0 +1,27 @@
using System;
using MCPForUnity.Editor.Helpers;
using MCPForUnity.Editor.Services;
using Newtonsoft.Json.Linq;
namespace MCPForUnity.Editor.Resources.Editor
{
/// <summary>
/// Provides dynamic editor state information that changes frequently.
/// </summary>
[McpForUnityResource("get_editor_state")]
public static class EditorState
{
public static object HandleCommand(JObject @params)
{
try
{
var snapshot = EditorStateCache.GetSnapshot();
return new SuccessResponse("Retrieved editor state.", snapshot);
}
catch (Exception e)
{
return new ErrorResponse($"Error getting editor state: {e.Message}");
}
}
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: f7c6df54e014c44fdb0cd3f65a479e37
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 329908
packageName: MCP for Unity | AI Driven Development
packageVersion: 9.0.3
assetPath: Assets/MCPForUnity/Editor/Resources/Editor/EditorState.cs
uploadId: 855486
@@ -0,0 +1,52 @@
using System;
using System.Linq;
using MCPForUnity.Editor.Helpers;
using Newtonsoft.Json.Linq;
using UnityEditor;
namespace MCPForUnity.Editor.Resources.Editor
{
/// <summary>
/// Provides detailed information about the current editor selection.
/// </summary>
[McpForUnityResource("get_selection")]
public static class Selection
{
public static object HandleCommand(JObject @params)
{
try
{
var selectionInfo = new
{
activeObject = UnityEditor.Selection.activeObject?.name,
activeGameObject = UnityEditor.Selection.activeGameObject?.name,
activeTransform = UnityEditor.Selection.activeTransform?.name,
activeInstanceID = UnityEditor.Selection.activeInstanceID,
count = UnityEditor.Selection.count,
objects = UnityEditor.Selection.objects
.Select(obj => new
{
name = obj?.name,
type = obj?.GetType().FullName,
instanceID = obj?.GetInstanceID()
})
.ToList(),
gameObjects = UnityEditor.Selection.gameObjects
.Select(go => new
{
name = go?.name,
instanceID = go?.GetInstanceID()
})
.ToList(),
assetGUIDs = UnityEditor.Selection.assetGUIDs
};
return new SuccessResponse("Retrieved current selection details.", selectionInfo);
}
catch (Exception e)
{
return new ErrorResponse($"Error getting selection: {e.Message}");
}
}
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: c7ea869623e094599a70be086ab4fc0e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 329908
packageName: MCP for Unity | AI Driven Development
packageVersion: 9.0.3
assetPath: Assets/MCPForUnity/Editor/Resources/Editor/Selection.cs
uploadId: 855486
@@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using MCPForUnity.Editor.Helpers;
using Newtonsoft.Json.Linq;
using UnityEditor;
using UnityEngine;
namespace MCPForUnity.Editor.Resources.Editor
{
/// <summary>
/// Provides list of all open editor windows.
/// </summary>
[McpForUnityResource("get_windows")]
public static class Windows
{
public static object HandleCommand(JObject @params)
{
try
{
EditorWindow[] allWindows = UnityEngine.Resources.FindObjectsOfTypeAll<EditorWindow>();
var openWindows = new List<object>();
foreach (EditorWindow window in allWindows)
{
if (window == null)
continue;
try
{
openWindows.Add(new
{
title = window.titleContent.text,
typeName = window.GetType().FullName,
isFocused = EditorWindow.focusedWindow == window,
position = new
{
x = window.position.x,
y = window.position.y,
width = window.position.width,
height = window.position.height
},
instanceID = window.GetInstanceID()
});
}
catch (Exception ex)
{
McpLog.Warn($"Could not get info for window {window.GetType().Name}: {ex.Message}");
}
}
return new SuccessResponse("Retrieved list of open editor windows.", openWindows);
}
catch (Exception e)
{
return new ErrorResponse($"Error getting editor windows: {e.Message}");
}
}
}
}
@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 58a341e64bea440b29deaf859aaea552
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 329908
packageName: MCP for Unity | AI Driven Development
packageVersion: 9.0.3
assetPath: Assets/MCPForUnity/Editor/Resources/Editor/Windows.cs
uploadId: 855486