@ohah/react-native-mcp-server 0.1.0-rc.5 → 0.1.0-rc.6

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/dist/index.js CHANGED
@@ -642,20 +642,25 @@ var AppSession = class {
642
642
  conn.ws.send(JSON.stringify(msg));
643
643
  });
644
644
  }
645
- /** 서버 종료 */
645
+ /** 서버 종료 — 클라이언트에 정상 close frame 전송 후 서버 닫기 */
646
646
  stop() {
647
647
  stopAllRecordings();
648
648
  if (this.staleCheckTimer) {
649
649
  clearInterval(this.staleCheckTimer);
650
650
  this.staleCheckTimer = null;
651
651
  }
652
+ for (const [ws] of this.deviceByWs) try {
653
+ ws.close(1e3, "server shutting down");
654
+ } catch {}
655
+ for (const ext of this.extensionClients) try {
656
+ ext.close(1e3, "server shutting down");
657
+ } catch {}
658
+ this.extensionClients.clear();
659
+ for (const [ws] of this.deviceByWs) this.removeConnection(ws);
652
660
  if (this.server) {
653
661
  this.server.close();
654
662
  this.server = null;
655
663
  }
656
- for (const ext of this.extensionClients) ext.close();
657
- this.extensionClients.clear();
658
- for (const [ws] of this.deviceByWs) this.removeConnection(ws);
659
664
  }
660
665
  };
661
666
  /** 싱글톤 앱 세션 (index에서 생성 후 tools에 전달) */
@@ -4897,6 +4902,12 @@ async function main() {
4897
4902
  const transport = new StdioServerTransport();
4898
4903
  await server.connect(transport);
4899
4904
  console.error("[react-native-mcp-server] Running on stdio");
4905
+ const gracefulStop = () => {
4906
+ appSession.stop();
4907
+ setTimeout(() => process.exit(0), 200);
4908
+ };
4909
+ process.once("SIGINT", gracefulStop);
4910
+ process.once("SIGTERM", gracefulStop);
4900
4911
  }
4901
4912
  const subcommand = process.argv[2];
4902
4913
  if (subcommand === "test") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ohah/react-native-mcp-server",
3
- "version": "0.1.0-rc.5",
3
+ "version": "0.1.0-rc.6",
4
4
  "description": "MCP server for React Native app automation and monitoring",
5
5
  "keywords": [
6
6
  "automation",
package/runtime.js CHANGED
@@ -3168,12 +3168,10 @@
3168
3168
  function connect() {
3169
3169
  if (!_shouldConnect()) return;
3170
3170
  if (ws && (ws.readyState === 0 || ws.readyState === 1)) return;
3171
- if (ws) try {
3172
- ws.close();
3173
- } catch (_unused3) {}
3171
+ ws = null;
3174
3172
  try {
3175
3173
  ws = new WebSocket(wsUrl);
3176
- } catch (_unused4) {
3174
+ } catch (_unused3) {
3177
3175
  ws = null;
3178
3176
  _reconnectTimer = setTimeout(function() {
3179
3177
  connect();
@@ -3203,7 +3201,7 @@
3203
3201
  var scriptURL = _rn.NativeModules && _rn.NativeModules.SourceCode && _rn.NativeModules.SourceCode.scriptURL;
3204
3202
  if (scriptURL && typeof scriptURL === "string") try {
3205
3203
  origin = new URL(scriptURL).origin;
3206
- } catch (_unused5) {
3204
+ } catch (_unused4) {
3207
3205
  var _match$;
3208
3206
  var match = scriptURL.match(/^(https?:\/\/[^/?#]+)/);
3209
3207
  if (match) origin = (_match$ = match[1]) !== null && _match$ !== void 0 ? _match$ : null;
@@ -3256,7 +3254,7 @@
3256
3254
  id: msg.id,
3257
3255
  result: res
3258
3256
  }));
3259
- } catch (_unused6) {}
3257
+ } catch (_unused5) {}
3260
3258
  }
3261
3259
  if (errMsg != null) sendEvalResponse(null, errMsg);
3262
3260
  else if (result != null && typeof result.then === "function") result.then(function(r) {
@@ -3266,7 +3264,7 @@
3266
3264
  });
3267
3265
  else sendEvalResponse(result, null);
3268
3266
  }
3269
- } catch (_unused7) {}
3267
+ } catch (_unused6) {}
3270
3268
  };
3271
3269
  ws.onclose = function() {
3272
3270
  _stopHeartbeat();
@@ -3276,7 +3274,9 @@
3276
3274
  if (reconnectDelay < 3e4) reconnectDelay = Math.min(reconnectDelay * 1.5, 3e4);
3277
3275
  }, reconnectDelay);
3278
3276
  };
3279
- ws.onerror = function() {};
3277
+ ws.onerror = function() {
3278
+ _stopHeartbeat();
3279
+ };
3280
3280
  }
3281
3281
  var _isDevMode, wsUrl, ws, _reconnectTimer, reconnectDelay, _mcpEnabled, _heartbeatTimer, _pongTimer, HEARTBEAT_INTERVAL_MS, PONG_TIMEOUT_MS, _AppRegistry, _originalRun, PERIODIC_INTERVAL_MS;
3282
3282
  var init_connection = __esmMin(() => {
@@ -3317,7 +3317,7 @@
3317
3317
  if (ws && ws.readyState === 1) _startHeartbeat();
3318
3318
  } else _stopHeartbeat();
3319
3319
  });
3320
- } catch (_unused8) {}
3320
+ } catch (_unused7) {}
3321
3321
  })();
3322
3322
  PERIODIC_INTERVAL_MS = 5e3;
3323
3323
  setInterval(function() {