A bridge between the Unity game engine and AI assistants using the Model Context Protocol (MCP).
A bridge between Unity and AI assistants using the Model Context Protocol (MCP).
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.
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
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.
To get started with Unity-MCP, follow these steps:
Clone the repository:
git clone https://github.com/TSavo/Unity-MCP.git
cd Unity-MCP
Install dependencies:
npm install
Build the project:
npm run build
Start the MCP STDIO client:
npm start
This will start the MCP STDIO client that communicates with Unity and uses AILogger for persistence.
Note: Make sure AILogger is running on http://localhost:3030 or set the AI_LOGGER_URL environment variable to point to your AILogger instance.
Run tests:
# Run all tests
npm test
# Run only unit tests
npm run test:unit
# Run only e2e tests
npm run test:e2e
# Run tests with a specific pattern
npm test -- --testNamePattern="should return the server manifest"
npm run test:unit -- --testNamePattern="should return the server manifest"
npm run test:e2e -- --testNamePattern="should discover the test server"
For more detailed instructions, see the Installation Guide.
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.
The Unity-MCP bridge provides the following tools:
You can execute C# code in Unity using the execute_code
tool. The code will be executed in the Unity runtime environment, and the result will be stored in AILogger for later retrieval.
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "execute_code",
"arguments": {
"code": "Debug.Log(\"Hello from Unity!\"); return GameObject.FindObjectsOfType<GameObject>().Length;",
"timeout": 5000
}
}
}
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"content": [
{
"type": "text",
"text": "{\"status\":\"success\",\"logName\":\"unity-execute-1712534400000\",\"result\":{\"success\":true,\"result\":42,\"logs\":[\"Hello from Unity!\"],\"executionTime\":123}}"
}
]
}
}
You can query Unity objects using the query
tool. This allows you to access objects, properties, and methods using dot notation.
{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/call",
"params": {
"name": "query",
"arguments": {
"query": "Camera.main.transform.position",
"timeout": 5000
}
}
}
{
"jsonrpc": "2.0",
"id": 2,
"result": {
"content": [
{
"type": "text",
"text": "{\"status\":\"success\",\"logName\":\"unity-query-1712534400000\",\"result\":{\"success\":true,\"result\":{\"x\":0,\"y\":1,\"z\":-10},\"executionTime\":45}}"
}
]
}
}
You can retrieve the results of previous operations from AILogger using the get_log_by_name
tool.
{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "get_log_by_name",
"arguments": {
"log_name": "unity-execute-1712534400000",
"limit": 1
}
}
}
{
"jsonrpc": "2.0",
"id": 3,
"result": {
"content": [
{
"type": "text",
"text": "{\"status\":\"success\",\"name\":\"unity-execute-1712534400000\",\"entries\":[{\"id\":\"123e4567-e89b-12d3-a456-426614174000\",\"name\":\"unity-execute-1712534400000\",\"data\":{\"result\":{\"success\":true,\"result\":42,\"logs\":[\"Hello from Unity!\"],\"executionTime\":123},\"timestamp\":\"2025-04-08T00:00:00.000Z\"},\"timestamp\":\"2025-04-08T00:00:00.000Z\"}]}"
}
]
}
}
Once the AI assistant has access to the Unity tool, you can ask it to perform tasks like:
Can you execute the following C# code in Unity?
GameObject.Find("Player").transform.position = new Vector3(0, 1, 0);
MIT
T Savo (@TSavo)
A collection of reference implementations for the Model Context Protocol (MCP), showcasing various MCP servers implemented with TypeScript and Python SDKs.
An MCP server and client implementation for EdgeOne Pages Functions, supporting OpenAI-formatted requests.
An intelligent scientific reasoning framework that uses graph structures and Neo4j to perform advanced reasoning via the Model Context Protocol (MCP).
A Python server providing Retrieval-Augmented Generation (RAG) functionality. It indexes various document formats and requires a PostgreSQL database with pgvector.
A Model Context Protocol (MCP) server for CODESYS V3 programming environments.
Provides real-time access to Chainlink's decentralized on-chain price feeds.
A template for deploying a remote, auth-less MCP server on Cloudflare Workers.
A Model Context Protocol (MCP) server that enables AI assistants to integrate with Prometheus Alertmanager
A collection of reference implementations for the Model Context Protocol (MCP), demonstrating how to give LLMs secure access to tools and data using Typescript and Python SDKs.
An authentication-free, remote MCP server deployable on Cloudflare Workers or locally via npm.