W Agent
A self-hosted WhatsApp bridge with an AI agent enabling searchable context, message drafting, and approval workflow via MCP protocol for Claude Desktop and other MCP clients.
README
W Agent
W Agent: your WhatsApp, with a brain.
A self-hosted bridge that gives an AI agent continuous, searchable context over your WhatsApp chats — and lets it reply for you, safely.
W Agent keeps your archive in your Postgres, stages every outbound draft for approval (unless you opt a chat into auto-send), and exposes the same context to Claude Desktop and other MCP clients. The WhatsApp transport is swappable: unofficial Baileys for personal companion use, or the official Meta Cloud API for business messaging.
Operational warning. The default bridge uses Baileys (unofficial multi-device protocol) and carries real account ban / restriction risk. Prefer a dedicated number. For business workloads, set
WHATSAPP_PROVIDER=meta. See docs/security.md and docs/providers.md.
<!-- Optional: drop a ~60s screen capture at docs/assets/demo.gif
-->
Features
- Provider-adapter WhatsApp bridge — Baileys (personal / multi-device) or Meta Cloud API
- Durable ingest — inbound messages → BullMQ → Postgres (contacts, chats, messages, media)
- History sync & backfill — Baileys history chunks and on-demand per-chat backfill
- Hybrid search — OpenAI embeddings + pgvector merged with Postgres full-text search
- Rolling chat summaries — cheap-model memory on a message cadence
- Engagement engine — allowlists, group @-mentions, opt-in/out, owner
/agentcommands - Safety stack — injection heuristics (+ optional LLM classifier), outbound chat lock, secret redaction
- Approval outbox — drafts notify the owner; approve in the dashboard (or per-chat auto-send)
- Send hygiene — quotas, quiet hours, typing delays, exponential WA rate-limit cooldown
- MCP server — stdio + HTTP/SSE tools, resources, and prompts
- Ops — watchdog,
/healthz, atomic auth persistence, chaos + red-team scripts
Architecture
flowchart TB
subgraph clients [Clients]
WA[WhatsApp]
Dash[Dashboard]
MCPC[MCP clients<br/>Claude / ChatGPT / custom]
end
subgraph bridge [Bridge]
Prov["WhatsAppProvider<br/>baileys | meta"]
end
subgraph queues [Queues - Redis / BullMQ]
IngestQ[ingest]
EmbedQ[embed]
SumQ[summary]
Outbox[outbox sender]
end
subgraph storage [Storage]
PG[(Postgres + pgvector)]
Auth[(Auth / media volumes)]
end
subgraph agent [Agent + safety]
Engage[Engagement]
Guard[Injection guard]
Loop[Agent loop + tools]
Draft[Draft + owner notify]
end
subgraph mcp [MCP]
Stdio[stdio]
HTTPMCP[HTTP + SSE]
end
WA <--> Prov
Prov -->|ProviderMessage| IngestQ
IngestQ --> PG
IngestQ --> EmbedQ
EmbedQ --> PG
IngestQ --> SumQ
SumQ --> PG
Prov --> Auth
PG --> Engage
Engage --> Guard
Guard --> Loop
Loop --> Draft
Draft --> PG
Dash --> PG
Dash -->|approve| Outbox
Outbox --> Prov
MCPC --> Stdio
MCPC --> HTTPMCP
Stdio --> PG
HTTPMCP --> PG
Stdio --> Draft
HTTPMCP --> Draft
Layer detail: docs/architecture.md. Provider trade-offs: docs/providers.md.
Quickstart
Requires Docker, Node.js 22+, and pnpm 9+.
git clone https://github.com/Chessing234/w-agent.git
cd w-agent
cp .env.example .env
# Required: OPENAI_API_KEY
# Recommended: DASHBOARD_TOKEN (long random secret)
docker compose up -d --build
pnpm install && pnpm migrate
# Pair: QR in app logs or the dashboard
docker compose logs -f app
# — or —
# DASHBOARD_TOKEN=… pnpm dashboard:dev → http://localhost:3200/pairing
Open WhatsApp → Linked devices → scan the QR. When the session shows connected, you are done for the default Baileys path.
curl -sS "http://127.0.0.1:3099/healthz"
Local Postgres/Redis only (host-run agent): make up-dev — see examples/docker-compose.override.yml.
Documentation
| Document | Contents |
|---|---|
| docs/architecture.md | Bridge, queue, storage, agent, MCP; provider-adapter rationale |
| docs/security.md | Injection threat model, approval pipeline, ban risk, data locality |
| SECURITY.md | Responsible disclosure |
| docs/mcp-clients.md | Claude Desktop & ChatGPT MCP snippets |
| docs/providers.md | Baileys vs Meta Cloud API |
| examples/demo.md | Demo flows, red-team, backup/restore |
| CHANGELOG.md | Release notes |
| CONTRIBUTING.md | Dev setup, tests, PR expectations |
Dashboard
pnpm dashboard:dev # http://localhost:3200 — token: DASHBOARD_TOKEN
Routes: /pairing, /chats, /approvals, /health.
MCP
| Transport | Command | Auth |
|---|---|---|
| stdio | pnpm mcp |
Local process (Claude Desktop) |
| HTTP + SSE | App when MCP_AUTH_TOKEN is set, or pnpm mcp:http |
Bearer / X-MCP-Token / ?token= |
Full client setup: docs/mcp-clients.md.
Development
pnpm install && cp .env.example .env
make up-dev && pnpm migrate
pnpm dev
pnpm dashboard:dev
pnpm lint && pnpm typecheck
pnpm test # Docker required (testcontainers Postgres)
pnpm test:coverage # ≥80% on src/safety + src/agent
pnpm redteam # 10 canned injection payloads
pnpm backup # Postgres + auth → backups/*.tar.gz
CI (.github/workflows/ci.yml): lint, typecheck, coverage on Node 22 with Redis; Postgres via testcontainers.
Configuration
Validated in src/config.ts (Zod). Full list: .env.example.
| Variable | Purpose |
|---|---|
OPENAI_API_KEY |
Embeddings, summaries, agent, optional classifiers |
DATABASE_URL / REDIS_URL |
Postgres + Redis |
WHATSAPP_PROVIDER |
baileys (default) | meta | evolution (reserved) |
WHATSAPP_AUTH_DIR / MEDIA_DIR |
Baileys auth + inbound media |
DASHBOARD_TOKEN / MCP_AUTH_TOKEN |
Dashboard / remote MCP secrets |
HEALTHZ_PORT |
Aggregated /healthz |
OWNER_TIMEZONE / QUIET_HOURS_* / SEND_* |
Auto-send safety |
License
MIT © W Agent contributors
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。