YetAnotherUnityMcp

YetAnotherUnityMcp

MCP server that bridges Unity with AI agents, enabling scene inspection, C# code execution, and screenshot capture via WebSocket communication.

Category
访问服务器

README

YetAnotherUnityMcp

A Unity Master Control Protocol (MCP) implementation that allows AI agents to control and interact with Unity.

Overview

YetAnotherUnityMcp is a system that bridges the Unity game engine with AI-driven tools using the Model Context Protocol (MCP). It consists of a Unity .NET/C# plugin acting as the MCP client, and a Python MCP server (built with FastMCP) that handles requests from AI agents. Communication between Unity and the server is done via WebSockets, enabling real-time, bidirectional exchange of JSON messages and image data.

This architecture cleanly separates the game engine concerns from the AI logic, improving scalability and maintainability. The goal is to allow AI agents (e.g. an LLM-based assistant) to inspect and control a running Unity scene in a structured, safe manner.

Key components include:

  1. Unity MCP Plugin (Client) – A C# plugin integrated into the Unity Editor that connects to the MCP server via WebSockets
  2. FastMCP Python Server – A Python application that implements the MCP interface for Unity
  3. MCP Client (AI or External) – The external entity (such as an AI assistant or testing script) that sends MCP requests

What is MCP?

The Model Context Protocol (MCP) is a standardized way for AI models to interact with applications. It separates the concerns of providing context from the LLM interaction itself, allowing for:

  • Resources: Providing data to LLMs (like Unity scene hierarchies)
  • Tools: Allowing LLMs to take actions (like executing code in Unity)
  • Prompts: Defining interaction templates (like how to create GameObjects)

Features

  • Execute C# code in Unity from AI agents
  • Query Unity Editor state through MCP resources
  • Capture screenshots with AI-driven parameters
  • Get logs and debug information from Unity
  • Modify GameObject properties with AI assistance
  • List and navigate GameObject hierarchies
  • Provide contextual templates through MCP prompts
  • Real-time communication via WebSockets
  • Fallback to local command execution when server is unavailable

Getting Started

Server Setup

# Clone the repository
git clone https://github.com/yourusername/YetAnotherUnityMcp.git
cd YetAnotherUnityMcp

# Create and activate a virtual environment using uv
uv venv -p 3.11
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install the server with development dependencies
uv pip install -e ".[dev]"

# Run the MCP server for AI integration
python -m server.mcp_server

# Alternatively, run the WebSocket-based server
python -m server.websocket_mcp_server

MCP Integration

# Install FastMCP and tools
uv pip install fastmcp

# Run the server with MCP inspector for debugging
fastmcp dev server/mcp_server.py

# Install in Claude Desktop
fastmcp install server/mcp_server.py --name "Unity Controller"

Unity Plugin Setup

  1. Open your Unity project (2020.3 or later)
  2. Import the YetAnotherUnityMcp plugin using one of these methods:
    • Copy the plugin/Scripts folder to your Unity project's Assets directory
    • Create a Unity package and import it
    • Create a symbolic link for development (Windows PowerShell example):
      New-Item -ItemType SymbolicLink -Target "D:\Dev\YetAnotherUnityMcp\plugin" -Path "C:\Users\azrea\My project\Assets\Plugins\YetAnotherUnityMcp"
      
  3. Add the MCPClient to your scene
    • Create an empty GameObject
    • Add the MCPClient component
    • Configure the server URL (WebSocket URL, e.g., ws://localhost:8000/ws)
  4. Use the MCP Editor Window
    • Open: Window > MCP Client (standard HTTP-based client)
    • Or: Window > WebSocket MCP Client (WebSocket-based client)
    • Connect to the server
    • Test the various MCP features

Project Structure

YetAnotherUnityMcp/
├── server/                      # Python MCP server
│   ├── api/                     # API endpoints
│   ├── models/                  # Data models
│   ├── main.py                  # Traditional API server
│   ├── mcp_server.py            # MCP server implementation
│   ├── websocket_mcp_server.py  # WebSocket-based MCP server
│   └── fastmcp_example.py       # Simple FastMCP example
├── plugin/                      # Unity C# plugin
│   ├── Scripts/                 # Plugin source code
│   │   ├── Editor/              # Editor extensions
│   │   │   ├── Commands/        # Editor command implementations
│   │   │   ├── Models/          # Data models for Editor
│   │   │   └── WebSocket/       # WebSocket implementation
│   │   └── YetAnotherUnityMcp.asmdef  # Assembly definition
│   └── README.md                # Plugin documentation
└── tests/                       # Test suite

MCP Resources and Tools

Resources

  • unity://info - Basic information about the Unity environment
  • unity://logs - Editor logs for debugging
  • unity://scene/{scene_name} - Information about a specific scene
  • unity://object/{object_id} - Details about a specific GameObject

Tools

  • execute_code - Run C# code in the Unity Editor
  • screen_shot_editor - Take screenshots of the Unity Editor
  • modify_object - Change properties of Unity GameObjects

Prompts

  • create_object - Template for creating new GameObjects
  • debug_error - Template for diagnosing Unity errors

Communication Protocol

All communication between the Unity plugin and the Python server uses a WebSocket connection, which allows persistent, low-latency bidirectional messaging. The connection is initiated by the Unity client to the server's WebSocket endpoint (e.g. ws://localhost:8000/ws).

Every message is a JSON object containing at least a message type, a unique ID (to pair requests with responses), and a payload. For more details on the communication protocol, see the Technical Details document.

Development

# Server development
python -m pytest                    # Run tests
python -m black .                   # Format code
python -m flake8                    # Lint code
python -m mypy .                    # Type check
python -m pytest tests/test_mcp_server.py  # Test MCP integration

# MCP Development
fastmcp dev server/mcp_server.py           # Run with MCP Inspector UI
fastmcp dev server/websocket_mcp_server.py # Run WebSocket server with Inspector

# Plugin development
# The Unity plugin can be developed in Unity Editor
# Use the editor window for testing

License

This project is licensed under the MIT License - see the LICENSE file for details.

For more details on architecture, implementation, and extensibility, see the Technical Details document.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选