unity-mcp/Server
dsarno 2b23af45a2
Fix/script path assets prefix and ctx warn bug (#453)
* Fix script path handling and FastMCP Context API usage

1. Fix script path doubling when Assets prefix is used
   - ManageScript.TryResolveUnderAssets now properly handles both Assets and Assets/ prefixes
   - Previously, paths like Assets/Script.cs would create files at Assets/Assets/Script.cs
   - Now correctly strips the prefix and creates files at the intended location

2. Fix FastMCP Context API call in manage_asset
   - Changed ctx.warn() to ctx.warning() to match FastMCP Context API
   - Fixes AttributeError when manage_asset encounters property parse errors
   - Affects ScriptableObject creation and other asset operations with invalid properties

* Fix manage_asset error handling to use ctx.error

Changed ctx.warning to ctx.error for property parse errors in manage_asset
tool to properly handle error cases. This ensures parse errors are reported
as errors rather than warnings, and fixes compatibility with FastMCP Context API.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-10 20:09:16 -08:00
..
src Fix/script path assets prefix and ctx warn bug (#453) 2025-12-10 20:09:16 -08:00
tests feat: Add `manage_material` tool for dedicated material manipulation (#440) 2025-12-07 19:39:52 -08:00
Dockerfile HTTP Server, uvx, C# only custom tools (#375) 2025-11-24 23:21:06 -04:00
README.md chore: bump version to 8.2.2 2025-12-10 23:11:15 +00:00
__init__.py Copy the MCP server to the top level (#354) 2025-10-25 00:53:53 -04:00
pyproject.toml chore: bump version to 8.2.2 2025-12-10 23:11:15 +00:00
pyrightconfig.json Copy the MCP server to the top level (#354) 2025-10-25 00:53:53 -04:00
uv.lock feat: Add `manage_material` tool for dedicated material manipulation (#440) 2025-12-07 19:39:52 -08:00

README.md

MCP for Unity Server

MCP python License Discord

Model Context Protocol server for Unity Editor integration. Control Unity through natural language using AI assistants like Claude, Cursor, and more.

Maintained by Coplay - This project is not affiliated with Unity Technologies.

💬 Join our community: Discord Server

Required: Install the Unity MCP Plugin to connect Unity Editor with this MCP server.


Installation

Run directly from GitHub without installation:

# HTTP (default)
uvx --from git+https://github.com/CoplayDev/unity-mcp@v8.2.2#subdirectory=Server \
    mcp-for-unity --transport http --http-url http://localhost:8080

# Stdio
uvx --from git+https://github.com/CoplayDev/unity-mcp@v8.2.2#subdirectory=Server \
    mcp-for-unity --transport stdio

MCP Client Configuration (HTTP):

{
  "mcpServers": {
    "UnityMCP": {
      "url": "http://localhost:8080/mcp"
    }
  }
}

MCP Client Configuration (stdio):

{
  "mcpServers": {
    "UnityMCP": {
      "command": "uvx",
      "args": [
        "--from",
        "git+https://github.com/CoplayDev/unity-mcp@v8.2.2#subdirectory=Server",
        "mcp-for-unity",
        "--transport",
        "stdio"
      ],
      "type": "stdio"
    }
  }
}

Option 2: Using uv (Local Installation)

For local development or custom installations:

# Clone the repository
git clone https://github.com/CoplayDev/unity-mcp.git
cd unity-mcp/Server

# Run with uv (HTTP)
uv run server.py --transport http --http-url http://localhost:8080

# Run with uv (stdio)
uv run server.py --transport stdio

MCP Client Configuration (HTTP):

{
  "mcpServers": {
    "UnityMCP": {
      "url": "http://localhost:8080/mcp"
    }
  }
}

MCP Client Configuration (stdio Windows):

{
  "mcpServers": {
    "UnityMCP": {
      "command": "uv",
      "args": [
        "run",
        "--directory",
        "C:\\path\\to\\unity-mcp\\Server",
        "server.py",
        "--transport",
        "stdio"
      ]
    }
  }
}

MCP Client Configuration (stdio macOS/Linux):

{
  "mcpServers": {
    "UnityMCP": {
      "command": "uv",
      "args": [
        "run",
        "--directory",
        "/path/to/unity-mcp/Server",
        "server.py",
        "--transport",
        "stdio"
      ]
    }
  }
}

Option 3: Using Docker

docker build -t unity-mcp-server .
docker run -p 8080:8080 unity-mcp-server --transport http --http-url http://0.0.0.0:8080

Configure your MCP client with "url": "http://localhost:8080/mcp". For stdio-in-docker (rare), run the container with --transport stdio and use the same command/args pattern as the uv examples, wrapping it in docker run -i ... if needed.


Configuration

The server connects to Unity Editor automatically when both are running. No additional configuration needed.

Environment Variables:

  • DISABLE_TELEMETRY=true - Opt out of anonymous usage analytics
  • LOG_LEVEL=DEBUG - Enable detailed logging (default: INFO)

Example Prompts

Once connected, try these commands in your AI assistant:

  • "Create a 3D player controller with WASD movement"
  • "Add a rotating cube to the scene with a red material"
  • "Create a simple platformer level with obstacles"
  • "Generate a shader that creates a holographic effect"
  • "List all GameObjects in the current scene"

Documentation

For complete documentation, troubleshooting, and advanced usage:

📖 Full Documentation


Requirements

  • Python: 3.10 or newer
  • Unity Editor: 2021.3 LTS or newer
  • uv: Python package manager (Installation Guide)

License

MIT License - See LICENSE