A native Model Context Protocol (MCP) server that connects AI coding agents (Antigravity, Claude Code, Cursor, VS Code) directly with the Unity Editor.
By communicating with a running Unity Editor (or a headless background instance) via loopback TCP sockets and exposing standard JSON-RPC stdio MCP tools, UnityCliRunner enables sub-second compilation feedback, instant test execution, dynamic C# evaluation, and static method invocations without shell quoting issues or slow batchmode restarts.
UnityCliRunner provides 6 core MCP tools:
unity_status: Inspects Editor connection state (Ready,Not Running,Compiling, orRunning Unreachable).unity_refresh: TriggersAssetDatabase.Refresh()and returns compiler diagnostics.unity_recompile: Cleans compiler cache and forces a full rebuild of script assemblies.unity_run_tests: Runs EditMode and/or PlayMode unit and integration tests with granular filtering by name (filter) and category (category).unity_execute_method: Executes static C# methods (Namespace.Class.Method) with typed arguments and returns formatted outputs and console logs.unity_eval: Evaluates live C# expressions, statements, or multiline blocks dynamically in-memory without domain reloads.unity_stop: Safely stops the running Unity background instance.
| Tool | Parameters | Description |
|---|---|---|
unity_status |
none | Checks Editor state (Ready, Not Running, etc.). |
unity_refresh |
none | Triggers AssetDatabase.Refresh() and returns compilation diagnostics. |
unity_recompile |
none | Forces a full C# recompilation (clears build cache) and returns compiler diagnostics. |
unity_run_tests |
filter, category, mode (all, editmode, playmode) |
Runs tests and reports pass/fail/skip counts and failed stack traces. |
unity_execute_method |
methodName, args (array) |
Executes static C# method with arguments (refreshes first, stops Play Mode). |
unity_eval |
code (string) |
Evaluates C# expression or script dynamically in-memory against active Editor/Play Mode. |
unity_stop |
none | Safely terminates the background Unity Editor instance. |
Auto-Start: If Unity is not running when an operation is requested, UnityCliRunner automatically starts a headless background instance in batchmode first.
- .NET 10.0 Runtime or SDK (
dotnet). - Unity: Version 2021.3 or higher.
openupm add com.pereviader.unityclirunnerOr add via git URL in Unity's Package Manager:
https://github.com/PereViader/UnityCliRunner.git?path=src/UnityCliRunner.Unity3d/Packages/com.pereviader.unityclirunner
In the Unity Editor menu, select: Tools > UnityCliRunner > Install MCP Configurations
This installs the repository launcher (.unity-cli/Launcher.cs) and configures your AI development tools:
- Repository-Portable Configurations (safe to commit to git):
- VS Code:
.vscode/mcp.json(usesserversschema and${workspaceFolder}) - Cursor:
.cursor/mcp.json(usesmcpServersschema and${workspaceFolder}) - Claude Code:
.mcp.json(usesmcpServersschema and${CLAUDE_PROJECT_DIR:-.})
- VS Code:
- Machine-Specific Configurations (gitignored):
- Antigravity:
.agents/plugins/unity-cli/mcp_config.json(uses absolute paths to.unity-cli/Launcher.csand Unity project) - Codex:
.codex/config.toml(uses absolute paths to.unity-cli/Launcher.csand Unity project)
- Antigravity:
- Codex & Antigravity: Because these clients do not support environment/workspace variable substitution in their local MCP configs, the installer writes absolute paths to
.unity-cli/Launcher.csand the Unity project directory. ThroughLauncher.cs, they still automatically resolve and track any future updates tocom.pereviader.unityclirunneracrossLibrary/PackageCache. - Claude Desktop: Claude Desktop only supports global user configurations (
claude_desktop_config.json) rather than repository-level configurations. For Claude Desktop, configure the server in your global configuration using the launcher or absolute package path.
For repository-portable configurations (e.g. VS Code, Cursor, Claude Code), invoke .unity-cli/Launcher.cs:
{
"servers": {
"unity-cli": {
"command": "dotnet",
"args": [
"run",
"--file",
"${workspaceFolder}/.unity-cli/Launcher.cs",
"--",
"--project",
"${workspaceFolder}/<relative-path-to-unity-project>"
]
}
}
}The MCP binary can also be called directly from the command line for testing or scripting:
# Check status
dotnet Packages/com.pereviader.unityclirunner/MCP~/UnityCliRunner.Mcp.dll call unity_status
# Evaluate C#
dotnet Packages/com.pereviader.unityclirunner/MCP~/UnityCliRunner.Mcp.dll call unity_eval '{"code":"1 + 1"}'
# Refresh AssetDatabase
dotnet Packages/com.pereviader.unityclirunner/MCP~/UnityCliRunner.Mcp.dll call unity_refresh
# Run tests
dotnet Packages/com.pereviader.unityclirunner/MCP~/UnityCliRunner.Mcp.dll call unity_run_tests '{"mode":"editmode"}'
# Execute static method
dotnet Packages/com.pereviader.unityclirunner/MCP~/UnityCliRunner.Mcp.dll call unity_execute_method '{"methodName":"Tests.DummyExecuteClass.SuccessMethod"}'MIT License. See LICENSE.md for details.