UN

Unity3d Editor MCP Server for LLMs

Enable LLMs to interact with the Unity3d Editor via an MCP server to access console and test logs, editor functions, hierarchy state, and execute editor tools.

Quick Install
npx -y @CoderGamester/mcp-unity

Overview

This MCP (Model Context Protocol) server runs inside the Unity3D Editor and exposes editor state and functions to LLM-based agents. It allows external language models to observe console and test logs, query the scene/hierarchy, and request execution of editor tools or automated editor commands using a standard protocol. The server is intended for development workflows where LLMs need structured access to project context to provide debugging help, automated edits, or content generation.

Using an editor-hosted MCP server keeps the communication local to the development machine (or a secured network) and lets model-driven agents interact with a live Unity Editor instance instead of just static files. This enables capabilities like summarizing runtime errors, applying repair patches suggested by models, running and analyzing tests, or manipulating scene hierarchies programmatically and safely.

Features

  • Exposes Unity Editor state and events via the MCP protocol
  • Read access to console logs, test results, and playmode events
  • Queryable scene/hierarchy and GameObject/component metadata
  • Execute registered editor tools, menu actions, and scripted commands
  • Simple local HTTP endpoint, configurable port and auth
  • Designed for integration with LLM agents and tool-runners that support MCP

Installation / Configuration

  1. Clone the repository:
git clone https://github.com/CoderGamester/mcp-unity.git
cd mcp-unity
  1. Open the project in the Unity Editor (recommended Unity 2019.4+). Import the package or copy the “Assets/MCP” folder into your Unity project’s Assets folder.

  2. Start the MCP server from the Editor menu or a dedicated window (the package provides an Editor window to control the server). Alternatively, enable auto-start in the Inspector for the MCP component.

Example configuration file (mcp-config.json):

{
  "port": 8765,
  "bindAddress": "127.0.0.1",
  "authToken": "changeme",
  "logBufferSize": 1000,
  "enablePlaymodeEvents": true
}

Start the server (if provided as a CLI or HTTP call):

curl -X POST "http://127.0.0.1:8765/mcp/start" \
  -H "Authorization: Bearer changeme"

Example: request the latest console logs

curl "http://127.0.0.1:8765/mcp/console?limit=100" \
  -H "Authorization: Bearer changeme"

Note: exact menu names and start endpoints depend on the shipped package version in the repository. The above commands show typical usage patterns.

Available Resources

The MCP server exposes a set of resources useful to LLM-based tooling. Typical endpoints/resources include:

ResourcePurpose
Console logsRetrieve recent editor and runtime logs, with timestamps and stack traces
Test resultsAccess unit/integration test run summaries, failures, and stack traces
Hierarchy snapshotSerialize scene root GameObjects, names, components, and transform data
Scene diffProduce compact change sets or suggestions for scene modifications
Editor toolsTrigger registered editor actions, menu commands, or custom scripted tools
Asset databaseQuery assets by type, GUID, and path; preview metadata
Playmode controlStart/stop playmode, capture playmode events and frames

Available resources are registered by the package and by any custom editor scripts that opt into the MCP bridge. Each resource typically accepts query parameters (limit, filters, serialization depth) and returns JSON structured for LM consumption.

Use Cases

  • Debugging assistant: An LLM fetches the latest error logs and failing test traces, summarizes root causes, and suggests concrete editor commands to fix missing references or incorrect prefabs. The model can then request the editor to apply the suggested changes.
  • Automated test summarization: After running CI or local test suites, the MCP server provides structured test outcomes to an LLM which classifies failures and drafts a checklist for triage.
  • Scene editing by intent: A designer describes a change (“place three enemy prefabs along the platform and rotate them to face the player”); the LLM translates the intent into a sequence of MCP tool calls that instantiate prefabs and set transforms.
  • Content generation and validation: Generate placeholder content (textures, prefabs) and have the LLM validate naming conventions, folder placement, and asset metadata via the asset database API.

Security & Best Practices

  • Run the server only in a trusted environment; restrict binding to localhost or a secured network.
  • Use token authentication (as shown in configuration) and enable firewall rules for the MCP port.
  • Limit capabilities for untrusted models: prefer read-only access for third-party tools, and gate destructive editor actions behind explicit approval flows.
  • Log and audit MCP requests so changes are traceable and reversible via source control.

Troubleshooting

  • If the server does not start, check Unity console for initialization errors and port conflicts.
  • Increase logBufferSize in config to capture more console history if requests return incomplete logs.
  • If models produce invalid editor requests, enforce a review step before executing high-impact changes.

For the repository and latest implementation details, visit: https://github.com/CoderGamester/mcp-unity

Tags:ai-ml