replywizard-whatsapp-mcp 0.2.1 → 0.2.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/connector.js +1 -0
- package/src/daemon.js +26 -2
- package/src/protocol.js +1 -0
- package/src/wsServer.js +17 -0
package/package.json
CHANGED
package/src/connector.js
CHANGED
package/src/daemon.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
1
2
|
// daemon.js — long-lived multi-client MCP daemon (Option A, WS-A1).
|
|
2
3
|
//
|
|
3
4
|
// The original index.js binds ONE stdio client and ONE extension WebSocket per
|
|
@@ -89,7 +90,26 @@ export function createDaemon({
|
|
|
89
90
|
return [`127.0.0.1:${port}`, `localhost:${port}`];
|
|
90
91
|
};
|
|
91
92
|
|
|
93
|
+
// Relay the distinct names of currently-connected MCP clients to the extension,
|
|
94
|
+
// so the options page can show which AI assistants are attached. Names come from
|
|
95
|
+
// each client's `initialize` clientInfo (the stdio connector pumps frames raw, so
|
|
96
|
+
// the real client's name — "Antigravity", "Cursor", … — reaches us verbatim).
|
|
97
|
+
function publishClients() {
|
|
98
|
+
if (!bridge || typeof bridge.setConnectedClients !== 'function') return;
|
|
99
|
+
const seen = new Set();
|
|
100
|
+
const clients = [];
|
|
101
|
+
for (const s of sessions.values()) {
|
|
102
|
+
const name = (s.clientInfo && s.clientInfo.name) || 'Unknown assistant';
|
|
103
|
+
if (seen.has(name)) continue;
|
|
104
|
+
seen.add(name);
|
|
105
|
+
clients.push({ name, version: (s.clientInfo && s.clientInfo.version) || null });
|
|
106
|
+
}
|
|
107
|
+
bridge.setConnectedClients(clients);
|
|
108
|
+
}
|
|
109
|
+
|
|
92
110
|
async function newSession(req, res, body) {
|
|
111
|
+
// The client's name/version live in the initialize request's clientInfo.
|
|
112
|
+
const clientInfo = (body && body.params && body.params.clientInfo) || null;
|
|
93
113
|
// Capture the session id at init: transport.sessionId may already be cleared by
|
|
94
114
|
// the time onclose fires, so we must not rely on it for cleanup.
|
|
95
115
|
let sid = null;
|
|
@@ -97,9 +117,13 @@ export function createDaemon({
|
|
|
97
117
|
sessionIdGenerator: () => randomUUID(),
|
|
98
118
|
enableDnsRebindingProtection: true,
|
|
99
119
|
allowedHosts: allowedHosts(),
|
|
100
|
-
onsessioninitialized: (id) => {
|
|
120
|
+
onsessioninitialized: (id) => {
|
|
121
|
+
sid = id;
|
|
122
|
+
sessions.set(id, { transport, server, lastSeen: now(), clientInfo });
|
|
123
|
+
publishClients();
|
|
124
|
+
},
|
|
101
125
|
});
|
|
102
|
-
transport.onclose = () => { if (sid
|
|
126
|
+
transport.onclose = () => { if (sid && sessions.delete(sid)) publishClients(); };
|
|
103
127
|
const server = createMcpServer(bridge);
|
|
104
128
|
await server.connect(transport);
|
|
105
129
|
await transport.handleRequest(req, res, body);
|
package/src/protocol.js
CHANGED
package/src/wsServer.js
CHANGED
|
@@ -113,6 +113,9 @@ export class ExtensionBridge {
|
|
|
113
113
|
this.portConflict = false; // true if the port was already in use at startup
|
|
114
114
|
// Desktop-notification fn for the pairing code (injectable for tests).
|
|
115
115
|
this._notify = opts.notify ?? notifyPairingCode;
|
|
116
|
+
// Connected MCP clients (by name), set by the daemon and relayed to the
|
|
117
|
+
// extension so the options page can show which AI assistants are attached.
|
|
118
|
+
this.connectedClients = [];
|
|
116
119
|
// Concurrency scheduler (WS-A3): all client sessions multiplex onto the single
|
|
117
120
|
// extension socket. Reads and value-actions run in INDEPENDENT lanes so a slow
|
|
118
121
|
// value-action (transcribe/summarize/suggest → LLM/STT) never head-of-line-blocks
|
|
@@ -192,6 +195,7 @@ export class ExtensionBridge {
|
|
|
192
195
|
if (token && this.sessionToken && token === this.sessionToken) {
|
|
193
196
|
this.paired = true;
|
|
194
197
|
this._send({ method: CONTROL.AUTH_SUCCESS, params: { protocol: PROTOCOL_VERSION } });
|
|
198
|
+
this._sendClients(); // sync current assistants to a freshly reconnected extension
|
|
195
199
|
log('Reconnected with a valid session token (no pairing needed).');
|
|
196
200
|
} else {
|
|
197
201
|
this.pairingCode = sixDigitCode();
|
|
@@ -218,6 +222,7 @@ export class ExtensionBridge {
|
|
|
218
222
|
clearPairingCode();
|
|
219
223
|
this._send({ method: CONTROL.PAIRING_COMPLETE, params: { session_id: randomUUID(), session_token: this.sessionToken } });
|
|
220
224
|
this._send({ method: CONTROL.AUTH_SUCCESS, params: {} });
|
|
225
|
+
this._sendClients(); // sync current assistants right after pairing
|
|
221
226
|
log('Pairing approved.');
|
|
222
227
|
} else {
|
|
223
228
|
// Tell the extension so it can show "incorrect code" instead of just
|
|
@@ -328,6 +333,18 @@ export class ExtensionBridge {
|
|
|
328
333
|
if (this.socket && this.socket.readyState === this.socket.OPEN) this.socket.send(JSON.stringify(obj));
|
|
329
334
|
}
|
|
330
335
|
|
|
336
|
+
// Set the list of connected MCP clients (called by the daemon on session
|
|
337
|
+
// open/close) and relay it to the extension. Idempotent and safe to call when
|
|
338
|
+
// no extension is connected (the _send is a no-op then; re-sent on next auth).
|
|
339
|
+
setConnectedClients(clients) {
|
|
340
|
+
this.connectedClients = Array.isArray(clients) ? clients : [];
|
|
341
|
+
this._sendClients();
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
_sendClients() {
|
|
345
|
+
this._send({ method: CONTROL.CLIENTS_UPDATE, params: { clients: this.connectedClients } });
|
|
346
|
+
}
|
|
347
|
+
|
|
331
348
|
// Reject every queued and in-flight action (e.g. on disconnect / shutdown).
|
|
332
349
|
_failAll(err) {
|
|
333
350
|
for (const lane of Object.values(this.lanes)) {
|