Skip to content

API Reference

Ivan Murzak edited this page Nov 13, 2026 · 6 revisions

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.

Architecture

AI agent, MCP server (GameDev-MCP-Server), Unity plugin, Unity API
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

Attributes

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).

Threading

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).

Runtime (in-game)

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.

Configuration file

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.

Coding conventions (for contributions)

#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.

Clone this wiki locally