whats-mcp 0.1.0

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/.dockerignore ADDED
@@ -0,0 +1,12 @@
1
+ .agent/
2
+ AGENTS.md
3
+ CLAUDE.md
4
+ GEMINI.md
5
+ COPILOT.md
6
+ VIBE.md
7
+ .git/
8
+ node_modules/
9
+ coverage/
10
+ .env
11
+ deploy/.env
12
+ auth/
package/.gitlab-ci.yml ADDED
@@ -0,0 +1,54 @@
1
+ stages:
2
+ - validate
3
+ - deploy
4
+
5
+ validate_project:
6
+ stage: validate
7
+ image: node:22-bookworm-slim
8
+ script:
9
+ - npm ci
10
+ - npm test -- --runInBand
11
+ - node -e "const { loadConfig } = require('./src/config'); const cfg = loadConfig(); if (cfg.server.name !== 'whats-mcp') throw new Error('Unexpected package metadata wiring'); console.log('whats-mcp config smoke test OK');"
12
+
13
+ deploy_homelab:
14
+ stage: deploy
15
+ tags:
16
+ - homelab
17
+ variables:
18
+ GIT_CLEAN_FLAGS: none
19
+ only:
20
+ - main
21
+ needs:
22
+ - validate_project
23
+ script:
24
+ - echo "🚀 Deploying whats-mcp to the homelab..."
25
+ - cd deploy
26
+ - echo "WHATSAPP_STATE_DIR=/data/state" > .env
27
+ - echo "WHATSAPP_LOG_LEVEL=error" >> .env
28
+ - echo "WHATSAPP_PRINT_QR=false" >> .env
29
+ - echo "WHATS_MCP_HTTP_HOST=0.0.0.0" >> .env
30
+ - echo "WHATS_MCP_HTTP_PORT=8092" >> .env
31
+ - echo "WHATS_MCP_HTTP_MCP_PATH=/mcp" >> .env
32
+ - echo "WHATS_MCP_ADMIN_ENV_FILE=/data/whats-admin.env" >> .env
33
+ - echo "WHATS_MCP_PUBLIC_BASE_URL=https://whats.kpihx-labs.com" >> .env
34
+ - echo "WHATS_MCP_FALLBACK_BASE_URL=https://whats.homelab" >> .env
35
+ - echo "TELEGRAM_WHATS_HOMELAB_TOKEN=$TELEGRAM_WHATS_HOMELAB_TOKEN" >> .env
36
+ - echo "TELEGRAM_CHAT_IDS=$TELEGRAM_CHAT_IDS" >> .env
37
+ - docker compose -p whats-mcp config -q
38
+ - docker rm -f whats-mcp || true
39
+ - docker compose -p whats-mcp up -d --build --remove-orphans
40
+ - |
41
+ for attempt in $(seq 1 20); do
42
+ status="$(docker inspect --format '{{if .State.Health}}{{.State.Health.Status}}{{else}}starting{{end}}' whats-mcp 2>/dev/null || true)"
43
+ if [ "$status" = "healthy" ]; then
44
+ break
45
+ fi
46
+ if [ "$status" = "unhealthy" ]; then
47
+ docker logs --tail 200 whats-mcp
48
+ exit 1
49
+ fi
50
+ sleep 3
51
+ done
52
+ - docker inspect --format '{{.State.Health.Status}}' whats-mcp | grep -qx healthy
53
+ - docker exec whats-mcp node -e "fetch('http://127.0.0.1:8092/health').then((r) => { if (!r.ok) process.exit(1); }).catch(() => process.exit(1))"
54
+ - docker image prune -f
package/CHANGELOG.md ADDED
@@ -0,0 +1,38 @@
1
+ # Changelog
2
+
3
+ All notable changes to **whats-mcp** will be documented in this file.
4
+
5
+ ## [Unreleased]
6
+
7
+ ### Changed
8
+
9
+ - **Project rename finalized** — the public package and operator surface now consistently use `whats-mcp` / `whats-admin`.
10
+ - **Package metadata normalized** — server name and version now come from `package.json` instead of being duplicated in `config.json`.
11
+ - **Runtime artifact naming cleaned** — pid/log filenames now use the final `whats-mcp.*` naming.
12
+
13
+ ### Added
14
+
15
+ - **Shared MCP server builder** — `src/server.js` now centralizes stdio and HTTP server construction.
16
+ - **Dual transport entrypoint** — `src/main.js` now supports both `serve` and `serve-http`.
17
+ - **HTTP operator surface** — `src/http_app.js` now exposes `/health`, `/admin/status`, `/admin/help`, and streamable MCP over `/mcp`.
18
+ - **Shared admin helpers** — `src/admin/service.js` now centralizes status/help/log summaries for CLI, HTTP, and Telegram.
19
+ - **Telegram admin bridge** — `src/admin/telegram.js` adds the first homelab operator bridge for `/start`, `/help`, `/status`, `/health`, `/urls`, `/logs`, and `/restart`.
20
+ - **Deployment bundle** — `.dockerignore`, `Dockerfile`, `deploy/docker-compose.yml`, `deploy/docker-compose.override.example.yml`, `src/.env.example`, and `.gitlab-ci.yml`.
21
+ - **HTTP admin tests** — `tests/http_app.test.js` validates the new handler surface.
22
+ - **Admin logging parity** — shared admin logging now records Telegram commands, replies, and errors into the common admin log file.
23
+ - **Package-internal env loading** — `src/.env` is loaded automatically before runtime environment overrides.
24
+ - **Deploy health probes fixed** — Docker Compose and GitLab now use Node-native fetch probes instead of assuming `curl` exists inside the image.
25
+ - **Container operator binaries exposed** — the image now installs `whats-mcp` and `whats-admin` on `PATH` so `docker exec ... whats-admin ...` works directly.
26
+ - **Admin reconnect path clarified** — CLI and Telegram now expose a `reconnect` operator action, and pairing code login accepts phone formats like `+33605957785`.
27
+ - **Remote pairing flow added** — HTTP and Telegram admin now expose first-connection / re-pair actions through `POST /admin/pair-code` and `/pair_code <phone>`, backed by the shared `whats-admin login --code --phone ... --force` flow.
28
+ - **Compose project isolation** — whats-mcp deploys now pin the Compose project name to `whats-mcp`, preventing sibling MCP stacks deployed from other `deploy/` directories from being treated as orphans and removed.
29
+ - **Reconnect semantics fixed** — `/reconnect`, `POST /admin/reconnect`, and `whats-admin server reconnect` now trigger a live WhatsApp socket reconnect instead of restarting the container, preventing Telegram command replay loops caused by poll offset resets. `/restart` remains the explicit full-process restart path.
30
+ - **Deploy migration hardened** — the homelab deploy now reuses the existing `deploy_whats_mcp_data` volume and removes any stale `whats-mcp` container before `docker compose up`, preserving the paired WhatsApp session while migrating to the isolated Compose project name.
31
+
32
+ ## [0.1.0]
33
+
34
+ ### Added
35
+
36
+ - Initial WhatsApp MCP server based on Baileys
37
+ - Persistent local store and analytics
38
+ - Tool catalog covering messaging, chats, contacts, groups, profile, channels, labels, utilities, and intent-first overview flows
package/README.md ADDED
@@ -0,0 +1,205 @@
1
+ # whats-mcp
2
+
3
+ Comprehensive **WhatsApp MCP server** powered by Baileys, with intent-first read surfaces and dual transport support:
4
+
5
+ - local `stdio` for direct MCP clients
6
+ - remote `streamable-http` for homelab deployment
7
+ - operator surfaces over CLI, HTTP, and Telegram
8
+
9
+ ## Features
10
+
11
+ - **64 MCP tools** for messaging, chats, contacts, groups, profile, channels, labels, analytics, watchlists, and intent-first overview flows
12
+ - **Intent-first tools** already built into the surface:
13
+ - `whatsup`
14
+ - `find_messages`
15
+ - `daily_digest`
16
+ - `manage_watchlist`
17
+ - **Persistent auth + local analytics store**
18
+ - **Dual transport**:
19
+ - `whats-mcp serve`
20
+ - `whats-mcp serve-http`
21
+ - **Operator surfaces**:
22
+ - `whats-admin`
23
+ - `/health`
24
+ - `/admin/status`
25
+ - `/admin/help`
26
+ - `POST /admin/reconnect`
27
+ - `POST /admin/pair-code`
28
+ - Telegram admin bridge when configured
29
+
30
+ ## Package Layout
31
+
32
+ ```text
33
+ src/
34
+ ├── admin/
35
+ │ ├── service.js # shared operator summaries and runtime status helpers
36
+ │ └── telegram.js # Telegram command bridge
37
+ ├── tools/ # MCP tool catalog
38
+ ├── connection.js # Baileys lifecycle and reconnect logic
39
+ ├── config.js # config.json + env overrides + package metadata
40
+ ├── helpers.js # shared WhatsApp helper functions
41
+ ├── http_app.js # HTTP transport + /health + /admin/*
42
+ ├── main.js # transport entrypoint (stdio + HTTP)
43
+ ├── server.js # shared MCP server construction
44
+ └── store.js # local cache, analytics index, watchlists
45
+ ```
46
+
47
+ ## Installation
48
+
49
+ ```bash
50
+ npm install
51
+ ```
52
+
53
+ Commands exposed:
54
+
55
+ ```bash
56
+ whats-mcp
57
+ whats-admin
58
+ ```
59
+
60
+ ## Local Usage
61
+
62
+ ### Stdio MCP
63
+
64
+ ```bash
65
+ whats-mcp serve
66
+ ```
67
+
68
+ ### HTTP MCP
69
+
70
+ ```bash
71
+ whats-mcp serve-http
72
+ ```
73
+
74
+ Default HTTP surface:
75
+
76
+ - MCP: `/mcp`
77
+ - Health: `/health`
78
+ - Admin status: `/admin/status`
79
+ - Admin help: `/admin/help`
80
+ - Admin reconnect: `POST /admin/reconnect`
81
+ - Admin pair-code: `POST /admin/pair-code`
82
+
83
+ Default URLs:
84
+
85
+ - Primary: `https://whats.kpihx-labs.com`
86
+ - Fallback: `https://whats.homelab`
87
+
88
+ ## Configuration
89
+
90
+ The project uses:
91
+
92
+ - `config.json` for non-sensitive runtime settings
93
+ - `src/.env.example` for deploy/runtime environment variables
94
+
95
+ Relevant environment variables:
96
+
97
+ | Variable | Purpose |
98
+ |---|---|
99
+ | `WHATSAPP_STATE_DIR` | Persistent Baileys auth + local store path |
100
+ | `WHATSAPP_LOG_LEVEL` | Runtime log level |
101
+ | `WHATS_MCP_HTTP_HOST` | HTTP bind host |
102
+ | `WHATS_MCP_HTTP_PORT` | HTTP bind port |
103
+ | `WHATS_MCP_HTTP_MCP_PATH` | MCP HTTP path |
104
+ | `WHATS_MCP_PUBLIC_BASE_URL` | Primary trusted route |
105
+ | `WHATS_MCP_FALLBACK_BASE_URL` | Fallback route |
106
+ | `TELEGRAM_WHATS_HOMELAB_TOKEN` | Optional Telegram admin bot token |
107
+ | `TELEGRAM_CHAT_IDS` | Optional comma-separated Telegram admin allowlist |
108
+
109
+ ## CLI Admin
110
+
111
+ Shared operator summary:
112
+
113
+ ```bash
114
+ whats-admin guide
115
+ ```
116
+
117
+ Main commands:
118
+
119
+ ```text
120
+ whats-admin status
121
+ whats-admin guide
122
+ whats-admin login [--code] [--phone N] [--force]
123
+ whats-admin logout [-f]
124
+ whats-admin server status|stop|restart|reconnect|pid|test
125
+ whats-admin config show|edit|reset|path
126
+ whats-admin logs show|tail|clean|path
127
+ ```
128
+
129
+ Container usage:
130
+
131
+ ```bash
132
+ docker exec -it whats-mcp whats-admin status
133
+ docker exec -it whats-mcp whats-admin login
134
+ docker exec -it whats-mcp whats-admin login --code --phone +33605957785
135
+ curl -fsS -X POST https://whats.kpihx-labs.com/admin/pair-code -H 'content-type: application/json' -d '{"phone":"33605957785"}'
136
+ curl -fsS -X POST https://whats.kpihx-labs.com/admin/reconnect
137
+ docker exec -it whats-mcp whats-admin server reconnect
138
+ ```
139
+
140
+ Reconnect semantics:
141
+
142
+ - `reconnect` performs an in-process WhatsApp socket reconnect and keeps the HTTP server plus Telegram poller alive.
143
+ - `restart` restarts the container process and should be reserved for full service restarts, not routine session refreshes.
144
+
145
+ ## Telegram Admin
146
+
147
+ When both variables are configured:
148
+
149
+ - `TELEGRAM_WHATS_HOMELAB_TOKEN`
150
+ - `TELEGRAM_CHAT_IDS`
151
+
152
+ the HTTP service auto-starts a Telegram admin poller.
153
+
154
+ Current commands:
155
+
156
+ ```text
157
+ /start
158
+ /help
159
+ /status
160
+ /health
161
+ /urls
162
+ /logs [lines]
163
+ /pair_code <phone>
164
+ /reconnect
165
+ /restart
166
+ ```
167
+
168
+ ## Docker / Homelab Deployment
169
+
170
+ Deployment bundle:
171
+
172
+ - `Dockerfile`
173
+ - `deploy/docker-compose.yml`
174
+ - `deploy/docker-compose.override.example.yml`
175
+ - `.dockerignore`
176
+ - `.gitlab-ci.yml`
177
+ - `src/.env.example`
178
+
179
+ Typical local dry-run:
180
+
181
+ ```bash
182
+ cd deploy
183
+ cp ../src/.env.example .env
184
+ docker compose config -q
185
+ docker compose up --build
186
+ ```
187
+
188
+ The deployment stores persistent WhatsApp state under `/data/state` inside the container volume, so redeploys do not wipe the linked session.
189
+
190
+ ## Validation
191
+
192
+ Current baseline:
193
+
194
+ ```bash
195
+ npm test -- --runInBand
196
+ ```
197
+
198
+ This validates:
199
+
200
+ - config loading
201
+ - helpers
202
+ - store behavior
203
+ - tool registry and handlers
204
+ - HTTP admin handler surface
205
+ - Telegram admin dispatch and runtime status
package/TODO.md ADDED
@@ -0,0 +1,6 @@
1
+ # TODO
2
+
3
+ - [ ] Split the current large Node modules into smaller domains where it materially improves maintainability without harming testability.
4
+ - [ ] Add integration tests for `serve-http` end-to-end MCP initialize / tools/list / tools/call flows.
5
+ - [ ] Add deployment smoke checks for the containerized HTTP transport on the homelab.
6
+ - [ ] Open the GitHub and GitLab remotes for this new repository once the migration is stable.
package/config.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "server": {
3
+ "state_directory": "~/.mcps/whatsapp"
4
+ },
5
+ "connection": {
6
+ "print_qr_in_terminal": true,
7
+ "reconnect_interval_ms": 3000,
8
+ "max_reconnect_attempts": 10,
9
+ "mark_online_on_connect": false
10
+ },
11
+ "store": {
12
+ "max_messages_per_chat": 5000,
13
+ "max_chats": 1000
14
+ },
15
+ "logging": {
16
+ "level": "error"
17
+ },
18
+ "watchlists": {}
19
+ }
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "whats-mcp",
3
+ "version": "0.1.0",
4
+ "description": "MCP server for WhatsApp — intent-first messaging, chat management, analytics, and operator surfaces over stdio and HTTP.",
5
+ "main": "src/main.js",
6
+ "bin": {
7
+ "whats-mcp": "src/main.js",
8
+ "whats-admin": "src/admin.js"
9
+ },
10
+ "scripts": {
11
+ "start": "node src/main.js serve",
12
+ "serve:http": "node src/main.js serve-http",
13
+ "admin": "node src/admin.js",
14
+ "login": "node src/admin.js login",
15
+ "login:code": "node src/admin.js login --code",
16
+ "test": "node --experimental-vm-modules node_modules/.bin/jest --coverage",
17
+ "test:watch": "node --experimental-vm-modules node_modules/.bin/jest --watch",
18
+ "stop": "node src/admin.js server stop",
19
+ "status": "node src/admin.js status"
20
+ },
21
+ "keywords": [
22
+ "whatsapp",
23
+ "mcp",
24
+ "model-context-protocol",
25
+ "baileys",
26
+ "messaging",
27
+ "automation"
28
+ ],
29
+ "author": "Ivann KAMDEM <kapoivha@gmail.com>",
30
+ "license": "MIT",
31
+ "type": "commonjs",
32
+ "engines": {
33
+ "node": ">=18.0.0"
34
+ },
35
+ "dependencies": {
36
+ "@modelcontextprotocol/sdk": "^1.26.0",
37
+ "@whiskeysockets/baileys": "^7.0.0-rc.9",
38
+ "commander": "^13.1.0",
39
+ "express": "^5.2.1",
40
+ "pino": "^10.3.1",
41
+ "qrcode-terminal": "^0.12.0"
42
+ },
43
+ "devDependencies": {
44
+ "jest": "^29.0.0"
45
+ }
46
+ }
@@ -0,0 +1,21 @@
1
+ # HTTP transport
2
+ WHATS_MCP_HTTP_HOST=0.0.0.0
3
+ WHATS_MCP_HTTP_PORT=8092
4
+ WHATS_MCP_HTTP_MCP_PATH=/mcp
5
+ WHATS_MCP_PUBLIC_BASE_URL=https://whats.kpihx-labs.com
6
+ WHATS_MCP_FALLBACK_BASE_URL=https://whats.homelab
7
+ WHATS_MCP_ADMIN_ENV_FILE=/data/whats-admin.env
8
+
9
+ # WhatsApp runtime
10
+ WHATSAPP_STATE_DIR=/data/state
11
+ WHATSAPP_LOG_LEVEL=error
12
+ WHATSAPP_MAX_RECONNECT=10
13
+ WHATSAPP_PRINT_QR=false
14
+ WHATSAPP_SYNC_FULL_HISTORY=true
15
+ WHATSAPP_REFRESH_APP_STATE=true
16
+ WHATSAPP_PERSIST_STORE=true
17
+ WHATSAPP_MAX_MESSAGES_PER_CHAT=5000
18
+
19
+ # Optional Telegram admin bridge
20
+ TELEGRAM_WHATS_HOMELAB_TOKEN=
21
+ TELEGRAM_CHAT_IDS=