Commit Graph

14 Commits (b52d1563b0b1147a06ad00caf7cf9d829b1cd4c0)

Author SHA1 Message Date
Shutong Wu 424df879d4
Update warning message for Camera Capture (#661) 2026-01-30 21:09:06 -05:00
adrd 67dda7f9cc
fix: improve manage_scene screenshot capture (#600)
* fix: improve manage_scene screenshot capture

* fix: address PR review feedback for screenshot capture

- Gate pre-2022 ScreenCapture fallback warning to log only once
- Downgrade warning to Debug.Log to reduce log noise
- Refactor path-building into shared PrepareCaptureResult() helper
- Add conditional logging to catch blocks in BestEffortPrepareGameViewForScreenshot
- Add timeout/failure logging to ScheduleAssetImportWhenFileExists
- Fix grammar in README-DEV.md

* fix(unity): resolve screenshot import callback type + FindObjectsOfType deprecation

* chore: bump version to 9.2.0

* Update ManageScene.cs

* Update ScreenshotUtility.cs

* Update error logging in ManageScene.cs

---------

Co-authored-by: Marcus Sanatan <msanatan@gmail.com>
Co-authored-by: GitHub Actions <actions@github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Shutong Wu <51266340+Scriptwonder@users.noreply.github.com>
2026-01-24 17:07:08 -05:00
dsarno cf177b50af
Replace asmdef GUID references (#564) 2026-01-15 07:52:53 -08:00
dsarno b874922cb0
Fix manage_components set_property for object references (#551) 2026-01-13 22:23:18 -08:00
dsarno 7d58053f87
fix: replace Editor-only McpLog with Debug.LogWarning in Runtime assembly (#535)
- UnityTypeConverters.cs referenced McpLog (Editor-only) from Runtime asmdef
- This caused CS0103 build errors in player builds
- Replaced with UnityEngine.Debug.LogWarning for runtime compatibility

Also cleaned up test file:
- Removed stale NL test artifacts (Build marker, Tail test comments)
- Removed unused local functions causing CS8321 warnings
2026-01-08 07:59:05 -08:00
Marcus Sanatan 22e52664cd
Asset store helper script + updated README (#521)
* Remove stray .meta file

* Add a new project that will do asset uploads

* Add asset store uploader

* refactor: Replace Debug.Log calls with McpLog helper across codebase

Standardize logging by replacing direct Debug.Log/LogWarning/LogError calls
with McpLog.Info/Warn/Error throughout helper classes and client registry.
Affected files:
- McpClientRegistry.cs
- GameObjectLookup.cs
- GameObjectSerializer.cs
- MaterialOps.cs
- McpConfigurationHelper.cs
- ObjectResolver.cs
- PropertyConversion.cs
- UnityJsonSerializer.cs
- UnityTypeResolver.cs

* feat: Add Asset Store release preparation script

Add prepare_unity_asset_store_release.py tool to automate Asset Store packaging:
- Stages temporary copy of MCPForUnity with Asset Store-specific edits
- Removes auto-popup setup window ([InitializeOnLoad] attribute)
- Renames menu entry to "Local Setup Window" for clarity
- Sets default HTTP base URL to hosted endpoint
- Defaults transport to HTTPRemote instead of HTTPLocal
- Supports dry-run mode and optional backup of existing Assets/MCPForUnity

* Show gif of MCP for Unity in Action

* Add shield with asset store link

* Update README to have asset store page unders installation section
2026-01-07 01:33:20 -04:00
dsarno 5511a2b8ad
🔧 Clean up & Consolidate Shared Services Across MCP Tools (#519)
* feat: Redesign GameObject API for better LLM ergonomics

- find_gameobjects: Search GameObjects, returns paginated instance IDs only
- manage_components: Component lifecycle (add, remove, set_property)

- unity://scene/gameobject/{id}: Single GameObject data (no component serialization)
- unity://scene/gameobject/{id}/components: All components (paginated)
- unity://scene/gameobject/{id}/component/{name}: Single component by type

- manage_scene get_hierarchy: Now includes componentTypes array
- manage_gameobject: Slimmed to lifecycle only (create, modify, delete)
  - Legacy actions (find, get_components, etc.) log deprecation warnings

- ParamCoercion: Centralized int/bool/float/string coercion
- VectorParsing: Vector3/Vector2/Quaternion/Color parsing
- GameObjectLookup: Centralized GameObject search logic

- 76 new Unity EditMode tests for ManageGameObject actions
- 21 new pytest tests for Python tools/resources
- New NL/T CI suite for GameObject API (GO-0 to GO-5)

Addresses LLM confusion with parameter overload by splitting into
focused tools and read-only resources.

* feat: Add GameObject API stress tests and NL/T suite updates

Stress Tests (12 new tests):
- BulkCreate small/medium batches
- FindGameObjects pagination with by_component search
- AddComponents to single object
- GetComponents with full serialization
- SetComponentProperties (complex Rigidbody)
- Deep hierarchy creation and path lookup
- GetHierarchy with large scenes
- Resource read performance tests
- RapidFire create-modify-delete cycles

NL/T Suite Updates:
- Added GO-0..GO-10 tests in nl-gameobject-suite.md
- Fixed tool naming: mcp__unity__ → mcp__UnityMCP__

Other:
- Fixed LongUnityScriptClaudeTest.cs compilation errors
- Added reports/, .claude/local/, scripts/local-test/ to .gitignore

All 254 EditMode tests pass (250 run, 4 explicit skips)

* fix: Address code review feedback

- ParamCoercion: Use CultureInfo.InvariantCulture for float parsing
- ManageComponents: Move Transform removal check before GetComponent
- ManageGameObjectFindTests: Use try-finally for LogAssert.ignoreFailingMessages
- VectorParsing: Document that quaternions are not auto-normalized
- gameobject.py: Prefix unused ctx parameter with underscore

* fix: Address more code review feedback

NL/T Prompt Fixes:
- nl-gameobject-suite.md: Remove non-existent list_resources/read_resource from AllowedTools
- nl-gameobject-suite.md: Fix parameter names (component_type, properties)
- nl-unity-suite-nl.md: Remove unused manage_editor from AllowedTools

Test Fixes:
- GameObjectAPIStressTests: Add null check to ToJObject helper
- GameObjectAPIStressTests: Clarify AudioSource usage comment
- ManageGameObjectFindTests: Use built-in 'UI' layer instead of 'Water'
- LongUnityScriptClaudeTest: Clean up NL/T test artifacts (Counte42 typo, HasTarget)

* docs: update README tools and resources lists

- Add missing tools: manage_components, batch_execute, find_gameobjects, refresh_unity
- Add missing resources: gameobject_api, editor_state_v2
- Make descriptions more concise across all tools and resources
- Ensure documentation matches current MCP server functionality

* chore: Remove accidentally committed test artifacts

- Remove Materials folder (40 .mat files from interactive testing)
- Remove Shaders folder (5 noise shaders from testing)
- Remove test scripts (Bounce*, CylinderBounce* from testing)
- Remove Temp.meta and commit.sh

* refactor: remove deprecated manage_gameobject actions

- Remove deprecated switch cases: find, get_components, get_component, add_component, remove_component, set_component_property
- Remove deprecated wrapper methods (423 lines deleted from ManageGameObject.cs)
- Delete ManageGameObjectFindTests.cs (tests deprecated 'find' action)
- Remove deprecated test methods from ManageGameObjectTests.cs
- Add GameObject resource URIs to README documentation
- Add batch_execute performance tips to README, tool description, and gameobject_api resource
- Enhance batch_execute description to emphasize 10-100x performance gains

Total: ~1200 lines removed. New API (find_gameobjects, manage_components, resources) is the recommended path forward.

* refactor: consolidate shared services across MCP tools

Major architectural improvements:
- Create UnityJsonSerializer for shared JSON/Unity type conversion
- Create ObjectResolver for unified object resolution (GameObjects, Components, Assets)
- Create UnityTypeResolver for consolidated type resolution with caching
- Create PropertyConversion for unified JSON→Unity property conversion
- Create ComponentOps for low-level component operations
- Create Pagination helpers for standardized pagination across tools

Tool simplifications:
- ManageGameObject: Remove 68-line prefab redirect anti-pattern, delegate to helpers
- ManageAsset: Remove ~80 lines duplicate ConvertJTokenToType
- ManageScriptableObject: Remove ~40 lines duplicate ResolveType
- ManageComponents: Use ComponentOps, UnityTypeResolver (~90 lines saved)
- ManageMaterial: Standardize to SuccessResponse/ErrorResponse patterns
- FindGameObjects: Use PaginationRequest/PaginationResponse
- GameObjectLookup: FindComponentType delegates to UnityTypeResolver

Tests: 242/246 passed, 4 skipped (expected)

* Apply code review feedback: consolidate utilities and improve compatibility

Python Server:
- Extract normalize_properties() to shared utils.py (removes duplication)
- Move search_term validation before preflight() for fail-fast
- Fix manage_script.py documentation (remove incorrect 'update' reference)
- Remove stale comments in execute_menu_item.py, manage_editor.py
- Remove misleading destructiveHint from manage_shader.py

C# Unity:
- Add Vector4Converter (commonly used, was missing)
- Fix Unity 2021 compatibility: replace FindObjectsByType with FindObjectsOfType
- Add path normalization in ObjectResolver before StartsWith check
- Improve ComponentOps.SetProperty conversion error detection
- Add Undo.RecordObject in ManageComponents before property modifications
- Improve error message clarity in ManageMaterial.cs
- Add defensive error handling to stress test ToJObject helper
- Increase CI timeout thresholds for test stability

GitHub Workflows:
- Fix GO test sorting in markdown output (GO-10 now sorts after GO-9)
- Add warning logging for fragment parsing errors

* Fix animator hash names in test fixture to match parameter names

BlendXHash/BlendYHash now use 'reachX'/'reachY' to match the
actual animator parameter names.

* fix(windows): improve HTTP server detection and auto-start reliability

- Fix netstat detection on Windows by running netstat.exe directly instead
  of piping through findstr (findstr returns exit code 1 when no matches,
  causing false detection failures)
- Increase auto-start retry attempts (20→30) and delays (2s→3s) to handle
  slow server starts during first install, version upgrades, and dev mode
- Only attempt blind connection after 20 failed detection attempts to reduce
  connection error spam during server startup
- Remove verbose debug logs that were spamming the console every frame

* fix: auto-create tags and remove deprecated manage_gameobject actions

- ManageGameObject.cs: Check tag existence before setting; auto-create
  undefined tags using InternalEditorUtility.AddTag() instead of relying
  on exception handling (Unity logs warning, doesn't throw)
- manage_gameobject.py: Remove deprecated actions (find, get_components,
  add_component, remove_component, set_component_property, get_component)
  from Literal type - these are now handled by find_gameobjects and
  manage_components tools
- Update test suite and unit tests to reflect new auto-create behavior

* fix: address code review feedback

Bug fixes:
- Fix searchInactive flag ignored in FindObjectsOfType (use includeInactive overload)
- Fix property lookup to try both original and normalized names for backwards compat
- Remove dead code for deprecated 'find' action validation
- Update error message to list only valid actions

Improvements:
- Add destructiveHint=True to manage_shader tool
- Limit fallback connection attempts (every 3rd attempt) to avoid spamming errors
- Consolidate PropertyConversion exception handlers to single catch block
- Add tag existence assertion and cleanup in tag auto-creation tests

Test fixes:
- Update SetComponentProperties_ContinuesAfterException log regex for new error format
- Update test_manage_gameobject_param_coercion to test valid actions only
2026-01-06 12:58:17 -08:00
dsarno 91b6f4d8d6
Test/478 matrix4x4 serialization crash (#481)
* Fix #478: Add Matrix4x4Converter to prevent Cinemachine serialization crash

The `get_components` action crashes Unity when serializing Cinemachine
camera components because Newtonsoft.Json accesses computed Matrix4x4
properties (lossyScale, rotation) that call ValidTRS() on non-TRS matrices.

This fix adds a safe Matrix4x4Converter that only accesses raw matrix
elements (m00-m33), avoiding the dangerous computed properties entirely.

Changes:
- Add Matrix4x4Converter to UnityTypeConverters.cs
- Register converter in GameObjectSerializer serializer settings

Tested with Cinemachine 3.1.5 on Unity 6 - get_components now returns
full component data without crashing.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Add unit tests for Matrix4x4Converter

Tests cover:
- Identity matrix serialization/deserialization
- Translation matrix round-trip
- Degenerate matrix (determinant=0) - key regression test
- Non-TRS matrix (projection) - validates ValidTRS() is never called
- Null handling
- Ensures dangerous properties are not in output

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Address code review feedback

- Fix null handling consistency: return zero matrix instead of identity
  (consistent with missing field defaults of 0f)
- Improve degenerate matrix test to verify:
  - JSON only contains raw mXY properties
  - Values roundtrip correctly
- Rename test to reflect expanded coverage

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Move tests to TestProject per review feedback

Moved Matrix4x4ConverterTests from MCPForUnity/Editor/Tests/ to
TestProjects/UnityMCPTests/Assets/Tests/EditMode/Helpers/ as requested.

Also added MCPForUnity.Runtime reference to the test asmdef since
the converter lives in the Runtime assembly.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Fix Matrix4x4 deserialization guard + UI Toolkit USS warning

---------

Co-authored-by: Alexander Mangel <cygnusfear@gmail.com>
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-23 15:53:14 -08:00
Shutong Wu 90758f19f4
Fix on Issue #465 (#477)
* Update ScreenshotUtility.cs

Fix issue in issue#465

* Update ScreenshotUtility.cs
2025-12-22 13:36:55 -05:00
Shutong Wu a9878622ea
Implement screenshot capture for Unity 2022.1+
Add conditional screenshot capture for Unity 2022.1 and newer.
2025-12-10 12:15:29 -05:00
Evan 2f2b56a20d
修复ArrayPool可能会产生报错的问题 (#451)
* Fixed ArrayPool conflict with CString.dll ArrayPool in Tolua

Fixed ArrayPool conflict with CString.dll ArrayPool in Tolua

* ScreenCapture在Unity2022中才支持

ScreenCapture在Unity2022中才支持,增加Unity版本判断
2025-12-10 12:14:30 -05:00
Shutong Wu 79b3255d0a
[FEATURE] Deployment of local source code to Unity (#450)
* [FEATURE] Local MCPForUnity Deployment

Similar to deploy.bat, but sideload it to MCP For Unity for easier deployment inside Unity menu.

* Update PackageDeploymentService.cs

* Update with meta file

* Updated Readme
2025-12-09 20:17:18 -05:00
Shutong Wu 97b85749b5
[FEATURE] Camera Capture (#449)
* Updates on Camera Capture Feature

* Enable Camera Capture through both play and editor mode
Notes: Because the standard ScreenCapture.CaptureScreenshot does not work in editor mode, so we use ScreenCapture.CaptureScreenshotIntoRenderTexture to enable it during play mode.

* The user can access the camera access through the tool menu or through direct LLM calling. Both tested on Windows with Claude Desktop.

* Minor changes

nitpicking changes
2025-12-09 19:00:30 -05:00
Marcus Sanatan e9b1ae44c5
Rename plugin folder to MCPForUnity (#303)
* Copy UnityMcpBridge into a new MCPForUnity folder

This is to close #284

* refactor: rename UnityMcpBridge directory to MCPForUnity in docs

* chore: rename UnityMcpBridge directory to MCPForUnity across workflow files

* chore: rename UnityMcpBridge directory to MCPForUnity across all files

* refactor: update import paths from UnityMcpBridge to MCPForUnity across test files

* fix: update module import paths to use MCPForUnity instead of UnityMcpBridge

* chore: update unity-mcp package path to MCPForUnity directory

* feat: add OneTimeSetUp to initialize CommandRegistry before tests run

Hopefully fix the CI failures

* Apply recent fix to new folder

* Temporarily trigger tests to see if CI works

* Revert "Temporarily trigger tests to see if CI works"

It works!

This reverts commit 8c6eaaad07545cef047769f2c52fe506545a8161.
2025-10-03 20:23:28 -04:00