kibbutz-mcp 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/build/index.js +32 -20
  2. package/package.json +1 -1
package/build/index.js CHANGED
@@ -9,14 +9,14 @@ import { spawn } from 'child_process';
9
9
  import fs from 'fs';
10
10
  import path from 'path';
11
11
  let mcpSocket = null;
12
- let socket = null;
12
+ let pingSocket = null;
13
13
  let token = null;
14
14
  let port = null;
15
15
  let wsPromise = null;
16
16
  const map = new Map();
17
17
  const server = new McpServer({
18
18
  name: 'kibbutz-mcp',
19
- version: '1.0.2',
19
+ version: '1.0.3',
20
20
  });
21
21
  function findChromeExecutable() {
22
22
  const platform = process.platform;
@@ -65,7 +65,7 @@ const sendAndWaitForReply = async (message, args) => {
65
65
  const timeout = setTimeout(() => {
66
66
  wsPromise = null;
67
67
  reject(new Error('Timeout waiting for MCP extension WebSocket connection'));
68
- }, 10000);
68
+ }, 2000);
69
69
  wsPromise = () => {
70
70
  clearTimeout(timeout);
71
71
  resolve();
@@ -75,19 +75,15 @@ const sendAndWaitForReply = async (message, args) => {
75
75
  }
76
76
  catch (error) { }
77
77
  }
78
- if (!mcpSocket || mcpSocket.readyState !== WebSocket.OPEN) {
78
+ if (!mcpSocket ||
79
+ !pingSocket ||
80
+ mcpSocket.readyState !== WebSocket.OPEN ||
81
+ pingSocket.readyState !== WebSocket.OPEN) {
79
82
  return Promise.resolve({
80
83
  content: [
81
84
  {
82
85
  type: 'text',
83
- text: `Connection failed: The MCP server cannot reach the Chrome extension.
84
-
85
- Please check the following:
86
- 1. Is the browser open?
87
- 2. Is the MCP switch inside the extension popup turned ON?
88
-
89
- If the issue persists, copy and paste this URL into your browser address bar:
90
- chrome-extension://bpfjmggaaiigpfahhmpmacfhlemnhhip/KIBBUTZ-MCP.html`,
86
+ text: `Connection failed: The MCP server cannot reach the Chrome extension. Open chrome-extension://bpfjmggaaiigpfahhmpmacfhlemnhhip/KIBBUTZ-MCP.html for troubleshooting.`,
91
87
  },
92
88
  ],
93
89
  isError: true,
@@ -242,11 +238,19 @@ async function main() {
242
238
  const wss = new WebSocketServer({ noServer: true });
243
239
  const wssMcp = new WebSocketServer({ noServer: true });
244
240
  wss.on('connection', (ws) => {
245
- socket = ws;
241
+ pingSocket = ws;
246
242
  ws.on('error', console.error);
247
243
  ws.on('close', () => {
248
- if (socket === ws) {
249
- socket = null;
244
+ if (pingSocket === ws) {
245
+ pingSocket = null;
246
+ if (mcpSocket) {
247
+ wssMcp.clients.forEach((ws) => ws.terminate());
248
+ mcpSocket = null;
249
+ }
250
+ for (const { reject } of map.values()) {
251
+ reject(new Error('Extension WebSocket closed'));
252
+ }
253
+ map.clear();
250
254
  }
251
255
  });
252
256
  });
@@ -277,24 +281,32 @@ async function main() {
277
281
  });
278
282
  });
279
283
  httpServer.on('upgrade', (request, socket, head) => {
280
- if (request.headers['sec-websocket-protocol'] !== token) {
281
- socket.write('HTTP/1.1 401 Unauthorized\r\n\r\n');
282
- socket.destroy();
283
- return;
284
- }
285
284
  const { pathname } = new URL(request.url || '', `wss:127.0.0.1:${port}`);
286
285
  if (pathname === '/ping') {
286
+ if (request.headers['sec-websocket-protocol'] !== token) {
287
+ socket.write('HTTP/1.1 401 Unauthorized\r\n\r\n');
288
+ socket.destroy();
289
+ return;
290
+ }
287
291
  wss.clients.forEach((ws) => ws.terminate());
288
292
  wss.handleUpgrade(request, socket, head, (ws) => {
289
293
  wss.emit('connection', ws, request);
290
294
  });
291
295
  }
292
296
  else if (pathname === '/mcp') {
297
+ if (pingSocket?.readyState !== WebSocket.OPEN) {
298
+ socket.write('HTTP/1.1 403 Forbidden\r\n\r\n');
299
+ socket.destroy();
300
+ return;
301
+ }
293
302
  wssMcp.clients.forEach((ws) => ws.terminate());
294
303
  wssMcp.handleUpgrade(request, socket, head, (ws) => {
295
304
  wssMcp.emit('connection', ws, request);
296
305
  });
297
306
  }
307
+ else {
308
+ socket.destroy();
309
+ }
298
310
  });
299
311
  httpServer.listen(0, () => {
300
312
  port = httpServer.address().port;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kibbutz-mcp",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "scripts": {