replywizard-whatsapp-mcp 0.3.2 → 0.3.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "replywizard-whatsapp-mcp",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "description": "Local MCP server and command line that expose WhatsApp Web (read + value tools) to AI clients via the Reply Wizard Chrome extension.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/connector.js CHANGED
@@ -24,16 +24,88 @@ const HOST = '127.0.0.1';
24
24
  const log = (...args) => console.error('[replywizard-mcp:connector]', ...args);
25
25
  const delay = (ms) => new Promise((r) => setTimeout(r, ms));
26
26
 
27
+ /**
28
+ * JSON-RPC error handed back when a request cannot reach the daemon, or when the daemon goes
29
+ * away while the request is in flight. -32000 is the "implementation-defined server error"
30
+ * range, which is what this is: the protocol was fine and the hop underneath it was not.
31
+ */
32
+ const DAEMON_GONE = -32000;
33
+ const DAEMON_GONE_TEXT =
34
+ 'The Reply Wizard MCP daemon is not reachable. It may have been stopped, or the machine '
35
+ + 'may have slept. Run `replywizard status` to restart it, then try again.';
36
+
37
+ /** A JSON-RPC REQUEST is the only frame anybody is waiting on: it has BOTH an id and a method. */
38
+ function isRequest(msg) {
39
+ return !!msg && typeof msg === 'object' && msg.method !== undefined
40
+ && msg.id !== undefined && msg.id !== null;
41
+ }
42
+
27
43
  /**
28
44
  * Wire two MCP transports so every message on one is forwarded to the other, in both
29
45
  * directions, and a close/error on either tears down the pair. Pure plumbing: no
30
- * protocol knowledge. Returns nothing; assign the transports' lifecycle to the caller.
46
+ * protocol knowledge beyond "which frames is somebody waiting for an answer to".
47
+ *
48
+ * WHY THIS IS NOT A BARE RELAY, AND THE MEASUREMENT BEHIND IT (2026-09-21)
49
+ * It used to be one: a failed forward was `.catch((e) => log(...))`, logged to stderr and
50
+ * swallowed. **stderr is not shown to anyone.** An MCP client that had sent `tools/call` and
51
+ * whose request could not be forwarded therefore waited FOR EVER, because a JSON-RPC client
52
+ * has nothing to wait on but the matching id.
53
+ *
54
+ * That is not theoretical. The owner hit it on 2026-09-21 and reported it as "you were
55
+ * working for an unusually long time on a single tool call", and the only way out was to
56
+ * interrupt. Reproduced deterministically: connect a client, prove a call works, `kill -9`
57
+ * the daemon, send the same call again -- the connector printed `→daemon send failed: fetch
58
+ * failed` and the client received nothing in 30 seconds and would have received nothing ever.
59
+ *
60
+ * A daemon that dies is ordinary. It is a detached background process, so it goes with a
61
+ * crash, a laptop sleeping, an OOM kill, `pkill node`, or a machine restart, and the client
62
+ * that started it has no idea. **The failure is unavoidable; being silent about it is not.**
63
+ *
64
+ * So every frame anybody is waiting on gets an answer, one way or the other:
65
+ * - a request that cannot be FORWARDED is answered immediately with an error, and
66
+ * - a request already IN FLIGHT when the daemon drops is answered on the way down,
67
+ * which is why `pending` exists rather than only a catch.
68
+ * Notifications and responses are still relayed best-effort and still only logged: nothing
69
+ * is waiting on them, and inventing an error for a notification would corrupt the stream.
31
70
  */
32
71
  export function pumpTransports(clientFacing, daemonFacing) {
33
- clientFacing.onmessage = (msg) => { daemonFacing.send(msg).catch((e) => log('→daemon send failed:', e && e.message)); };
34
- daemonFacing.onmessage = (msg) => { clientFacing.send(msg).catch((e) => log('→client send failed:', e && e.message)); };
72
+ /** Request ids the client is waiting on. Settled by the daemon, or by us on the way down. */
73
+ const pending = new Set();
74
+
75
+ const failClient = (id, message) => {
76
+ pending.delete(id);
77
+ clientFacing.send({ jsonrpc: '2.0', id, error: { code: DAEMON_GONE, message } })
78
+ .catch((e) => log('could not report the failure to the client:', e && e.message));
79
+ };
80
+ /** Answer everything still outstanding. Called once, when the daemon side goes away. */
81
+ const failAllPending = () => {
82
+ if (!pending.size) return;
83
+ log(`daemon gone with ${pending.size} request(s) in flight; answering them with an error.`);
84
+ for (const id of [...pending]) failClient(id, DAEMON_GONE_TEXT);
85
+ };
86
+
87
+ clientFacing.onmessage = (msg) => {
88
+ const waiting = isRequest(msg);
89
+ if (waiting) pending.add(msg.id);
90
+ daemonFacing.send(msg).catch((e) => {
91
+ log('→daemon send failed:', e && e.message);
92
+ // The whole point: a request that never reached the daemon is answered here, because
93
+ // nothing downstream exists to answer it.
94
+ if (waiting) failClient(msg.id, DAEMON_GONE_TEXT);
95
+ });
96
+ };
97
+ daemonFacing.onmessage = (msg) => {
98
+ // Any frame carrying an id settles that id, whether it is a result or an error.
99
+ if (msg && typeof msg === 'object' && msg.id !== undefined && msg.id !== null) pending.delete(msg.id);
100
+ clientFacing.send(msg).catch((e) => log('→client send failed:', e && e.message));
101
+ };
35
102
  clientFacing.onclose = () => { daemonFacing.close().catch(() => {}); };
36
- daemonFacing.onclose = () => { clientFacing.close().catch(() => {}); };
103
+ daemonFacing.onclose = () => {
104
+ // Before the client transport goes, not after: once it is closed nothing can be sent on
105
+ // it, and the in-flight requests would be lost in exactly the silent way this fixes.
106
+ failAllPending();
107
+ clientFacing.close().catch(() => {});
108
+ };
37
109
  clientFacing.onerror = (e) => log('client transport error:', e && e.message);
38
110
  daemonFacing.onerror = (e) => log('daemon transport error:', e && e.message);
39
111
  }
package/src/tools.js CHANGED
@@ -22,7 +22,9 @@ export const TOOLS = [
22
22
  name: ACTIONS.LIST_CHATS,
23
23
  description:
24
24
  'List the user\'s WhatsApp chats, most recently active first. Returns id, name, ' +
25
- 'isGroup, unreadCount and timestamp for each. Use the returned `id` with get_messages.',
25
+ 'phone, isGroup, unreadCount and timestamp for each. Use the returned `id` with ' +
26
+ 'get_messages. `phone` is the dialable number in digits, or null: a group never has ' +
27
+ 'one, and a small number of one-to-one chats do not either, so it is never required.',
26
28
  inputSchema: {
27
29
  type: 'object',
28
30
  properties: {