Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 20 additions & 23 deletions MCPForUnity/UnityMcpServer~/src/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,26 @@ def _emit_startup():
# Initialize MCP server
mcp = FastMCP(
name="mcp-for-unity-server",
lifespan=server_lifespan
lifespan=server_lifespan,
instructions="""
This server provides tools to interact with the Unity Game Engine Editor.\n\n
Available tools:\n
- `manage_editor`: Controls editor state and queries info.\n
- `execute_menu_item`: Executes, lists and checks for the existence of Unity Editor menu items.\n
- `read_console`: Reads or clears Unity console messages, with filtering options.\n
- `manage_scene`: Manages scenes.\n
- `manage_gameobject`: Manages GameObjects in the scene.\n
- `manage_script`: Manages C# script files.\n
- `manage_asset`: Manages prefabs and assets.\n
- `manage_shader`: Manages shaders.\n\n
- Tips:\n
- Create prefabs for reusable GameObjects.\n
- Always include a camera and main light in your scenes.\n
- Unless specified otherwise, paths are relative to the project's `Assets/` folder.\n
- After creating or modifying scripts with `manage_script`, allow Unity to recompile; use `read_console` to check for compile errors.\n
- Use `execute_menu_item` for interacting with Unity systems and third party tools like a user would.\n

"""
Comment on lines +161 to +179
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Incomplete tool list in instructions.

The instructions document 8 tools but the README (lines 41-51) lists 11 tools. The following tools are missing from the instructions:

  • apply_text_edits: Precise text edits with precondition hashes and atomic multi-edit batches
  • script_apply_edits: Structured C# method/class edits (insert/replace/delete) with safer boundaries
  • validate_script: Fast validation (basic/standard) to catch syntax/structure issues before/after writes

These appear to be significant tools for script editing workflows. Please verify whether these tools are registered and add them to the instructions.

Run the following script to confirm which tools are actually registered:


🏁 Script executed:

#!/bin/bash
# Description: Find all tool registrations in the codebase

# Search for tool registration patterns
rg -n "def (apply_text_edits|script_apply_edits|validate_script)" -A 2

Length of output: 2013


🏁 Script executed:

#!/bin/bash
# Description: Find tool registration/decoration patterns

# Search for how tools are decorated and registered
rg -n "@.*tool|@tool|register.*tool" MCPForUnity/UnityMcpServer~/src/ -B 1 -A 1 | head -50

echo "---"

# Check if the three tools use the same registration pattern as others
rg -n "^def (apply_text_edits|script_apply_edits|validate_script|manage_editor|execute_menu_item)" -B 3 | head -80

Length of output: 3014


🏁 Script executed:

#!/bin/bash
# Description: Check server.py context and how tools are actually registered

# Look at the server.py around lines 160-180 to see full context
cat git/MCPForUnity/UnityMcpServer~/src/server.py | sed -n '155,185p'

echo "---"

# Check if tools are auto-discovered or manually registered
rg -n "apply_text_edits|script_apply_edits|validate_script" git/MCPForUnity/UnityMcpServer~/src/server.py

Length of output: 167


🏁 Script executed:

#!/bin/bash
# Description: Locate and read server.py with correct paths

# Find server.py files
fd -type f -name "server.py" | head -5

echo "---"

# Read the first found server.py, focusing on lines 155-185
fd -type f -name "server.py" -exec sed -n '155,185p' {} \; | head -40

Length of output: 345


🏁 Script executed:

#!/bin/bash
# Description: Find and read server.py with correct syntax

# Find server.py files
find . -name "server.py" 2>/dev/null | head -5

echo "---"

# Read the MCPForUnity server.py around lines 155-185
find . -path "*MCPForUnity*server.py" -exec head -185 {} \; 2>/dev/null | tail -35

Length of output: 1483


🏁 Script executed:

#!/bin/bash
# Description: Verify register_all_tools includes all decorated tools

# Find register_all_tools definition
rg -n "def register_all_tools" -A 20

echo "---"

# Also check how many @mcp_for_unity_tool decorations exist
rg -n "@mcp_for_unity_tool" | wc -l
rg -n "@mcp_for_unity_tool" | cut -d: -f1 | sort -u | wc -l

Length of output: 3721


Incomplete tool list in instructions—add missing three tools.

The instructions parameter (lines 161-179) lists 8 tools, but the codebase registers 11 total tools via register_all_tools(). The three missing tools are:

  • apply_text_edits: Precise text edits with precondition hashes and atomic multi-edit batches
  • script_apply_edits: Structured C# method/class edits (insert/replace/delete) with safer boundaries
  • validate_script: Fast validation (basic/standard) to catch syntax/structure issues before/after writes

Add these three tools to the instructions list so the server's documented capabilities match the actual available tools.

🤖 Prompt for AI Agents
In MCPForUnity/UnityMcpServer~/src/server.py around lines 161 to 179, the
instructions string omits three registered tools; update the multi-line
instructions text to include the missing tools `apply_text_edits`,
`script_apply_edits`, and `validate_script` (with short phrases matching the
style used for other tools, e.g., `- apply_text_edits: Precise text edits with
precondition hashes and atomic multi-edit batches.`, `- script_apply_edits:
Structured C# method/class edits (insert/replace/delete) with safer
boundaries.`, `- validate_script: Fast validation (basic/standard) to catch
syntax/structure issues before/after writes.`) so the documented tool list
matches register_all_tools().

)

