aipex-mcp-bridge 1.0.2 → 1.0.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.
Files changed (2) hide show
  1. package/dist/bridge.js +38 -8
  2. package/package.json +1 -1
package/dist/bridge.js CHANGED
@@ -51,6 +51,30 @@ var cachedToolsTimestamp = 0;
51
51
  var pingInterval = null;
52
52
  var lastConnectionTime = null;
53
53
  var lastDisconnectReason = null;
54
+ var connectionWaiters = [];
55
+ var WAIT_FOR_CONNECTION_MS = 15e3;
56
+ function waitForConnection() {
57
+ return new Promise((resolve, reject) => {
58
+ if (aipexReady && aipexSocket?.readyState === WebSocket.OPEN) {
59
+ resolve();
60
+ return;
61
+ }
62
+ const timer = setTimeout(() => {
63
+ const idx = connectionWaiters.indexOf(wrapped);
64
+ if (idx !== -1) connectionWaiters.splice(idx, 1);
65
+ reject(new Error("Timed out waiting for AIPex to connect"));
66
+ }, WAIT_FOR_CONNECTION_MS);
67
+ const wrapped = () => {
68
+ clearTimeout(timer);
69
+ resolve();
70
+ };
71
+ connectionWaiters.push(wrapped);
72
+ });
73
+ }
74
+ function notifyConnectionWaiters() {
75
+ const waiters = connectionWaiters.splice(0);
76
+ for (const w of waiters) w();
77
+ }
54
78
  var nextAipexId = 1;
55
79
  var aipexPending = /* @__PURE__ */ new Map();
56
80
  function respond(id, result) {
@@ -137,6 +161,7 @@ async function doAipexHandshake(socket) {
137
161
  aipexReady = true;
138
162
  lastConnectionTime = Date.now();
139
163
  log(`Handshake complete. ${cachedTools.length} tools available.`);
164
+ notifyConnectionWaiters();
140
165
  }
141
166
  async function doAipexHandshakeWithRetry(socket) {
142
167
  for (let attempt = 1; attempt <= HANDSHAKE_RETRY_COUNT; attempt++) {
@@ -239,14 +264,19 @@ async function handleAgentRequest(req) {
239
264
  }
240
265
  if (method === "tools/call") {
241
266
  if (!aipexReady || !aipexSocket || aipexSocket.readyState !== WebSocket.OPEN) {
242
- const ctx = lastConnectionTime ? ` Last connected: ${new Date(lastConnectionTime).toISOString()}.` : "";
243
- const reason = lastDisconnectReason ? ` Disconnect reason: ${lastDisconnectReason}.` : "";
244
- respondError(
245
- id,
246
- -32e3,
247
- `AIPex extension not connected.${ctx}${reason} Open AIPex Options and connect to ws://localhost:${WS_PORT}`
248
- );
249
- return;
267
+ log(`AIPex not ready, waiting up to ${WAIT_FOR_CONNECTION_MS / 1e3}s for reconnect...`);
268
+ try {
269
+ await waitForConnection();
270
+ } catch {
271
+ const ctx = lastConnectionTime ? ` Last connected: ${new Date(lastConnectionTime).toISOString()}.` : "";
272
+ const reason = lastDisconnectReason ? ` Disconnect reason: ${lastDisconnectReason}.` : "";
273
+ respondError(
274
+ id,
275
+ -32e3,
276
+ `AIPex extension not connected.${ctx}${reason} Open AIPex Options and connect to ws://localhost:${WS_PORT}`
277
+ );
278
+ return;
279
+ }
250
280
  }
251
281
  try {
252
282
  const result = await sendToAipex(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aipex-mcp-bridge",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "MCP bridge that connects AI agents (Cursor, Claude, VS Code Copilot, etc.) to the AIPex browser extension via WebSocket",
5
5
  "type": "module",
6
6
  "bin": {