Problem
add_component resolves the target GameObject but does not check whether it exists before passing it to Undo.AddComponent.
Evidence
Editor/MCPServerMethods.Component.cs:32-38 resolves go with IdToObject(...) as GameObject.
- The method validates the component type, but not
go.
- It then calls
Undo.AddComponent(go, type) directly.
Impact
If the object was destroyed or the instance ID became stale, the RPC fails with a raw Unity/null reference exception instead of a clear GameObject not found style validation error.
Suggested fix
Check go == null immediately after resolution and return the same clear error pattern used by get_game_object, destroy_game_object, and related methods.
Source report
Imported from audit report item: correctness (11) / Editor/MCPServerMethods.Component.cs:35.
Problem
add_componentresolves the target GameObject but does not check whether it exists before passing it toUndo.AddComponent.Evidence
Editor/MCPServerMethods.Component.cs:32-38resolvesgowithIdToObject(...) as GameObject.go.Undo.AddComponent(go, type)directly.Impact
If the object was destroyed or the instance ID became stale, the RPC fails with a raw Unity/null reference exception instead of a clear
GameObject not foundstyle validation error.Suggested fix
Check
go == nullimmediately after resolution and return the same clear error pattern used byget_game_object,destroy_game_object, and related methods.Source report
Imported from audit report item:
correctness (11)/Editor/MCPServerMethods.Component.cs:35.