Documentation Index
Fetch the complete documentation index at: https://zapo.to/llms.txt
Use this file to discover all available pages before exploring further.
zapo ships two optional packages aimed purely at development and testing — neither is meant for production:
- MCP server (
@zapo-js/mcp-server) — expose a liveWaClientto an AI agent (Claude Code, Cursor) so it can connect, pair, send, and inspect state interactively. - Fake server (
@zapo-js/fake-server) — an in-process fake WhatsApp Web server that drives the realWaClientend-to-end, so you can test deterministically without touching WhatsApp’s servers.
MCP server
It exposes a liveWaClient instance and the zapo-js module namespace as MCP tools. An LLM agent can then drive end-to-end WhatsApp flows — connect, pair, send, query groups/newsletters, inspect events, walk SQL state — without you writing throwaway scripts.
Tool surface
| Tool | What it does |
|---|---|
call / inspect | Walk dotted paths against client (the WaClient) or lib (the zapo-js namespace, including proto.* and helpers like parsePhoneJid). call invokes functions; inspect lists members. |
events / events_clear | Bounded ring buffer of every WaClientEventMap event — filter by types / since / limit / drain. |
logs / logs_clear | Queryable buffer mirroring every runtime + lib log line (also stderr; JSONL to MCP_LOG_FILE if set). |
lifecycle | status / start / destroy for the client. |
restart | soft (drop the client + clear buffers) or process_exit (also exit so a supervisor respawns it). |
Install & register
tsx — no build step, and zapo-js resolves straight from src/:
Pairing gotcha
client.connect() blocks until pairing finishes, so always start it without awaiting, then poll the event buffer:
auth_qr string to the user, wait for auth_paired, then continue.
Key environment variables
| Var | Default | Purpose |
|---|---|---|
MCP_AUTH_PATH | <cwd>/.auth/state.sqlite | SQLite credential store path |
MCP_SESSION_ID | default_2 | sessionId passed to WaClient |
MCP_LOG_LEVEL | info | trace / debug / info / warn / error |
MCP_TRANSPORT | stdio | stdio or http |
MCP_HTTP_HOST / MCP_HTTP_PORT / MCP_HTTP_PATH | 127.0.0.1 / 3737 / /mcp | HTTP listener config |
MCP_EVENT_BUFFER_SIZE / MCP_LOG_BUFFER_SIZE | 1000 / 500 | In-memory ring sizes |
WaClient per process (multi-session needs multiple servers with distinct MCP_AUTH_PATH + MCP_SESSION_ID); no auto-reconnect (call connect again on connection: close); restart soft does not pick up code changes while process_exit + a supervisor does. Full reference: packages/mcp-server/README.md.
Fake server
@zapo-js/fake-server is an in-process fake WhatsApp Web server that drives the real zapo-js WaClient end-to-end — full Noise XX/IK handshake, QR pairing, Signal Protocol (X3DH + Double Ratchet), group SenderKey, media upload/download over self-signed HTTPS, and app-state sync — all without touching WhatsApp’s servers. It powers the library’s own cross-check test suite and benchmarks, and you can use it to test your integration deterministically.
Quick start
chatSocketUrls (point at the fake WebSocket), testHooks.noiseRootCa (trust the fake server’s certificate without bypassing verification — the full cert-chain check still runs), and proxy.mediaUpload / proxy.mediaDownload (route media to the fake HTTPS server).
What it simulates
FakeWaServer— the WebSocket listener, Noise handshake, an IQ router that answers every IQ the lib emits during normal operation (prekey upload/fetch, usync,media-conn, app-state sync, groups, privacy, profile, blocklist, …), plus state registries for peers and groups.FakePeer— a simulated contact with real Signal crypto:peer.sendConversation(text)/peer.sendGroupConversation(groupJid, text)push messages to the client, andpeer.expectMessage()captures and decrypts what the client sends.- Pairing —
server.runPairing(pipeline, { deviceJid }, materialFn)drives the full QR-pairing handshake; afterward the lib reconnects with the IK handshake (capture it viawaitForNextAuthenticatedPipeline()).
Standalone CLI
Run it as a standalone server for manual experiments:Benchmarking
The package ships a messaging profiler (send/recv × 1:1/group) used to track the library’s performance:ZAPO_BENCH_* env vars (ZAPO_BENCH_CONTACTS, ZAPO_BENCH_GROUP_MEMBERS, ZAPO_BENCH_MESSAGES, ZAPO_BENCH_SCENARIOS, …) and add --cpu / --heap / --separate-process for profiles. See packages/fake-server/README.md for the full flag reference.
The fake server is an in-process testing harness, not a runtime you deploy. Pair it with the memory store for fast, isolated tests that reset on every run.
