Skip to content
Open
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
1 change: 1 addition & 0 deletions Editor/Settings/McpSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ static void Load() {
_instance.authToken = GenerateToken();
Save();
}
Debug.Log($"[McpSettings] Auth token {_instance.authToken}");
}

public static void Save() {
Expand Down
64 changes: 64 additions & 0 deletions Server~/mcp-instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Connecting to UnityMCP

This guide explains how to test your Unity MCP server from the command line and how to configure Antigravity to use it.

## Testing via CMD (Original HTTP JSON-RPC)

Since the original `server.js` implementation uses HTTP POST JSON-RPC, you can test it directly via Command Prompt or PowerShell without any special MCP client tools.

Make sure `server.js` is running:
```cmd
npm start
```

**Using Command Prompt (curl):**
```cmd
curl -X POST http://127.0.0.1:5173/mcp -H "Content-Type: application/json" -H "Authorization: Bearer dev-local-token" -d "{\"jsonrpc\": \"2.0\", \"id\": 1, \"method\": \"tools/list\"}"
```

**Using PowerShell:**
```powershell
Invoke-RestMethod -Uri "http://127.0.0.1:5173/mcp" -Method Post -Headers @{"Authorization"="Bearer dev-local-token"} -ContentType "application/json" -Body '{"jsonrpc": "2.0", "id": 1, "method": "tools/list"}'
```

***

## Connecting UnityMCP to Antigravity

Antigravity natively requires an MCP server to communicate through the standard **stdio** transport or **SSE** stream. The newly implemented `src/mcp-stdio.js` allows Antigravity to connect via stdio exactly as intended by the MCP protocol.

### Antigravity Configuration

To attach the server to the Antigravity agent context (or an IDE like Cursor, Windsurf, Claude Desktop), you need to add it to your MCP settings file (typically `mcp.json` or within IDE settings for MCP Servers):

1. **Open your MCP configuration file.**
2. **Add the following entry snippet:**

```json
{
"mcpServers": {
"unity-mcp": {
"command": "node",
"args": [
"f:/Node/UnityMCP/Server~/src/mcp-stdio.js"
],
"env": {
"MCP_TOKEN": "dev-local-token",
"MCP_HTTP_PORT": "5173",
"MCP_IPC_PORT": "52100"
}
}
}
}
```

### Starting the Server Manually (Troubleshooting)
If you want to manually run the stdio server to make sure it loads correctly and finds the new MCP SDK:
```cmd
npm run mcp
```
*(Note: Because it's a `stdio` server, it will appear to hang and not print anything besides standard error logs. This is perfectly normal because it's actively waiting for JSON-RPC inputs from Antigravity over `stdin`)*.

---

**That's it! Once Antigravity restarts or you reload the MCP configurations, it will spin up the `mcp-stdio.js` script in the background and establish a direct connection to your Unity tools.**
4 changes: 3 additions & 1 deletion Server~/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
"private": true,
"type": "commonjs",
"scripts": {
"start": "node src/server.js"
"start": "node src/server.js",
"mcp": "node src/mcp-stdio.js"
},
"engines": {
"node": ">=18"
},
"dependencies": {
"@modelcontextprotocol/sdk": "^1.27.1",
"dotenv": "^17.2.3"
}
}
Loading