Skip to content

Commit ee52e4a

Browse files
author
ichimi abunai
committed
feat: add remote host configuration support for Unity WebSocket connection
Add configurable host property to McpUnity class with support for UNITY_HOST environment variable and Host configuration in Unity's McpUnitySettings.json. Maintains full backward compatibility with original Unity workflow while enabling remote Unity Editor connections across network.
1 parent f0d0bcf commit ee52e4a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Server~/src/unity/mcpUnity.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ interface UnityResponse {
3434
export class McpUnity {
3535
private logger: Logger;
3636
private port: number | null = null;
37+
private host: string = 'localhost';
3738
private ws: WebSocket | null = null;
3839
private pendingRequests: Map<string, PendingRequest> = new Map<string, PendingRequest>();
3940
private requestTimeout = 10000;
@@ -80,6 +81,10 @@ export class McpUnity {
8081
this.port = configPort ? parseInt(configPort, 10) : 8090;
8182
this.logger.info(`Using port: ${this.port} for Unity WebSocket connection`);
8283

84+
// Check environment variable first, then config file, then default to localhost
85+
const configHost = process.env.UNITY_HOST || config.Host;
86+
this.host = configHost || 'localhost';
87+
8388
// Initialize timeout from environment variable (in seconds; it is the same as Cline) or use default (10 seconds)
8489
const configTimeout = config.RequestTimeoutSeconds;
8590
this.requestTimeout = configTimeout ? parseInt(configTimeout, 10) * 1000 : 10000;
@@ -100,7 +105,7 @@ export class McpUnity {
100105
this.disconnect();
101106

102107
return new Promise<void>((resolve, reject) => {
103-
const wsUrl = `ws://localhost:${this.port}/McpUnity`;
108+
const wsUrl = `ws://${this.host}:${this.port}/McpUnity`;
104109
this.logger.debug(`Connecting to ${wsUrl}...`);
105110

106111
// Create connection options with headers for client identification

0 commit comments

Comments
 (0)