Skip to main content

manage_physics — Complete Feature Patch

A new manage_physics MCP tool that gives AI assistants full control over Unity's 3D and 2D physics systems. 21 actions across 9 categories, with C# Editor implementation, Python MCP service, CLI commands, and tests.

Actions by Category​

Settings​

ActionDescription
pingHealth check — returns gravity, solver settings, simulation mode
get_settingsRead physics project settings (3D or 2D)
set_settingsWrite physics project settings (gravity, solver iterations, thresholds, etc.)

Collision Matrix​

ActionDescription
get_collision_matrixRead per-layer collision matrix
set_collision_matrixEnable/disable collision between layer pairs

Materials​

ActionDescription
create_physics_materialCreate PhysicMaterial (3D) or PhysicsMaterial2D assets with friction/bounciness/combine modes
configure_physics_materialUpdate properties on an existing physics material asset
assign_physics_materialAssign a physics material to a GameObject's collider

Joints​

ActionDescription
add_jointAdd a joint (hinge, spring, fixed, configurable, etc.) with optional connected body
configure_jointConfigure motor, limits, spring, drive, and direct properties on an existing joint
remove_jointRemove joint(s) from a GameObject by type or all

Queries​

ActionDescription
raycastSingle-hit raycast from origin along direction
raycast_allBounded multi-hit raycast; returned hits are sorted by distance
linecastCheck if anything intersects the line between two points
shapecastCast a shape (sphere, box, capsule) along a direction
overlapBounded collider query within a shape (sphere, box, capsule) at a position

Both dimensions support query_trigger_interaction on overlap queries: Ignore, Collide, or UseGlobal (default). 3D explicit modes override the corresponding global trigger setting for that query without changing project settings. The 2D implementation uses a local ContactFilter2D, including when the layer mask is zero. Ignore excludes triggers and UseGlobal follows the current global setting.

For every 2D query action, explicit Collide requires Physics2D.queriesHitTriggers=true: Unity's local filter cannot include triggers when the global setting is disabled. If it is disabled, the tool returns success=false, code=unsupported_2d_trigger_override and an explanatory error before executing the query. This also applies to a zero layer mask. The tool never changes the global setting. With the global setting enabled, Collide includes triggers and Ignore can exclude them per query.

raycast_all and overlap accept max_results, a strict integer from 1 through 1000 (default 200). CLI commands expose the same limit as --max-results. The receiver validates the limit before issuing the native query and supplies an array of exactly that capacity to Unity. It does not collect an unbounded result set and then slice it. Single-hit raycast, linecast, and shapecast retain their existing behavior.

Multi-hit responses retain hits/hit_count or colliders and add:

FieldMeaning
max_resultsEffective native buffer capacity
returned_countNumber of entries returned, at most the capacity
buffer_saturatedThe native query filled its buffer; completeness is unknown
orderingdistance_ascending for returned ray hits; unspecified for overlaps
nearest_hits_guaranteedRay queries only: false when the buffer is saturated

An exact-capacity result is also saturated: it cannot establish whether more results exist. No total-hit count or definite truncation count is claimed. Sorting a saturated ray buffer orders its returned subset; it does not establish that these are the globally nearest hits. Unsaturated results are complete for the submitted query. Equal-distance ray ties and overlap identities have no stable ordering guarantee across calls.

The limit bounds result storage, sorting, and serialization. It does not guarantee a bound on native physics traversal time or provide cancellation inside synchronous Unity queries. Use an appropriate layer mask, distance, and query volume to narrow native work.

Forces​

ActionDescription
apply_forceApply force, torque (or both), force-at-position, or explosion force to Rigidbodies. Supports all ForceModes for 3D and 2D

Rigidbody​

ActionDescription
get_rigidbodyRead full Rigidbody state: mass, velocity, position, rotation, damping, constraints, sleep state, centerOfMass
configure_rigidbodySet Rigidbody properties (mass, damping, gravity, kinematic, interpolation, collision detection, constraints)

Validation​

ActionDescription
validateScan scene (or a single target) for physics issues. Paginated results (page_size/cursor/next_cursor) with per-category summary. 7 check categories: non-convex mesh, missing rigidbody, non-uniform scale, fast object with discrete detection, missing physics material, collision matrix, mixed 2D/3D. Smart warning levels — static colliders without Rigidbodies are downgraded to [Info] unless the object has an Animator

Simulation​

ActionDescription
simulate_stepStep physics simulation in Edit mode (1–100 steps). Returns positions, velocities, and angular velocities of active Rigidbodies after stepping. Optional target to filter to a specific object

Architecture​

C# — 10 files in MCPForUnity/Editor/Tools/Physics/​

FilePurpose
ManagePhysics.csAction dispatcher with [McpForUnityTool] registration
PhysicsSettingsOps.csping, get_settings, set_settings
CollisionMatrixOps.csget_collision_matrix, set_collision_matrix
PhysicsMaterialOps.cscreate, configure, assign physics materials
JointOps.csadd_joint, configure_joint, remove_joint
PhysicsQueryOps.csraycast, raycast_all, linecast, shapecast, overlap
PhysicsForceOps.csapply_force (normal, explosion, torque)
PhysicsRigidbodyOps.csget_rigidbody, configure_rigidbody
PhysicsValidationOps.csvalidate with pagination and smart warnings
PhysicsSimulationOps.cssimulate_step with state reporting

Python — 3 files​

FilePurpose
Server/src/services/tools/manage_physics.pyMCP tool definition with 21-action Literal type, forwards all params to Unity
Server/src/cli/commands/physics.pyFull CLI with commands for every action category
Server/tests/test_manage_physics.py19 unit tests covering action forwarding and validation

Unity Tests​

FilePurpose
TestProjects/UnityMCPTests/Assets/Tests/EditMode/Tools/ManagePhysicsTests.cs973-line EditMode test suite

Key Design Decisions​

  • Modular ops classes: Each physics domain (settings, materials, joints, queries, forces, etc.) gets its own C# class rather than one monolithic handler
  • Auto-dimension detection: All actions auto-detect 2D vs 3D based on Rigidbody/Rigidbody2D component presence, with optional dimension override
  • Unity version compatibility: Uses #if UNITY_6000_0_OR_NEWER for renamed APIs (drag → linearDamping, angularDrag → angularDamping)
  • Pagination on validate: Large scenes can produce hundreds of warnings — paginated by default (50 per page) with a summary that always shows category counts regardless of page
  • Smart warning levels: "Collider without Rigidbody" only escalates to a warning if the object has an Animator (suggesting runtime movement); otherwise downgraded to [Info]
  • Enriched responses: Force/explosion actions echo back all applied values. Simulation returns Rigidbody states. Validation returns category breakdowns

Stats​

  • Net change: +5,985 / −2,965 lines
  • New C# files: 10 (+ 10 .meta)
  • New Python files: 3
  • Actions: 21
  • Tests: 19 Python + EditMode C# suite