unity_execute_code
Run C# code inside the Unity Editor with full access to Unity and Editor APIs, returning a small JSON result so you can inspect changes, trigger actions, or query project state.
Instructions
Run C# in the Unity Editor with Unity API access. Return a small JSON result. If an error has executionCompleted=true, the code already ran; inspect its effects before retrying.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"code": "<code>"
},
"name": "unity_execute_code"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | C# code to execute. Must be a valid method body. Access UnityEngine and UnityEditor namespaces. Use 'return' to send data back. | |
| port | No | Unity instance port (from unity_select_instance). Always include it when multiple instances run. |