Labsco
TSavo logo

Unity-MCP

โ˜… 7

from TSavo

A bridge between the Unity game engine and AI assistants using the Model Context Protocol (MCP).

๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅโœ“ VerifiedFreeAdvanced setup

Unity-MCP

A bridge between Unity and AI assistants using the Model Context Protocol (MCP).

Overview

Unity-MCP is an open-source implementation of the Model Context Protocol for Unity game development. It enables AI assistants to interact with Unity game environments through a standardized interface, allowing for AI-assisted game development, automated testing, scene analysis, and runtime debugging.

Architecture

The architecture has been simplified to use AILogger for persistence, removing the need for a separate server component:

AI Assistant <-> Unity-MCP STDIO Client <-> Unity Client <-> AILogger
  • AI Assistant: Communicates with the Unity-MCP STDIO Client using the MCP protocol
  • Unity-MCP STDIO Client: Forwards commands to the Unity Client and stores results in AILogger
  • Unity Client: Executes commands in Unity and returns results
  • AILogger: Stores logs and results for later retrieval

The Unity-MCP STDIO Client communicates directly with the Unity Client, which provides endpoints for both code execution and queries. The query tool transforms queries into code execution by wrapping them in a return statement.

Features

  • Execute C# code in the Unity runtime environment
  • Inspect game objects and their components
  • Analyze scene hierarchies and structures
  • Run tests and receive results
  • Invoke methods on game objects and components
  • Modify game state during runtime

Documentation

Connecting to AI Assistants

To connect the Unity-MCP bridge to an AI assistant, you need to create an MCP configuration file:

{
  "mcpServers": {
    "unity-ai-bridge": {
      "url": "http://localhost:8080/sse"
    }
  }
}

Place this file in the appropriate location for your AI assistant. For Claude, this would typically be in the Claude Desktop app's configuration directory.

Available Tools

The Unity-MCP bridge provides the following tools:

  1. execute_code: Execute C# code directly in Unity.
  2. query: Execute a query using dot notation to access objects, properties, and methods.
  3. get_logs: Retrieve logs from AILogger.
  4. get_log_by_name: Retrieve a specific log from AILogger.

Author

T Savo (@TSavo)