# Register all tools
Expand All @@ -167,28 +186,6 @@ def _emit_startup():
register_all_resources(mcp)


@mcp.prompt()
def asset_creation_strategy() -> str:
"""Guide for discovering and using MCP for Unity tools effectively."""
return (
"Available MCP for Unity Server Tools:\n\n"
"- `manage_editor`: Controls editor state and queries info.\n"
"- `execute_menu_item`: Executes, lists and checks for the existence of Unity Editor menu items.\n"
"- `read_console`: Reads or clears Unity console messages, with filtering options.\n"
"- `manage_scene`: Manages scenes.\n"
"- `manage_gameobject`: Manages GameObjects in the scene.\n"
"- `manage_script`: Manages C# script files.\n"
"- `manage_asset`: Manages prefabs and assets.\n"
"- `manage_shader`: Manages shaders.\n\n"
"Tips:\n"
"- Create prefabs for reusable GameObjects.\n"
"- Always include a camera and main light in your scenes.\n"
"- Unless specified otherwise, paths are relative to the project's `Assets/` folder.\n"
"- After creating or modifying scripts with `manage_script`, allow Unity to recompile; use `read_console` to check for compile errors.\n"
"- Use `execute_menu_item` for interacting with Unity systems and third party tools like a user would.\n"
)


def main():
"""Entry point for uvx and console scripts."""
mcp.run(transport='stdio')
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,18 +162,17 @@ If Auto-Setup fails or you use a different client:
**Claude Code**

If you're using Claude Code, you can register the MCP server using the below commands:
🚨**make sure to run these from your Unity project's home directory**🚨

**macOS:**

```bash
claude mcp add UnityMCP -- uv --directory /Users/USERNAME/Library/AppSupport/UnityMCP/UnityMcpServer/src run server.py
claude mcp add --scope user UnityMCP -- uv --directory /Users/USERNAME/Library/AppSupport/UnityMCP/UnityMcpServer/src run server.py
```

**Windows:**

```bash
claude mcp add UnityMCP -- "C:/Users/USERNAME/AppData/Local/Microsoft/WinGet/Links/uv.exe" --directory "C:/Users/USERNAME/AppData/Local/UnityMCP/UnityMcpServer/src" run server.py
claude mcp add --scope user UnityMCP -- "C:/Users/USERNAME/AppData/Local/Microsoft/WinGet/Links/uv.exe" --directory "C:/Users/USERNAME/AppData/Local/UnityMCP/UnityMcpServer/src" run server.py
```
**VSCode (all OS)**

Expand Down