Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 20, 2025

This PR implements the Package Remove tool for Unity MCP, allowing AI assistants to programmatically remove Unity packages from a project's manifest.json file.

Key Features

Core Functionality:

  • Removes multiple Unity packages in a single operation
  • Modifies /Packages/manifest.json using Unity-compatible System.Text.Json
  • Returns individual success/warning results for each package on separate lines
  • Automatically refreshes AssetDatabase after package removal

Async Operation Handling:

  • Uses ResponseCallTool.Processing() status during AssetDatabase refresh operations
  • Implements PackageRemovalTracker with [InitializeOnLoad] to survive domain reloads
  • Properly handles both immediate completion and domain reload scenarios
  • Notifies MCP server when operations complete using McpPluginUnity.NotifyToolRequestCompleted()

Robust Error Handling:

  • Validates RequestID and package array parameters
  • Detects missing or malformed manifest.json files
  • Monitors compilation status after domain reload
  • Provides detailed error messages for troubleshooting

Implementation Details

The tool follows the established patterns from TestRunner.Run.cs:

  • Uses MainThread.Instance.RunAsync() for thread safety
  • Implements proper [RequestID] parameter handling
  • Returns ResponseCallTool with appropriate status codes
  • Handles domain reload completion via AssemblyReloadEvents.afterAssemblyReload

Example Usage:

// Remove multiple packages
var result = await Tool_Package.Remove(
    new[] { "com.unity.postprocessing", "org.nuget.system.text.json" },
    "request-123"
);

// Returns results like:
// [Success] Package com.unity.postprocessing removed
// [Warning] Package org.nuget.system.text.json not found

Testing

Comprehensive unit tests cover:

  • RequestID validation and error scenarios
  • Package removal tracker functionality across domain reloads
  • JSON manipulation and file operations
  • Edge cases like empty package arrays and compilation errors

Files Added

  • Package.cs - Base class with error definitions
  • Package.Remove.cs - Main implementation (283 lines)
  • TestToolPackageRemove.cs - Unit tests (192 lines)
  • Package.Remove.md - Usage documentation
  • Unity .meta files for proper asset management

The implementation enables AI assistants to safely manage Unity project dependencies, clean up unused packages, and resolve package conflicts programmatically.

Fixes #228.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 4 commits September 20, 2025 10:30
Co-authored-by: IvanMurzak <9135028+IvanMurzak@users.noreply.github.com>
Co-authored-by: IvanMurzak <9135028+IvanMurzak@users.noreply.github.com>
Co-authored-by: IvanMurzak <9135028+IvanMurzak@users.noreply.github.com>
Co-authored-by: IvanMurzak <9135028+IvanMurzak@users.noreply.github.com>
Copilot AI changed the title [WIP] Tool: Remove Package Implement Package Remove tool for Unity MCP with domain reload handling Sep 20, 2025
Copilot AI requested a review from IvanMurzak September 20, 2025 10:36
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.

Tool: Remove Package

2 participants