YetAnotherUnityMcp is a system that bridges the Unity game engine with AI-driven tools using the Model Context Protocol (MCP). It enables AI agents to inspect and control a running Unity scene through a TCP server hosted directly in Unity, with a Python client that handles the AI interaction.
plugin/Scripts
folder to your Unity project's Assets directoryNew-Item -ItemType SymbolicLink -Target "D:\Dev\YetAnotherUnityMcp\plugin" -Path "C:\Users\azrea\My project\Assets\Plugins\YetAnotherUnityMcp"
# 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 client
python -m server.mcp_server
# Install FastMCP and tools
uv pip install fastmcp
# Run the client with MCP inspector for debugging
fastmcp dev server/mcp_server.py
# Install in Claude Desktop
fastmcp install server/mcp_server.py --name "Unity Controller"
The MCP server provides several resources that can be queried:
unity://info
- Basic information about the Unity environmentunity://logs
- Editor logs for debuggingunity://scene/{scene_name}
- Information about a specific sceneunity://object/{object_id}
- Details about a specific GameObjectYou can use these tools to interact with Unity:
You can use the MCP client to execute C# code directly in Unity:
# Example using the MCP client to execute code
from fastmcp import MCPClient
async with MCPClient() as client:
result = await client.use_tool(
"execute_code_in_unity",
{
"code": "Debug.Log(\"Hello from MCP!\"); return GameObject.FindObjectsOfType<GameObject>().Length;"
}
)
print(f"Number of GameObjects: {result}")
To capture the current Unity scene:
async with MCPClient() as client:
screenshot = await client.use_tool(
"unity_screenshot",
{
"width": 1280,
"height": 720,
"camera": "Main Camera" # Optional: specific camera name
}
)
# Screenshot is returned as base64 encoded image
with open("unity_screenshot.png", "wb") as f:
f.write(base64.b64decode(screenshot["image_data"]))
To modify properties of a GameObject in Unity:
async with MCPClient() as client:
# First get information about available objects
scene_info = await client.get_resource("unity://scene/SampleScene")
# Then modify a specific object
result = await client.use_tool(
"unity_modify_object",
{
"object_id": scene_info["objects"][0]["id"],
"position": {"x": 0, "y": 2, "z": 0},
"rotation": {"x": 0, "y": 45, "z": 0},
"scale": {"x": 2, "y": 2, "z": 2}
}
)
All communication between the Unity server and the Python client uses a TCP socket connection with a simple framing protocol for persistent, low-latency bidirectional messaging:
This allows for real-time interaction with Unity from AI agents or other external systems.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"cursor-rules-mcp": {
"command": "npx",
"args": [
"-y",
"cursor-rules-mcp"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.