docs/guides/MCP_CLIENT_CONFIGURATORS.md
This guide explains how MCP client configurators work in this repo and how to add a new one.
It covers:
For most clients you just need a small class like this:
using System;
using System.Collections.Generic;
using System.IO;
using MCPForUnity.Editor.Models;
namespace MCPForUnity.Editor.Clients.Configurators
{
public class MyClientConfigurator : JsonFileMcpConfigurator
{
public MyClientConfigurator() : base(new McpClient
{
name = "My Client",
windowsConfigPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".myclient", "mcp.json"),
macConfigPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".myclient", "mcp.json"),
linuxConfigPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".myclient", "mcp.json"),
})
{ }
public override IList<string> GetInstallationSteps() => new List<string>
{
"Open My Client and go to MCP settings",
"Open or create the mcp.json file at the path above",
"Click Configure in MCP for Unity (or paste the manual JSON snippet)",
"Restart My Client"
};
}
}
At a high level:
IMcpClientConfigurator (MCPForUnity/Editor/Clients/IMcpClientConfigurator.cs)
Base classes (MCPForUnity/Editor/Clients/McpClientConfiguratorBase.cs)
McpClientConfiguratorBase
JsonFileMcpConfigurator
CheckStatus, Configure, and GetManualSnippet using ConfigJsonBuilder.CodexMcpConfigurator
ClaudeCliMcpConfigurator
McpClient model (MCPForUnity/Editor/Models/McpClient.cs)
namewindowsConfigPath, macConfigPath, linuxConfigPathJsonFileMcpConfigurator):
IsVsCodeLayout – VS Code-style layout (servers root, type field, etc.).SupportsHttpTransport – whether the client supports HTTP transport.EnsureEnvObject – ensure an env object exists.StripEnvWhenNotRequired – remove env when not needed.HttpUrlProperty – which property holds the HTTP URL (e.g. "url" vs "serverUrl").DefaultUnityFields – key/value pairs like { "disabled": false } applied when missing.Auto-discovery (McpClientRegistry)
McpClientRegistry.All uses TypeCache.GetTypesDerivedFrom<IMcpClientConfigurator>() to find configurators.Most MCP clients use a JSON config file that defines one or more MCP servers. Examples:
JsonFileMcpConfigurator (global ~/.cursor/mcp.json).JsonFileMcpConfigurator with IsVsCodeLayout = true.JsonFileMcpConfigurator with IsVsCodeLayout = true and Insider-specific Code - Insiders/User/mcp.json paths.JsonFileMcpConfigurator with standard HTTP transport.JsonFileMcpConfigurator with Windsurf-specific flags (HttpUrlProperty = "serverUrl", DefaultUnityFields["disabled"] = false, etc.).All of these follow the same pattern:
JsonFileMcpConfigurator.McpClient instance in the constructor with:
name.GetInstallationSteps to describe how users open or edit the config.CheckStatus – reads and validates the JSON config; can auto-rewrite to match Unity MCP.Configure – writes/rewrites the config file.GetManualSnippet – builds a JSON snippet using ConfigJsonBuilder.McpClientJsonFileMcpConfigurator relies on the fields on McpClient:
SupportsHttpTransport + EditorPrefs.UseHttpTransport decide whether to configure
url / serverUrl (HTTP), orcommand + args (stdio with uvx).HttpUrlProperty (default "url") selects which JSON property to use for HTTP urls."serverUrl".IsVsCodeLayout = true switches config structure to a VS Code compatible layout.EnsureEnvObject / StripEnvWhenNotRequired control an env block.DefaultUnityFields adds client-specific fields if they are missing (e.g. disabled: false).All of this logic is centralized in ConfigJsonBuilder, so most JSON-based clients do not need to override GetManualSnippet.
Some clients cannot be handled by the generic JSON configurator alone.
CodexMcpConfigurator.~/.codex/config.toml).CodexConfigHelper to:
CodexConfigurator class:
McpClient with TOML config paths.CodexMcpConfigurator.ClaudeCliMcpConfigurator.CheckStatus and Configure are implemented in the base class using claude mcp ... commands:
CheckStatus calls claude mcp list to detect if UnityMCP is registered.Configure toggles register/unregister via claude mcp add/remove UnityMCP.ClaudeCodeConfigurator class:
McpClient with a name.GetInstallationSteps with CLI-specific instructions.JsonFileMcpConfigurator, but only supports stdio transport.ClaudeDesktopConfigurator:
SupportsHttpTransport = false in McpClient.Configure / GetManualSnippet to:
This is the most common scenario: your MCP client uses a JSON file to configure servers.
JsonFileMcpConfigurator if your client reads a JSON config file.CodexMcpConfigurator only if you are integrating a TOML-based client like Codex.ClaudeCliMcpConfigurator only if your client exposes a CLI command to manage MCP servers.Create a new file under:
MCPForUnity/Editor/Clients/Configurators
Name it something like:
MyClientConfigurator.cs
Inside, follow the existing pattern (e.g. CursorConfigurator, WindsurfConfigurator, KiroConfigurator):
MCPForUnity.Editor.Clients.Configuratorspublic class MyClientConfigurator : JsonFileMcpConfiguratorbase(new McpClient { ... }).name = "My Client"windowsConfigPath = ...macConfigPath = ...linuxConfigPath = ...IsVsCodeLayout = true for VS Code-style config.HttpUrlProperty = "serverUrl" if your client expects serverUrl.EnsureEnvObject / StripEnvWhenNotRequired based on env handling.DefaultUnityFields = { { "disabled", false }, ... } for client-specific defaults.Because the constructor is parameterless and public, McpClientRegistry will auto-discover this configurator with no extra registration.
Override GetInstallationSteps to tell users how to configure the client:
Look at CursorConfigurator, VSCodeConfigurator, VSCodeInsidersConfigurator, KiroConfigurator, TraeConfigurator, or AntigravityConfigurator for phrasing.
Unless your client has very unusual behavior, you typically do not need to override:
CheckStatusConfigureGetManualSnippetThe base JsonFileMcpConfigurator:
ConfigJsonBuilder.Only override these methods if your client has constraints that cannot be expressed via McpClient flags.
After adding your configurator class:
McpClient.name).Not Configured.Configured.If your MCP client doesnt store configuration as a JSON file, you likely need a custom base class.
CodexMcpConfigurator.McpClient (similar to CodexConfigurator).GetInstallationSteps to describe how to open/edit the TOML.The Codex-specific status and configure logic is already implemented in the base class.
ClaudeCliMcpConfigurator.McpClient with a name.GetInstallationSteps with the CLI flow.The base class:
MCPServiceLocator.Paths.ExecPath.TryRun to call mcp list, mcp add, and mcp remove.Configure as a toggle between register and unregister.Use this only if the client exposes an official CLI for managing MCP servers.
JsonFileMcpConfigurator subclass in Editor/Clients/Configurators.McpClient with paths and flags.GetInstallationSteps.McpClientRegistry auto-discovers all configurators with a public parameterless constructor.Following these patterns keeps all MCP client integrations consistent and lets users configure everything from the MCP for Unity window with minimal friction.