unity_run_csharp
Compile and run C# snippets against the live Unity editor using Roslyn. Use custom logic, batch edits, or project-specific types; get compile errors with line numbers to fix and retry.
Instructions
Compile and run a C# snippet against the live editor with Unity's own Roslyn compiler. Use code for a method body (auto-wrapped, return a value to see it) or source for a complete file. Compile errors come back with line numbers so you can fix and retry. This is how you do anything the other tools do not cover: custom logic, batch edits, project-specific types. (Unity editor offline right now: schemas are cached; calls will fail until it reconnects)
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "unity_run_csharp"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | No | method body; returns whatever you `return`. Usings available: System, System.Linq, UnityEngine, UnityEditor, UnityEngine.SceneManagement | |
| type | No | entry type for `source` mode, e.g. My.Ns.Thing | |
| method | No | entry method, default Run | |
| source | No | complete C# file instead of `code` | |
| usings | No | semicolon-separated usings to override the defaults | |
| references | No | extra DLL paths to reference |