2025-10-04 08:23:28 +08:00
|
|
|
using System;
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
using UnityEditor;
|
|
|
|
|
using UnityEditorInternal; // Required for tag management
|
|
|
|
|
using MCPForUnity.Editor.Helpers;
|
|
|
|
|
|
|
|
|
|
namespace MCPForUnity.Editor.Tools
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
Move Get commands to editor resources + Run Python tests every update (#368)
* Add a function to reload the domain
Closes #357
* feat: restructure server instructions into workflow-focused format
- Reorganized instructions from flat bullet list into categorized workflow sections
- Emphasized critical script management workflow with numbered steps
- Improved readability and scannability for AI agents using the MCP server
It doesn't make sense to repeat the fucnction tools, they're already parsed
* docs: reorder tool list alphabetically in README + add reload_domain tool
* feat: add Unity editor state and project info resources
- Implemented resources for querying active tool, editor state, prefab stage, selection, and open windows
- Added project configuration resources for layers and project metadata
- Organized new resources into Editor and Project namespaces for better structure
* feat: clarify script management workflow in system prompt
- Expanded guidance to include scripts created by any tool, not just manage_script
- Added "etc" to tools examples for better clarity
* refactor: remove reload_domain tool and update script management workflow
- Removed reload_domain tool as Unity automatically recompiles scripts when modified
- Updated script management instructions to rely on editor_state polling and console checking instead of manual domain reload
- Simplified workflow by removing unnecessary manual recompilation step
* Change name of menu items resource as the LLM seems it
* refactor: reorganize tests into src/tests/integration directory
- Moved all test files from root tests/ to MCPForUnity/UnityMcpServer~/src/tests/integration/ for better organization
- Added conftest.py with telemetry and dependency stubs to simplify test setup
- Removed redundant path manipulation and module loading code from individual test files
* feat: expand Unity test workflow triggers
- Run tests on all branches instead of only main
- Add pull request trigger to catch issues before merge
- Maintain path filtering to run only when relevant files change
* chore: add GitHub Actions workflow for Python tests
- Configured automated testing on push and pull requests using pytest
- Set up uv for dependency management and Python 3.10 environment
- Added test results artifact upload for debugging failed runs
* refactor: update import path for fastmcp Context
* docs: update development setup instructions to use uv
- Changed installation commands from pip to uv pip for better dependency management
- Updated test running instructions to use uv run pytest
- Added examples for running integration and unit tests separately
* Formatting [skip ci]
* refactor: optimize CI workflow with path filters and dependency installation
- Added path filters to only trigger tests when Python source or workflow files change
- Split dependency installation into sync and dev install steps for better clarity
- Fixed YAML indentation for improved readability
* Update .github/workflows/python-tests.yml
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
* fix: standardize test mode values to match Unity's naming convention
- Changed default mode from "edit" to "EditMode" in C# code
- Updated Python tool to use "EditMode" and "PlayMode" instead of lowercase variants
* refactor: convert test imports to relative imports
- Changed absolute imports to relative imports in integration tests for better package structure
- Removed test packages from pyproject.toml package list
* refactor: use Field with default_factory for mutable default in TagsResponse
* refactor: remove duplicate PrefabStageUtility call
* Update this as well [skip ci]
* Update MCPForUnity/UnityMcpServer~/src/tests/integration/test_script_tools.py
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
* chore: remove pull_request triggers from test workflows [skip ci]
It's already covered by pushes
* refactor: update resource function return types to include MCPResponse union
* refactor: remove manual domain reload tool
- Removed reload_domain tool as Unity handles script recompilation automatically
- Updated documentation to reflect automatic compilation workflow
- Simplified script management workflow instructions in server description
* refactor: add context support to resource handlers
- Updated all resource handlers to accept Context parameter for Unity instance routing
- Replaced direct async_send_command_with_retry calls with async_send_with_unity_instance wrapper
- Added imports for get_unity_instance_from_context and async_send_with_unity_instance helpers
* fix: correct grammar in menu items documentation
* docs: update README with expanded tools and resources documentation
- Added new tools: manage_prefabs, create_script, delete_script, get_sha
- Added new resources: editor state, windows, project info, layers, and tags
- Clarified manage_script as compatibility router with recommendation to use newer edit tools
- Fixed run_test to run_tests for consistency
* refactor: convert unity_instances function to async [skip ci]
- Changed function signature from synchronous to async
- Added await keywords to ctx.info() and ctx.error() calls to properly handle async context methods
---------
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2025-11-06 04:06:48 +08:00
|
|
|
/// Handles editor control actions including play mode control, tool selection,
|
|
|
|
|
/// and tag/layer management. For reading editor state, use MCP resources instead.
|
2025-10-04 08:23:28 +08:00
|
|
|
/// </summary>
|
|
|
|
|
[McpForUnityTool("manage_editor")]
|
|
|
|
|
public static class ManageEditor
|
|
|
|
|
{
|
|
|
|
|
// Constant for starting user layer index
|
|
|
|
|
private const int FirstUserLayerIndex = 8;
|
|
|
|
|
|
|
|
|
|
// Constant for total layer count
|
|
|
|
|
private const int TotalLayerCount = 32;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Main handler for editor management actions.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static object HandleCommand(JObject @params)
|
|
|
|
|
{
|
|
|
|
|
string action = @params["action"]?.ToString().ToLower();
|
|
|
|
|
// Parameters for specific actions
|
|
|
|
|
string tagName = @params["tagName"]?.ToString();
|
|
|
|
|
string layerName = @params["layerName"]?.ToString();
|
|
|
|
|
bool waitForCompletion = @params["waitForCompletion"]?.ToObject<bool>() ?? false; // Example - not used everywhere
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(action))
|
|
|
|
|
{
|
|
|
|
|
return Response.Error("Action parameter is required.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Route action
|
|
|
|
|
switch (action)
|
|
|
|
|
{
|
|
|
|
|
// Play Mode Control
|
|
|
|
|
case "play":
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (!EditorApplication.isPlaying)
|
|
|
|
|
{
|
|
|
|
|
EditorApplication.isPlaying = true;
|
|
|
|
|
return Response.Success("Entered play mode.");
|
|
|
|
|
}
|
|
|
|
|
return Response.Success("Already in play mode.");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
return Response.Error($"Error entering play mode: {e.Message}");
|
|
|
|
|
}
|
|
|
|
|
case "pause":
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (EditorApplication.isPlaying)
|
|
|
|
|
{
|
|
|
|
|
EditorApplication.isPaused = !EditorApplication.isPaused;
|
|
|
|
|
return Response.Success(
|
|
|
|
|
EditorApplication.isPaused ? "Game paused." : "Game resumed."
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return Response.Error("Cannot pause/resume: Not in play mode.");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
return Response.Error($"Error pausing/resuming game: {e.Message}");
|
|
|
|
|
}
|
|
|
|
|
case "stop":
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (EditorApplication.isPlaying)
|
|
|
|
|
{
|
|
|
|
|
EditorApplication.isPlaying = false;
|
|
|
|
|
return Response.Success("Exited play mode.");
|
|
|
|
|
}
|
|
|
|
|
return Response.Success("Already stopped (not in play mode).");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
return Response.Error($"Error stopping play mode: {e.Message}");
|
|
|
|
|
}
|
|
|
|
|
|
Move Get commands to editor resources + Run Python tests every update (#368)
* Add a function to reload the domain
Closes #357
* feat: restructure server instructions into workflow-focused format
- Reorganized instructions from flat bullet list into categorized workflow sections
- Emphasized critical script management workflow with numbered steps
- Improved readability and scannability for AI agents using the MCP server
It doesn't make sense to repeat the fucnction tools, they're already parsed
* docs: reorder tool list alphabetically in README + add reload_domain tool
* feat: add Unity editor state and project info resources
- Implemented resources for querying active tool, editor state, prefab stage, selection, and open windows
- Added project configuration resources for layers and project metadata
- Organized new resources into Editor and Project namespaces for better structure
* feat: clarify script management workflow in system prompt
- Expanded guidance to include scripts created by any tool, not just manage_script
- Added "etc" to tools examples for better clarity
* refactor: remove reload_domain tool and update script management workflow
- Removed reload_domain tool as Unity automatically recompiles scripts when modified
- Updated script management instructions to rely on editor_state polling and console checking instead of manual domain reload
- Simplified workflow by removing unnecessary manual recompilation step
* Change name of menu items resource as the LLM seems it
* refactor: reorganize tests into src/tests/integration directory
- Moved all test files from root tests/ to MCPForUnity/UnityMcpServer~/src/tests/integration/ for better organization
- Added conftest.py with telemetry and dependency stubs to simplify test setup
- Removed redundant path manipulation and module loading code from individual test files
* feat: expand Unity test workflow triggers
- Run tests on all branches instead of only main
- Add pull request trigger to catch issues before merge
- Maintain path filtering to run only when relevant files change
* chore: add GitHub Actions workflow for Python tests
- Configured automated testing on push and pull requests using pytest
- Set up uv for dependency management and Python 3.10 environment
- Added test results artifact upload for debugging failed runs
* refactor: update import path for fastmcp Context
* docs: update development setup instructions to use uv
- Changed installation commands from pip to uv pip for better dependency management
- Updated test running instructions to use uv run pytest
- Added examples for running integration and unit tests separately
* Formatting [skip ci]
* refactor: optimize CI workflow with path filters and dependency installation
- Added path filters to only trigger tests when Python source or workflow files change
- Split dependency installation into sync and dev install steps for better clarity
- Fixed YAML indentation for improved readability
* Update .github/workflows/python-tests.yml
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
* fix: standardize test mode values to match Unity's naming convention
- Changed default mode from "edit" to "EditMode" in C# code
- Updated Python tool to use "EditMode" and "PlayMode" instead of lowercase variants
* refactor: convert test imports to relative imports
- Changed absolute imports to relative imports in integration tests for better package structure
- Removed test packages from pyproject.toml package list
* refactor: use Field with default_factory for mutable default in TagsResponse
* refactor: remove duplicate PrefabStageUtility call
* Update this as well [skip ci]
* Update MCPForUnity/UnityMcpServer~/src/tests/integration/test_script_tools.py
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
* chore: remove pull_request triggers from test workflows [skip ci]
It's already covered by pushes
* refactor: update resource function return types to include MCPResponse union
* refactor: remove manual domain reload tool
- Removed reload_domain tool as Unity handles script recompilation automatically
- Updated documentation to reflect automatic compilation workflow
- Simplified script management workflow instructions in server description
* refactor: add context support to resource handlers
- Updated all resource handlers to accept Context parameter for Unity instance routing
- Replaced direct async_send_command_with_retry calls with async_send_with_unity_instance wrapper
- Added imports for get_unity_instance_from_context and async_send_with_unity_instance helpers
* fix: correct grammar in menu items documentation
* docs: update README with expanded tools and resources documentation
- Added new tools: manage_prefabs, create_script, delete_script, get_sha
- Added new resources: editor state, windows, project info, layers, and tags
- Clarified manage_script as compatibility router with recommendation to use newer edit tools
- Fixed run_test to run_tests for consistency
* refactor: convert unity_instances function to async [skip ci]
- Changed function signature from synchronous to async
- Added await keywords to ctx.info() and ctx.error() calls to properly handle async context methods
---------
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2025-11-06 04:06:48 +08:00
|
|
|
// Tool Control
|
2025-10-04 08:23:28 +08:00
|
|
|
case "set_active_tool":
|
|
|
|
|
string toolName = @params["toolName"]?.ToString();
|
|
|
|
|
if (string.IsNullOrEmpty(toolName))
|
|
|
|
|
return Response.Error("'toolName' parameter required for set_active_tool.");
|
|
|
|
|
return SetActiveTool(toolName);
|
|
|
|
|
|
|
|
|
|
// Tag Management
|
|
|
|
|
case "add_tag":
|
|
|
|
|
if (string.IsNullOrEmpty(tagName))
|
|
|
|
|
return Response.Error("'tagName' parameter required for add_tag.");
|
|
|
|
|
return AddTag(tagName);
|
|
|
|
|
case "remove_tag":
|
|
|
|
|
if (string.IsNullOrEmpty(tagName))
|
|
|
|
|
return Response.Error("'tagName' parameter required for remove_tag.");
|
|
|
|
|
return RemoveTag(tagName);
|
|
|
|
|
// Layer Management
|
|
|
|
|
case "add_layer":
|
|
|
|
|
if (string.IsNullOrEmpty(layerName))
|
|
|
|
|
return Response.Error("'layerName' parameter required for add_layer.");
|
|
|
|
|
return AddLayer(layerName);
|
|
|
|
|
case "remove_layer":
|
|
|
|
|
if (string.IsNullOrEmpty(layerName))
|
|
|
|
|
return Response.Error("'layerName' parameter required for remove_layer.");
|
|
|
|
|
return RemoveLayer(layerName);
|
|
|
|
|
// --- Settings (Example) ---
|
|
|
|
|
// case "set_resolution":
|
|
|
|
|
// int? width = @params["width"]?.ToObject<int?>();
|
|
|
|
|
// int? height = @params["height"]?.ToObject<int?>();
|
|
|
|
|
// if (!width.HasValue || !height.HasValue) return Response.Error("'width' and 'height' parameters required.");
|
|
|
|
|
// return SetGameViewResolution(width.Value, height.Value);
|
|
|
|
|
// case "set_quality":
|
|
|
|
|
// // Handle string name or int index
|
|
|
|
|
// return SetQualityLevel(@params["qualityLevel"]);
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return Response.Error(
|
Move Get commands to editor resources + Run Python tests every update (#368)
* Add a function to reload the domain
Closes #357
* feat: restructure server instructions into workflow-focused format
- Reorganized instructions from flat bullet list into categorized workflow sections
- Emphasized critical script management workflow with numbered steps
- Improved readability and scannability for AI agents using the MCP server
It doesn't make sense to repeat the fucnction tools, they're already parsed
* docs: reorder tool list alphabetically in README + add reload_domain tool
* feat: add Unity editor state and project info resources
- Implemented resources for querying active tool, editor state, prefab stage, selection, and open windows
- Added project configuration resources for layers and project metadata
- Organized new resources into Editor and Project namespaces for better structure
* feat: clarify script management workflow in system prompt
- Expanded guidance to include scripts created by any tool, not just manage_script
- Added "etc" to tools examples for better clarity
* refactor: remove reload_domain tool and update script management workflow
- Removed reload_domain tool as Unity automatically recompiles scripts when modified
- Updated script management instructions to rely on editor_state polling and console checking instead of manual domain reload
- Simplified workflow by removing unnecessary manual recompilation step
* Change name of menu items resource as the LLM seems it
* refactor: reorganize tests into src/tests/integration directory
- Moved all test files from root tests/ to MCPForUnity/UnityMcpServer~/src/tests/integration/ for better organization
- Added conftest.py with telemetry and dependency stubs to simplify test setup
- Removed redundant path manipulation and module loading code from individual test files
* feat: expand Unity test workflow triggers
- Run tests on all branches instead of only main
- Add pull request trigger to catch issues before merge
- Maintain path filtering to run only when relevant files change
* chore: add GitHub Actions workflow for Python tests
- Configured automated testing on push and pull requests using pytest
- Set up uv for dependency management and Python 3.10 environment
- Added test results artifact upload for debugging failed runs
* refactor: update import path for fastmcp Context
* docs: update development setup instructions to use uv
- Changed installation commands from pip to uv pip for better dependency management
- Updated test running instructions to use uv run pytest
- Added examples for running integration and unit tests separately
* Formatting [skip ci]
* refactor: optimize CI workflow with path filters and dependency installation
- Added path filters to only trigger tests when Python source or workflow files change
- Split dependency installation into sync and dev install steps for better clarity
- Fixed YAML indentation for improved readability
* Update .github/workflows/python-tests.yml
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
* fix: standardize test mode values to match Unity's naming convention
- Changed default mode from "edit" to "EditMode" in C# code
- Updated Python tool to use "EditMode" and "PlayMode" instead of lowercase variants
* refactor: convert test imports to relative imports
- Changed absolute imports to relative imports in integration tests for better package structure
- Removed test packages from pyproject.toml package list
* refactor: use Field with default_factory for mutable default in TagsResponse
* refactor: remove duplicate PrefabStageUtility call
* Update this as well [skip ci]
* Update MCPForUnity/UnityMcpServer~/src/tests/integration/test_script_tools.py
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
* chore: remove pull_request triggers from test workflows [skip ci]
It's already covered by pushes
* refactor: update resource function return types to include MCPResponse union
* refactor: remove manual domain reload tool
- Removed reload_domain tool as Unity handles script recompilation automatically
- Updated documentation to reflect automatic compilation workflow
- Simplified script management workflow instructions in server description
* refactor: add context support to resource handlers
- Updated all resource handlers to accept Context parameter for Unity instance routing
- Replaced direct async_send_command_with_retry calls with async_send_with_unity_instance wrapper
- Added imports for get_unity_instance_from_context and async_send_with_unity_instance helpers
* fix: correct grammar in menu items documentation
* docs: update README with expanded tools and resources documentation
- Added new tools: manage_prefabs, create_script, delete_script, get_sha
- Added new resources: editor state, windows, project info, layers, and tags
- Clarified manage_script as compatibility router with recommendation to use newer edit tools
- Fixed run_test to run_tests for consistency
* refactor: convert unity_instances function to async [skip ci]
- Changed function signature from synchronous to async
- Added await keywords to ctx.info() and ctx.error() calls to properly handle async context methods
---------
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2025-11-06 04:06:48 +08:00
|
|
|
$"Unknown action: '{action}'. Supported actions: play, pause, stop, set_active_tool, add_tag, remove_tag, add_layer, remove_layer. Use MCP resources for reading editor state, project info, tags, layers, selection, windows, prefab stage, and active tool."
|
2025-10-04 08:23:28 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Move Get commands to editor resources + Run Python tests every update (#368)
* Add a function to reload the domain
Closes #357
* feat: restructure server instructions into workflow-focused format
- Reorganized instructions from flat bullet list into categorized workflow sections
- Emphasized critical script management workflow with numbered steps
- Improved readability and scannability for AI agents using the MCP server
It doesn't make sense to repeat the fucnction tools, they're already parsed
* docs: reorder tool list alphabetically in README + add reload_domain tool
* feat: add Unity editor state and project info resources
- Implemented resources for querying active tool, editor state, prefab stage, selection, and open windows
- Added project configuration resources for layers and project metadata
- Organized new resources into Editor and Project namespaces for better structure
* feat: clarify script management workflow in system prompt
- Expanded guidance to include scripts created by any tool, not just manage_script
- Added "etc" to tools examples for better clarity
* refactor: remove reload_domain tool and update script management workflow
- Removed reload_domain tool as Unity automatically recompiles scripts when modified
- Updated script management instructions to rely on editor_state polling and console checking instead of manual domain reload
- Simplified workflow by removing unnecessary manual recompilation step
* Change name of menu items resource as the LLM seems it
* refactor: reorganize tests into src/tests/integration directory
- Moved all test files from root tests/ to MCPForUnity/UnityMcpServer~/src/tests/integration/ for better organization
- Added conftest.py with telemetry and dependency stubs to simplify test setup
- Removed redundant path manipulation and module loading code from individual test files
* feat: expand Unity test workflow triggers
- Run tests on all branches instead of only main
- Add pull request trigger to catch issues before merge
- Maintain path filtering to run only when relevant files change
* chore: add GitHub Actions workflow for Python tests
- Configured automated testing on push and pull requests using pytest
- Set up uv for dependency management and Python 3.10 environment
- Added test results artifact upload for debugging failed runs
* refactor: update import path for fastmcp Context
* docs: update development setup instructions to use uv
- Changed installation commands from pip to uv pip for better dependency management
- Updated test running instructions to use uv run pytest
- Added examples for running integration and unit tests separately
* Formatting [skip ci]
* refactor: optimize CI workflow with path filters and dependency installation
- Added path filters to only trigger tests when Python source or workflow files change
- Split dependency installation into sync and dev install steps for better clarity
- Fixed YAML indentation for improved readability
* Update .github/workflows/python-tests.yml
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
* fix: standardize test mode values to match Unity's naming convention
- Changed default mode from "edit" to "EditMode" in C# code
- Updated Python tool to use "EditMode" and "PlayMode" instead of lowercase variants
* refactor: convert test imports to relative imports
- Changed absolute imports to relative imports in integration tests for better package structure
- Removed test packages from pyproject.toml package list
* refactor: use Field with default_factory for mutable default in TagsResponse
* refactor: remove duplicate PrefabStageUtility call
* Update this as well [skip ci]
* Update MCPForUnity/UnityMcpServer~/src/tests/integration/test_script_tools.py
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
* chore: remove pull_request triggers from test workflows [skip ci]
It's already covered by pushes
* refactor: update resource function return types to include MCPResponse union
* refactor: remove manual domain reload tool
- Removed reload_domain tool as Unity handles script recompilation automatically
- Updated documentation to reflect automatic compilation workflow
- Simplified script management workflow instructions in server description
* refactor: add context support to resource handlers
- Updated all resource handlers to accept Context parameter for Unity instance routing
- Replaced direct async_send_command_with_retry calls with async_send_with_unity_instance wrapper
- Added imports for get_unity_instance_from_context and async_send_with_unity_instance helpers
* fix: correct grammar in menu items documentation
* docs: update README with expanded tools and resources documentation
- Added new tools: manage_prefabs, create_script, delete_script, get_sha
- Added new resources: editor state, windows, project info, layers, and tags
- Clarified manage_script as compatibility router with recommendation to use newer edit tools
- Fixed run_test to run_tests for consistency
* refactor: convert unity_instances function to async [skip ci]
- Changed function signature from synchronous to async
- Added await keywords to ctx.info() and ctx.error() calls to properly handle async context methods
---------
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2025-11-06 04:06:48 +08:00
|
|
|
// --- Tool Control Methods ---
|
2025-10-04 08:23:28 +08:00
|
|
|
|
|
|
|
|
private static object SetActiveTool(string toolName)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Tool targetTool;
|
|
|
|
|
if (Enum.TryParse<Tool>(toolName, true, out targetTool)) // Case-insensitive parse
|
|
|
|
|
{
|
|
|
|
|
// Check if it's a valid built-in tool
|
|
|
|
|
if (targetTool != Tool.None && targetTool <= Tool.Custom) // Tool.Custom is the last standard tool
|
|
|
|
|
{
|
|
|
|
|
UnityEditor.Tools.current = targetTool;
|
|
|
|
|
return Response.Success($"Set active tool to '{targetTool}'.");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return Response.Error(
|
|
|
|
|
$"Cannot directly set tool to '{toolName}'. It might be None, Custom, or invalid."
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Potentially try activating a custom tool by name here if needed
|
|
|
|
|
// This often requires specific editor scripting knowledge for that tool.
|
|
|
|
|
return Response.Error(
|
|
|
|
|
$"Could not parse '{toolName}' as a standard Unity Tool (View, Move, Rotate, Scale, Rect, Transform, Custom)."
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
return Response.Error($"Error setting active tool: {e.Message}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- Tag Management Methods ---
|
|
|
|
|
|
|
|
|
|
private static object AddTag(string tagName)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(tagName))
|
|
|
|
|
return Response.Error("Tag name cannot be empty or whitespace.");
|
|
|
|
|
|
|
|
|
|
// Check if tag already exists
|
Move Get commands to editor resources + Run Python tests every update (#368)
* Add a function to reload the domain
Closes #357
* feat: restructure server instructions into workflow-focused format
- Reorganized instructions from flat bullet list into categorized workflow sections
- Emphasized critical script management workflow with numbered steps
- Improved readability and scannability for AI agents using the MCP server
It doesn't make sense to repeat the fucnction tools, they're already parsed
* docs: reorder tool list alphabetically in README + add reload_domain tool
* feat: add Unity editor state and project info resources
- Implemented resources for querying active tool, editor state, prefab stage, selection, and open windows
- Added project configuration resources for layers and project metadata
- Organized new resources into Editor and Project namespaces for better structure
* feat: clarify script management workflow in system prompt
- Expanded guidance to include scripts created by any tool, not just manage_script
- Added "etc" to tools examples for better clarity
* refactor: remove reload_domain tool and update script management workflow
- Removed reload_domain tool as Unity automatically recompiles scripts when modified
- Updated script management instructions to rely on editor_state polling and console checking instead of manual domain reload
- Simplified workflow by removing unnecessary manual recompilation step
* Change name of menu items resource as the LLM seems it
* refactor: reorganize tests into src/tests/integration directory
- Moved all test files from root tests/ to MCPForUnity/UnityMcpServer~/src/tests/integration/ for better organization
- Added conftest.py with telemetry and dependency stubs to simplify test setup
- Removed redundant path manipulation and module loading code from individual test files
* feat: expand Unity test workflow triggers
- Run tests on all branches instead of only main
- Add pull request trigger to catch issues before merge
- Maintain path filtering to run only when relevant files change
* chore: add GitHub Actions workflow for Python tests
- Configured automated testing on push and pull requests using pytest
- Set up uv for dependency management and Python 3.10 environment
- Added test results artifact upload for debugging failed runs
* refactor: update import path for fastmcp Context
* docs: update development setup instructions to use uv
- Changed installation commands from pip to uv pip for better dependency management
- Updated test running instructions to use uv run pytest
- Added examples for running integration and unit tests separately
* Formatting [skip ci]
* refactor: optimize CI workflow with path filters and dependency installation
- Added path filters to only trigger tests when Python source or workflow files change
- Split dependency installation into sync and dev install steps for better clarity
- Fixed YAML indentation for improved readability
* Update .github/workflows/python-tests.yml
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
* fix: standardize test mode values to match Unity's naming convention
- Changed default mode from "edit" to "EditMode" in C# code
- Updated Python tool to use "EditMode" and "PlayMode" instead of lowercase variants
* refactor: convert test imports to relative imports
- Changed absolute imports to relative imports in integration tests for better package structure
- Removed test packages from pyproject.toml package list
* refactor: use Field with default_factory for mutable default in TagsResponse
* refactor: remove duplicate PrefabStageUtility call
* Update this as well [skip ci]
* Update MCPForUnity/UnityMcpServer~/src/tests/integration/test_script_tools.py
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
* chore: remove pull_request triggers from test workflows [skip ci]
It's already covered by pushes
* refactor: update resource function return types to include MCPResponse union
* refactor: remove manual domain reload tool
- Removed reload_domain tool as Unity handles script recompilation automatically
- Updated documentation to reflect automatic compilation workflow
- Simplified script management workflow instructions in server description
* refactor: add context support to resource handlers
- Updated all resource handlers to accept Context parameter for Unity instance routing
- Replaced direct async_send_command_with_retry calls with async_send_with_unity_instance wrapper
- Added imports for get_unity_instance_from_context and async_send_with_unity_instance helpers
* fix: correct grammar in menu items documentation
* docs: update README with expanded tools and resources documentation
- Added new tools: manage_prefabs, create_script, delete_script, get_sha
- Added new resources: editor state, windows, project info, layers, and tags
- Clarified manage_script as compatibility router with recommendation to use newer edit tools
- Fixed run_test to run_tests for consistency
* refactor: convert unity_instances function to async [skip ci]
- Changed function signature from synchronous to async
- Added await keywords to ctx.info() and ctx.error() calls to properly handle async context methods
---------
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2025-11-06 04:06:48 +08:00
|
|
|
if (System.Linq.Enumerable.Contains(InternalEditorUtility.tags, tagName))
|
2025-10-04 08:23:28 +08:00
|
|
|
{
|
|
|
|
|
return Response.Error($"Tag '{tagName}' already exists.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// Add the tag using the internal utility
|
|
|
|
|
InternalEditorUtility.AddTag(tagName);
|
|
|
|
|
// Force save assets to ensure the change persists in the TagManager asset
|
|
|
|
|
AssetDatabase.SaveAssets();
|
|
|
|
|
return Response.Success($"Tag '{tagName}' added successfully.");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
return Response.Error($"Failed to add tag '{tagName}': {e.Message}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static object RemoveTag(string tagName)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(tagName))
|
|
|
|
|
return Response.Error("Tag name cannot be empty or whitespace.");
|
|
|
|
|
if (tagName.Equals("Untagged", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
return Response.Error("Cannot remove the built-in 'Untagged' tag.");
|
|
|
|
|
|
|
|
|
|
// Check if tag exists before attempting removal
|
Move Get commands to editor resources + Run Python tests every update (#368)
* Add a function to reload the domain
Closes #357
* feat: restructure server instructions into workflow-focused format
- Reorganized instructions from flat bullet list into categorized workflow sections
- Emphasized critical script management workflow with numbered steps
- Improved readability and scannability for AI agents using the MCP server
It doesn't make sense to repeat the fucnction tools, they're already parsed
* docs: reorder tool list alphabetically in README + add reload_domain tool
* feat: add Unity editor state and project info resources
- Implemented resources for querying active tool, editor state, prefab stage, selection, and open windows
- Added project configuration resources for layers and project metadata
- Organized new resources into Editor and Project namespaces for better structure
* feat: clarify script management workflow in system prompt
- Expanded guidance to include scripts created by any tool, not just manage_script
- Added "etc" to tools examples for better clarity
* refactor: remove reload_domain tool and update script management workflow
- Removed reload_domain tool as Unity automatically recompiles scripts when modified
- Updated script management instructions to rely on editor_state polling and console checking instead of manual domain reload
- Simplified workflow by removing unnecessary manual recompilation step
* Change name of menu items resource as the LLM seems it
* refactor: reorganize tests into src/tests/integration directory
- Moved all test files from root tests/ to MCPForUnity/UnityMcpServer~/src/tests/integration/ for better organization
- Added conftest.py with telemetry and dependency stubs to simplify test setup
- Removed redundant path manipulation and module loading code from individual test files
* feat: expand Unity test workflow triggers
- Run tests on all branches instead of only main
- Add pull request trigger to catch issues before merge
- Maintain path filtering to run only when relevant files change
* chore: add GitHub Actions workflow for Python tests
- Configured automated testing on push and pull requests using pytest
- Set up uv for dependency management and Python 3.10 environment
- Added test results artifact upload for debugging failed runs
* refactor: update import path for fastmcp Context
* docs: update development setup instructions to use uv
- Changed installation commands from pip to uv pip for better dependency management
- Updated test running instructions to use uv run pytest
- Added examples for running integration and unit tests separately
* Formatting [skip ci]
* refactor: optimize CI workflow with path filters and dependency installation
- Added path filters to only trigger tests when Python source or workflow files change
- Split dependency installation into sync and dev install steps for better clarity
- Fixed YAML indentation for improved readability
* Update .github/workflows/python-tests.yml
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
* fix: standardize test mode values to match Unity's naming convention
- Changed default mode from "edit" to "EditMode" in C# code
- Updated Python tool to use "EditMode" and "PlayMode" instead of lowercase variants
* refactor: convert test imports to relative imports
- Changed absolute imports to relative imports in integration tests for better package structure
- Removed test packages from pyproject.toml package list
* refactor: use Field with default_factory for mutable default in TagsResponse
* refactor: remove duplicate PrefabStageUtility call
* Update this as well [skip ci]
* Update MCPForUnity/UnityMcpServer~/src/tests/integration/test_script_tools.py
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
* chore: remove pull_request triggers from test workflows [skip ci]
It's already covered by pushes
* refactor: update resource function return types to include MCPResponse union
* refactor: remove manual domain reload tool
- Removed reload_domain tool as Unity handles script recompilation automatically
- Updated documentation to reflect automatic compilation workflow
- Simplified script management workflow instructions in server description
* refactor: add context support to resource handlers
- Updated all resource handlers to accept Context parameter for Unity instance routing
- Replaced direct async_send_command_with_retry calls with async_send_with_unity_instance wrapper
- Added imports for get_unity_instance_from_context and async_send_with_unity_instance helpers
* fix: correct grammar in menu items documentation
* docs: update README with expanded tools and resources documentation
- Added new tools: manage_prefabs, create_script, delete_script, get_sha
- Added new resources: editor state, windows, project info, layers, and tags
- Clarified manage_script as compatibility router with recommendation to use newer edit tools
- Fixed run_test to run_tests for consistency
* refactor: convert unity_instances function to async [skip ci]
- Changed function signature from synchronous to async
- Added await keywords to ctx.info() and ctx.error() calls to properly handle async context methods
---------
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2025-11-06 04:06:48 +08:00
|
|
|
if (!System.Linq.Enumerable.Contains(InternalEditorUtility.tags, tagName))
|
2025-10-04 08:23:28 +08:00
|
|
|
{
|
|
|
|
|
return Response.Error($"Tag '{tagName}' does not exist.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// Remove the tag using the internal utility
|
|
|
|
|
InternalEditorUtility.RemoveTag(tagName);
|
|
|
|
|
// Force save assets
|
|
|
|
|
AssetDatabase.SaveAssets();
|
|
|
|
|
return Response.Success($"Tag '{tagName}' removed successfully.");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
// Catch potential issues if the tag is somehow in use or removal fails
|
|
|
|
|
return Response.Error($"Failed to remove tag '{tagName}': {e.Message}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- Layer Management Methods ---
|
|
|
|
|
|
|
|
|
|
private static object AddLayer(string layerName)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(layerName))
|
|
|
|
|
return Response.Error("Layer name cannot be empty or whitespace.");
|
|
|
|
|
|
|
|
|
|
// Access the TagManager asset
|
|
|
|
|
SerializedObject tagManager = GetTagManager();
|
|
|
|
|
if (tagManager == null)
|
|
|
|
|
return Response.Error("Could not access TagManager asset.");
|
|
|
|
|
|
|
|
|
|
SerializedProperty layersProp = tagManager.FindProperty("layers");
|
|
|
|
|
if (layersProp == null || !layersProp.isArray)
|
|
|
|
|
return Response.Error("Could not find 'layers' property in TagManager.");
|
|
|
|
|
|
|
|
|
|
// Check if layer name already exists (case-insensitive check recommended)
|
|
|
|
|
for (int i = 0; i < TotalLayerCount; i++)
|
|
|
|
|
{
|
|
|
|
|
SerializedProperty layerSP = layersProp.GetArrayElementAtIndex(i);
|
|
|
|
|
if (
|
|
|
|
|
layerSP != null
|
|
|
|
|
&& layerName.Equals(layerSP.stringValue, StringComparison.OrdinalIgnoreCase)
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
return Response.Error($"Layer '{layerName}' already exists at index {i}.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Find the first empty user layer slot (indices 8 to 31)
|
|
|
|
|
int firstEmptyUserLayer = -1;
|
|
|
|
|
for (int i = FirstUserLayerIndex; i < TotalLayerCount; i++)
|
|
|
|
|
{
|
|
|
|
|
SerializedProperty layerSP = layersProp.GetArrayElementAtIndex(i);
|
|
|
|
|
if (layerSP != null && string.IsNullOrEmpty(layerSP.stringValue))
|
|
|
|
|
{
|
|
|
|
|
firstEmptyUserLayer = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (firstEmptyUserLayer == -1)
|
|
|
|
|
{
|
|
|
|
|
return Response.Error("No empty User Layer slots available (8-31 are full).");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Assign the name to the found slot
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
SerializedProperty targetLayerSP = layersProp.GetArrayElementAtIndex(
|
|
|
|
|
firstEmptyUserLayer
|
|
|
|
|
);
|
|
|
|
|
targetLayerSP.stringValue = layerName;
|
|
|
|
|
// Apply the changes to the TagManager asset
|
|
|
|
|
tagManager.ApplyModifiedProperties();
|
|
|
|
|
// Save assets to make sure it's written to disk
|
|
|
|
|
AssetDatabase.SaveAssets();
|
|
|
|
|
return Response.Success(
|
|
|
|
|
$"Layer '{layerName}' added successfully to slot {firstEmptyUserLayer}."
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
return Response.Error($"Failed to add layer '{layerName}': {e.Message}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static object RemoveLayer(string layerName)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(layerName))
|
|
|
|
|
return Response.Error("Layer name cannot be empty or whitespace.");
|
|
|
|
|
|
|
|
|
|
// Access the TagManager asset
|
|
|
|
|
SerializedObject tagManager = GetTagManager();
|
|
|
|
|
if (tagManager == null)
|
|
|
|
|
return Response.Error("Could not access TagManager asset.");
|
|
|
|
|
|
|
|
|
|
SerializedProperty layersProp = tagManager.FindProperty("layers");
|
|
|
|
|
if (layersProp == null || !layersProp.isArray)
|
|
|
|
|
return Response.Error("Could not find 'layers' property in TagManager.");
|
|
|
|
|
|
|
|
|
|
// Find the layer by name (must be user layer)
|
|
|
|
|
int layerIndexToRemove = -1;
|
|
|
|
|
for (int i = FirstUserLayerIndex; i < TotalLayerCount; i++) // Start from user layers
|
|
|
|
|
{
|
|
|
|
|
SerializedProperty layerSP = layersProp.GetArrayElementAtIndex(i);
|
|
|
|
|
// Case-insensitive comparison is safer
|
|
|
|
|
if (
|
|
|
|
|
layerSP != null
|
|
|
|
|
&& layerName.Equals(layerSP.stringValue, StringComparison.OrdinalIgnoreCase)
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
layerIndexToRemove = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (layerIndexToRemove == -1)
|
|
|
|
|
{
|
|
|
|
|
return Response.Error($"User layer '{layerName}' not found.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Clear the name for that index
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
SerializedProperty targetLayerSP = layersProp.GetArrayElementAtIndex(
|
|
|
|
|
layerIndexToRemove
|
|
|
|
|
);
|
|
|
|
|
targetLayerSP.stringValue = string.Empty; // Set to empty string to remove
|
|
|
|
|
// Apply the changes
|
|
|
|
|
tagManager.ApplyModifiedProperties();
|
|
|
|
|
// Save assets
|
|
|
|
|
AssetDatabase.SaveAssets();
|
|
|
|
|
return Response.Success(
|
|
|
|
|
$"Layer '{layerName}' (slot {layerIndexToRemove}) removed successfully."
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
return Response.Error($"Failed to remove layer '{layerName}': {e.Message}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- Helper Methods ---
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the SerializedObject for the TagManager asset.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private static SerializedObject GetTagManager()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// Load the TagManager asset from the ProjectSettings folder
|
|
|
|
|
UnityEngine.Object[] tagManagerAssets = AssetDatabase.LoadAllAssetsAtPath(
|
|
|
|
|
"ProjectSettings/TagManager.asset"
|
|
|
|
|
);
|
|
|
|
|
if (tagManagerAssets == null || tagManagerAssets.Length == 0)
|
|
|
|
|
{
|
Move Get commands to editor resources + Run Python tests every update (#368)
* Add a function to reload the domain
Closes #357
* feat: restructure server instructions into workflow-focused format
- Reorganized instructions from flat bullet list into categorized workflow sections
- Emphasized critical script management workflow with numbered steps
- Improved readability and scannability for AI agents using the MCP server
It doesn't make sense to repeat the fucnction tools, they're already parsed
* docs: reorder tool list alphabetically in README + add reload_domain tool
* feat: add Unity editor state and project info resources
- Implemented resources for querying active tool, editor state, prefab stage, selection, and open windows
- Added project configuration resources for layers and project metadata
- Organized new resources into Editor and Project namespaces for better structure
* feat: clarify script management workflow in system prompt
- Expanded guidance to include scripts created by any tool, not just manage_script
- Added "etc" to tools examples for better clarity
* refactor: remove reload_domain tool and update script management workflow
- Removed reload_domain tool as Unity automatically recompiles scripts when modified
- Updated script management instructions to rely on editor_state polling and console checking instead of manual domain reload
- Simplified workflow by removing unnecessary manual recompilation step
* Change name of menu items resource as the LLM seems it
* refactor: reorganize tests into src/tests/integration directory
- Moved all test files from root tests/ to MCPForUnity/UnityMcpServer~/src/tests/integration/ for better organization
- Added conftest.py with telemetry and dependency stubs to simplify test setup
- Removed redundant path manipulation and module loading code from individual test files
* feat: expand Unity test workflow triggers
- Run tests on all branches instead of only main
- Add pull request trigger to catch issues before merge
- Maintain path filtering to run only when relevant files change
* chore: add GitHub Actions workflow for Python tests
- Configured automated testing on push and pull requests using pytest
- Set up uv for dependency management and Python 3.10 environment
- Added test results artifact upload for debugging failed runs
* refactor: update import path for fastmcp Context
* docs: update development setup instructions to use uv
- Changed installation commands from pip to uv pip for better dependency management
- Updated test running instructions to use uv run pytest
- Added examples for running integration and unit tests separately
* Formatting [skip ci]
* refactor: optimize CI workflow with path filters and dependency installation
- Added path filters to only trigger tests when Python source or workflow files change
- Split dependency installation into sync and dev install steps for better clarity
- Fixed YAML indentation for improved readability
* Update .github/workflows/python-tests.yml
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
* fix: standardize test mode values to match Unity's naming convention
- Changed default mode from "edit" to "EditMode" in C# code
- Updated Python tool to use "EditMode" and "PlayMode" instead of lowercase variants
* refactor: convert test imports to relative imports
- Changed absolute imports to relative imports in integration tests for better package structure
- Removed test packages from pyproject.toml package list
* refactor: use Field with default_factory for mutable default in TagsResponse
* refactor: remove duplicate PrefabStageUtility call
* Update this as well [skip ci]
* Update MCPForUnity/UnityMcpServer~/src/tests/integration/test_script_tools.py
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
* chore: remove pull_request triggers from test workflows [skip ci]
It's already covered by pushes
* refactor: update resource function return types to include MCPResponse union
* refactor: remove manual domain reload tool
- Removed reload_domain tool as Unity handles script recompilation automatically
- Updated documentation to reflect automatic compilation workflow
- Simplified script management workflow instructions in server description
* refactor: add context support to resource handlers
- Updated all resource handlers to accept Context parameter for Unity instance routing
- Replaced direct async_send_command_with_retry calls with async_send_with_unity_instance wrapper
- Added imports for get_unity_instance_from_context and async_send_with_unity_instance helpers
* fix: correct grammar in menu items documentation
* docs: update README with expanded tools and resources documentation
- Added new tools: manage_prefabs, create_script, delete_script, get_sha
- Added new resources: editor state, windows, project info, layers, and tags
- Clarified manage_script as compatibility router with recommendation to use newer edit tools
- Fixed run_test to run_tests for consistency
* refactor: convert unity_instances function to async [skip ci]
- Changed function signature from synchronous to async
- Added await keywords to ctx.info() and ctx.error() calls to properly handle async context methods
---------
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2025-11-06 04:06:48 +08:00
|
|
|
McpLog.Error("[ManageEditor] TagManager.asset not found in ProjectSettings.");
|
2025-10-04 08:23:28 +08:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
// The first object in the asset file should be the TagManager
|
|
|
|
|
return new SerializedObject(tagManagerAssets[0]);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
Move Get commands to editor resources + Run Python tests every update (#368)
* Add a function to reload the domain
Closes #357
* feat: restructure server instructions into workflow-focused format
- Reorganized instructions from flat bullet list into categorized workflow sections
- Emphasized critical script management workflow with numbered steps
- Improved readability and scannability for AI agents using the MCP server
It doesn't make sense to repeat the fucnction tools, they're already parsed
* docs: reorder tool list alphabetically in README + add reload_domain tool
* feat: add Unity editor state and project info resources
- Implemented resources for querying active tool, editor state, prefab stage, selection, and open windows
- Added project configuration resources for layers and project metadata
- Organized new resources into Editor and Project namespaces for better structure
* feat: clarify script management workflow in system prompt
- Expanded guidance to include scripts created by any tool, not just manage_script
- Added "etc" to tools examples for better clarity
* refactor: remove reload_domain tool and update script management workflow
- Removed reload_domain tool as Unity automatically recompiles scripts when modified
- Updated script management instructions to rely on editor_state polling and console checking instead of manual domain reload
- Simplified workflow by removing unnecessary manual recompilation step
* Change name of menu items resource as the LLM seems it
* refactor: reorganize tests into src/tests/integration directory
- Moved all test files from root tests/ to MCPForUnity/UnityMcpServer~/src/tests/integration/ for better organization
- Added conftest.py with telemetry and dependency stubs to simplify test setup
- Removed redundant path manipulation and module loading code from individual test files
* feat: expand Unity test workflow triggers
- Run tests on all branches instead of only main
- Add pull request trigger to catch issues before merge
- Maintain path filtering to run only when relevant files change
* chore: add GitHub Actions workflow for Python tests
- Configured automated testing on push and pull requests using pytest
- Set up uv for dependency management and Python 3.10 environment
- Added test results artifact upload for debugging failed runs
* refactor: update import path for fastmcp Context
* docs: update development setup instructions to use uv
- Changed installation commands from pip to uv pip for better dependency management
- Updated test running instructions to use uv run pytest
- Added examples for running integration and unit tests separately
* Formatting [skip ci]
* refactor: optimize CI workflow with path filters and dependency installation
- Added path filters to only trigger tests when Python source or workflow files change
- Split dependency installation into sync and dev install steps for better clarity
- Fixed YAML indentation for improved readability
* Update .github/workflows/python-tests.yml
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
* fix: standardize test mode values to match Unity's naming convention
- Changed default mode from "edit" to "EditMode" in C# code
- Updated Python tool to use "EditMode" and "PlayMode" instead of lowercase variants
* refactor: convert test imports to relative imports
- Changed absolute imports to relative imports in integration tests for better package structure
- Removed test packages from pyproject.toml package list
* refactor: use Field with default_factory for mutable default in TagsResponse
* refactor: remove duplicate PrefabStageUtility call
* Update this as well [skip ci]
* Update MCPForUnity/UnityMcpServer~/src/tests/integration/test_script_tools.py
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
* chore: remove pull_request triggers from test workflows [skip ci]
It's already covered by pushes
* refactor: update resource function return types to include MCPResponse union
* refactor: remove manual domain reload tool
- Removed reload_domain tool as Unity handles script recompilation automatically
- Updated documentation to reflect automatic compilation workflow
- Simplified script management workflow instructions in server description
* refactor: add context support to resource handlers
- Updated all resource handlers to accept Context parameter for Unity instance routing
- Replaced direct async_send_command_with_retry calls with async_send_with_unity_instance wrapper
- Added imports for get_unity_instance_from_context and async_send_with_unity_instance helpers
* fix: correct grammar in menu items documentation
* docs: update README with expanded tools and resources documentation
- Added new tools: manage_prefabs, create_script, delete_script, get_sha
- Added new resources: editor state, windows, project info, layers, and tags
- Clarified manage_script as compatibility router with recommendation to use newer edit tools
- Fixed run_test to run_tests for consistency
* refactor: convert unity_instances function to async [skip ci]
- Changed function signature from synchronous to async
- Added await keywords to ctx.info() and ctx.error() calls to properly handle async context methods
---------
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2025-11-06 04:06:48 +08:00
|
|
|
McpLog.Error($"[ManageEditor] Error accessing TagManager.asset: {e.Message}");
|
2025-10-04 08:23:28 +08:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- Example Implementations for Settings ---
|
|
|
|
|
/*
|
|
|
|
|
private static object SetGameViewResolution(int width, int height) { ... }
|
|
|
|
|
private static object SetQualityLevel(JToken qualityLevelToken) { ... }
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
}
|