AD

Advanced Unity MCP Server: Editor Code Execution

Enable advanced Unity workflows with an MCP server: execute editor code, fetch logs, access project files and editor state for scripting and asset creation.

Quick Install
npx -y @quazaai/UnityMCPIntegration

Overview

This MCP (Model Context Protocol) server for Unity exposes a small HTTP API that lets external tools and AI agents interact directly with the Unity Editor. It is designed to enable advanced automation and scripting workflows: run editor-side C# snippets, inspect editor state, read and write project files, and fetch Editor logs. That makes it useful for programmatic asset creation, automated scene modifications, and integrating AI-driven tooling into a Unity development loop.

The server runs inside the Unity Editor (or alongside it) and executes requests on the editor thread, so operations have full access to UnityEditor APIs. Because these operations can modify project files and editor state, the server is intended for trusted environments and local development. The GitHub repository and source are available at: https://github.com/quazaai/UnityMCPIntegration

Features

  • Execute arbitrary Unity editor C# code snippets on the editor thread
  • Read and write project files (Assets, Packages) through the editor context
  • Query editor state: open scenes, selection, active objects, playmode status
  • Fetch Editor and Player logs for diagnostics
  • Simple HTTP/JSON API compatible with MCP-style agents and workflows
  • Configurable security options (local-only binding, API key)

Installation / Configuration

  1. Clone the repository into your Unity project (e.g., under Packages or Assets):
git clone https://github.com/quazaai/UnityMCPIntegration.git Packages/com.quazaai.mcp
  1. Open the Unity project. The package installs editor scripts that add the MCP server component.

  2. Configure server options via Project Settings or environment variables:

  • Example environment variables:
# Bind only to localhost (recommended)
MCP_BIND=127.0.0.1
MCP_PORT=5005
# Optional API key for simple auth
MCP_API_KEY=some-secret-token
  1. Start the server from the Unity Editor menu (usually under Tools > MCP Server) or let it auto-start on editor launch if enabled in package settings.

Example minimal configuration file (mcp.config.json):

{
  "bind": "127.0.0.1",
  "port": 5005,
  "requireApiKey": true
}

Available Resources

The server exposes a small set of HTTP endpoints. Use JSON bodies and include the API key as a header (if enabled):

MethodEndpointDescription
POST/executeExecute C# editor code and return result or error
GET/logsRetrieve recent Editor/Player logs
GET/POST/filesRead or write project files (path-based)
GET/stateQuery editor state (selection, scenes, playmode)
GET/healthHealth check / status

Example curl header with API key:

curl -H "Content-Type: application/json" -H "X-MCP-API-Key: some-secret-token" ...

Example Requests

Execute a short editor script (returns JSON result or exception text):

curl -X POST http://127.0.0.1:5005/execute \
  -H "Content-Type: application/json" \
  -H "X-MCP-API-Key: some-secret-token" \
  -d '{"code":"using UnityEditor; using UnityEngine; return Selection.activeGameObject?.name ?? \"<none>\";"}'

Read a project file:

curl "http://127.0.0.1:5005/files?path=Assets/MyPrefab.prefab" \
  -H "X-MCP-API-Key: some-secret-token"

Fetch editor logs:

curl "http://127.0.0.1:5005/logs?lines=200" \
  -H "X-MCP-API-Key: some-secret-token"

C# example (calling server from an external tool):

using System.Net.Http;
using System.Text;
var client = new HttpClient();
client.DefaultRequestHeaders.Add("X-MCP-API-Key", "some-secret-token");
var body = new StringContent("{\"code\":\"EditorApplication.isPlaying\"}", Encoding.UTF8, "application/json");
var resp = await client.PostAsync("http://127.0.0.1:5005/execute", body);
var text = await resp.Content.ReadAsStringAsync();
Console.WriteLine(text);

Use Cases

  • Automated asset generation: Use an LLM or procedural tool to generate meshes/materials and call /execute to construct prefabs in the editor context, saving results directly into Assets.
  • Editor-aware code completion and scripting: Send snippets to /execute to evaluate results or query Selection/Scene contents and adapt scripts programmatically.
  • Continuous content QA: A CI or local bot can query /state and /logs to validate editor setup and catch console errors after automated scene import steps.
  • AI-assisted scene editing: An agent can read the active scene, modify GameObjects via /execute, and persist changes — enabling “make the sky darker” style prompts that run as editor operations.
  • Diagnostics and reproducible debugging: Collect editor logs and exact project file snapshots via /files and /logs endpoints to reproduce issues or feed to automated analysis tools.

Security and Best Practices

  • Run the MCP server only in trusted environments; it executes arbitrary editor code with full project privileges.
  • Prefer binding to localhost (127.0.0.1) and enable API key protection.
  • Disable or firewall the service on shared or CI machines unless explicitly required.
  • Review and audit code snippets before executing in production projects.

For full source, examples, and detailed configuration options, see the GitHub repository: https://github.com/quazaai/UnityMCPIntegration