@akiojin/unity-mcp-server 2.42.2 → 2.42.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/core/unityConnection.js +19 -4
package/package.json
CHANGED
|
@@ -21,6 +21,7 @@ export class UnityConnection extends EventEmitter {
|
|
|
21
21
|
this.sendQueue = [];
|
|
22
22
|
this.inFlight = 0;
|
|
23
23
|
this.maxInFlight = 1; // process one command at a time by default
|
|
24
|
+
this.connectedAt = null; // Timestamp when connection was established
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
/**
|
|
@@ -77,8 +78,11 @@ export class UnityConnection extends EventEmitter {
|
|
|
77
78
|
|
|
78
79
|
// Set up event handlers
|
|
79
80
|
this.socket.on('connect', () => {
|
|
80
|
-
|
|
81
|
-
|
|
81
|
+
this.connectedAt = Date.now();
|
|
82
|
+
console.error(
|
|
83
|
+
`[unity-mcp-server] Unity TCP connected to ${targetHost}:${config.unity.port}`
|
|
84
|
+
);
|
|
85
|
+
logger.info(`Connected to Unity Editor at ${targetHost}:${config.unity.port}`);
|
|
82
86
|
this.connected = true;
|
|
83
87
|
this.reconnectAttempts = 0;
|
|
84
88
|
this.connectPromise = null;
|
|
@@ -88,6 +92,12 @@ export class UnityConnection extends EventEmitter {
|
|
|
88
92
|
});
|
|
89
93
|
|
|
90
94
|
this.socket.on('end', () => {
|
|
95
|
+
// Unity closed the connection (FIN received)
|
|
96
|
+
const duration = this.connectedAt ? Date.now() - this.connectedAt : 0;
|
|
97
|
+
console.error(
|
|
98
|
+
`[unity-mcp-server] Unity TCP connection ended by remote (FIN received, duration: ${duration}ms)`
|
|
99
|
+
);
|
|
100
|
+
logger.info(`Unity closed connection (FIN received) after ${duration}ms`);
|
|
91
101
|
// Treat end as close to trigger reconnection
|
|
92
102
|
this.socket.destroy();
|
|
93
103
|
});
|
|
@@ -130,9 +140,11 @@ export class UnityConnection extends EventEmitter {
|
|
|
130
140
|
return;
|
|
131
141
|
}
|
|
132
142
|
|
|
133
|
-
|
|
134
|
-
|
|
143
|
+
const duration = this.connectedAt ? Date.now() - this.connectedAt : 0;
|
|
144
|
+
console.error(`[unity-mcp-server] Unity TCP disconnected (duration: ${duration}ms)`);
|
|
145
|
+
logger.info(`Disconnected from Unity Editor after ${duration}ms`);
|
|
135
146
|
this.connected = false;
|
|
147
|
+
this.connectedAt = null;
|
|
136
148
|
this.socket = null;
|
|
137
149
|
|
|
138
150
|
// Clear message buffer
|
|
@@ -231,6 +243,9 @@ export class UnityConnection extends EventEmitter {
|
|
|
231
243
|
* @param {Buffer} data
|
|
232
244
|
*/
|
|
233
245
|
handleData(data) {
|
|
246
|
+
// Log received data size for debugging connection issues
|
|
247
|
+
console.error(`[unity-mcp-server] Received ${data.length} bytes from Unity`);
|
|
248
|
+
|
|
234
249
|
// Fast-path: accept single unframed JSON message (NDJSON style) from tests/clients
|
|
235
250
|
if (!this.messageBuffer.length) {
|
|
236
251
|
const asString = data.toString('utf8').trim();
|