Repository navigation
API Reference
The C# surface you use to extend Unity MCP. Attributes come from the MCP Plugin .NET library (namespace com.IvanMurzak.McpPlugin); the Unity integration lives in the package com.ivanmurzak.unity.mcp.
| Class | Role |
|---|---|
UnityMcpPlugin |
Shared base: configuration, connection (Connect(), Disconnect()), tool registry |
UnityMcpPluginEditor |
The Editor instance; reads UserSettings/AI-Game-Developer-Config.json
|
UnityMcpPluginRuntime |
The in-game instance, configured from code |
| Attribute | On | Key properties |
|---|---|---|
[AiToolType] |
class |
Target (ToolTarget.Both by default, Editor, Runtime), Path
|
[AiTool(name, title)] |
method |
Title, Visible, Target, ReadOnlyHint, DestructiveHint, IdempotentHint, OpenWorldHint
|
[AiPromptType] |
class | marks a prompt container |
[AiPrompt] |
method |
Name, Role (Role.User / Role.Assistant), Enabled
|
[AiResourceType] |
class | marks a resource container |
[AiResource] |
method |
Route (URI template), Name, Description, MimeType, ListResources, Enabled
|
[Description] |
method, parameter, member | the text the AI reads (System.ComponentModel) |
Visible = false installs a tool hidden: it is not listed to the agent but still runs when called by name. The old Enabled property on [AiTool] is an obsolete alias of Visible.
Hints follow the MCP tool annotations: ReadOnlyHint (does not change anything), DestructiveHint (may delete or overwrite), IdempotentHint (repeating has no extra effect), OpenWorldHint (touches things outside the project).
Tool calls arrive on a background thread. Unity APIs must run on the main thread:
using com.IvanMurzak.ReflectorNet.Utils;
var count = MainThread.Instance.Run(() => Object.FindObjectsOfType<Camera>().Length);
await MainThread.Instance.RunAsync(() => EditorApplication.isPlaying = true);On Windows, if a modal dialog blocks the main thread for more than 2 s, the call fails fast with a message that names the dialog and its buttons instead of hanging (unity-mcp-cli dialog can answer it).
The plugin also runs inside a built game. It has no built-in runtime tools; you register your own.
using System.Reflection;
using com.IvanMurzak.Unity.MCP;
using UnityEngine;
public static class GameMcp
{
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
static async void Setup()
{
var plugin = UnityMcpPluginRuntime.Initialize(builder =>
{
builder.WithConfig(c => c.Host = "http://localhost:8080");
builder.WithToolsFromAssembly(Assembly.GetExecutingAssembly());
})
.Build();
await plugin.Connect(); // later: await plugin.Disconnect();
}
}Mark game-only tools with [AiToolType(Target = ToolTarget.Runtime)] (using com.IvanMurzak.McpPlugin.Common;). Setting the environment variable UNITY_MCP_DISABLE=1 (or true) before Unity starts turns the plugin off.
UserSettings/AI-Game-Developer-Config.json holds, among others: connectionMode (Cloud / Custom), host (used only in Custom), transportMethod, authOption, keepServerRunning, the tool timeout, and the visibility of every tool, prompt and resource. Edit it through the window or unity-mcp-cli configure; see Configuration.
#nullable enable in every file, the Apache-2.0 copyright header, one partial-class file per tool, kebab-case IDs. Details: docs/agents/style.md.