WhatsApp访问服务器

一个通过集成Go桥接器提供对WhatsApp完整读写访问的Elixir MCP服务器。

  • by ZenHive
  • Elixir
  • 本地部署
  • 2 星标
  • 更新于
在 GitHub 查看 ZenHive/whatsapp_mcp

使用说明

WhatsApp MCP服务器

Elixir MCP(模型上下文协议)服务器,通过集成的Go桥提供对WhatsApp的完全读/写访问。

特性

50+WhatsApp工具 通过懒惰发现模式公开,以实现最小的令牌开销:

MCP服务器公开了3个元工具,可按需访问所有WhatsApp功能:

  • tool_list -列出可用工具并简要说明
  • tool_get -获取特定工具的完整架构
  • tool_call -按名称执行任何工具

与预先公开所有工具模式相比,这将令牌开销减少了约90%。

可用工具类别:

阅读: list_chats, get_messages, search_messages, search_contacts, get_chat, get_direct_chat_by_contact, get_message_context, get_last_interaction, get_contact_chats

写作: send_message, send_file, send_audio_message, download_media, create_poll, send_typing, mark_read, react_to_message, reply_to_message, edit_message, delete_message, send_location

组: list_groups, get_group_info, get_group_invite_link, join_group, create_group, leave_group, update_group_name, update_group_description, update_group_settings, manage_group_members

新闻通讯: list_newsletters, get_newsletter_info, get_newsletter_messages, follow_newsletter, unfollow_newsletter

隐私: get_privacy_settings, set_privacy_setting, get_blocklist, update_blocklist, set_disappearing_timer, set_presence, subscribe_presence

公用设施: get_bridge_status, get_help, is_on_whatsapp, get_profile_picture, get_business_profile, list_contacts, merge_chats, reject_call

需求

  • 灵丹妙药1.15+ 使用Erlang/OTP 26+
  • 转到1.25+ (有关WhatsApp桥,请参阅 bridge/go.mod)
  • SQLite (系统库——Exqlite捆绑了自己的,但 gcc/clang 需要在首次编译时构建NIF)
  • A. WhatsApp帐户 (您将在第一次过桥时扫描二维码)

安装工具链

macOS(Homebrew):

brew install elixir go sqlite

asdf(多版本管理器,建议用于匹配精确版本):

asdf plugin add elixir
asdf plugin add erlang
asdf plugin add golang
asdf install   # reads .tool-versions if present

Linux(Debian/Ubuntu):

sudo apt-get install elixir erlang-dev golang-go sqlite3 build-essential

安装

克隆仓库并安装两个堆栈的依赖关系:

git clone https://github.com/ZenHive/whatsapp_mcp.git
cd whatsapp_mcp

# 1. Elixir MCP server dependencies
mix deps.get
mix compile

# 2. Go bridge dependencies
cd bridge
go mod download
go build -o whatsapp-bridge .
cd ..

go build 是可选的-- go run . (以下使用)即时编译。一次建成,给你一个 bridge/whatsapp-bridge 二进制文件可以直接启动。

运行两台服务器

该项目已 两个长时间运行的进程 为了使MCP工具正常工作,这两者都必须是活的:

  1. 去桥 -与WhatsApp Web对话,将消息持久化到SQLite,在上公开HTTP API localhost:8080
  2. Elixir MCP服务器 -通过stdio将JSON-RPC 2.0与Claude Code进行对话,读取SQLite DB,并调用网桥的HTTP API进行发送/下载

Go桥在自己的终点站连续运行。Elixir MCP服务器通常会启动 由Claude Code自动执行 (通过 bin/whatsapp-mcp)--除非调试,否则不要手动运行它。

1.启动Go Bridge(1号航站楼,保持运行)

cd bridge
go run .
# or, if you ran `go build` above:
./whatsapp-bridge

首次运行时,使用WhatsApp移动应用程序扫描打印在终端上的二维码: 设置→ 链接设备→ 链接设备.

桥:

  • 收听 http://localhost:8080
  • 将消息历史记录存储在 bridge/store/messages.db
  • 将WhatsApp会话凭据存储在 bridge/store/whatsapp.db (所以你只扫描一次二维码)
  • 将媒体下载到 bridge/store/

保持此进程运行。如果你停止并重新启动它,会话将被保留——除非 bridge/store/whatsapp.db 已删除。

要强制完全重新同步(重新扫描二维码):

./scripts/clean_bridge_store.sh

2.使用Claude代码注册Elixir MCP服务器

claude mcp add whatsapp /path/to/whatsapp_mcp/bin/whatsapp-mcp

或者手动添加到您的Claude Code MCP设置中:

{
  "mcpServers": {
    "whatsapp": {
      "command": "/path/to/whatsapp_mcp/bin/whatsapp-mcp"
    }
  }
}

Claude Code将按需生成Elixir MCP服务器,并通过其stdio传输JSON-RPC。你不需要第二个终端。

3.重新启动克劳德代码

注册后,重新启动Claude Code或运行 /mcp 重新连接。

手动运行Elixir MCP服务器(仅调试)

如果您想手动驱动MCP服务器(例如通过管道JSON-RPC进行测试):

./bin/whatsapp-mcp
# or
mix run --no-halt -e "WhatsappMcp.Server.start_link([])"

使用MCP工具

服务器使用 懒惰发现模式 -它没有公开50多个工具模式,而是公开了3个包装工具:

包装工具 说明
tool_list 列出可用工具并简要说明。可选择按类别筛选。
tool_get 获取特定工具的完整JSON模式(参数、类型、描述)。
tool_call 按名称和参数执行工具。

AI工作流程:

  1. tool_list → 查看可用内容
  2. tool_get("send_message") → 如果需要,获取完整架构
  3. tool_call("send_message", {"recipient": "...", "message": "..."}) → 执行

提示: 呼叫 tool_call("get_help", {}) 用于电话号码格式、JID约定和使用工作流。

Claude代码中的示例用法

"Show me my recent WhatsApp chats"
→ Uses list_chats tool

"What did John say about the meeting?"
→ Uses search_messages with query "meeting"

"Get the last 20 messages from Mom"
→ Uses get_messages with chat_name "Mom"

"Send 'On my way!' to +1234567890"
→ Uses send_message tool

"Find all my contacts named Smith"
→ Uses search_contacts with query "Smith"

"Show me the context around that message"
→ Uses get_message_context with the message_id

"When did I last talk to John?"
→ Uses get_last_interaction tool

"Send this screenshot to the family group"
→ Uses send_file with the image path

"Download that photo John sent"
→ Uses download_media with message_id and chat_jid

建筑学

Claude Code ←→ Elixir MCP Server ←→ Go Bridge ←→ WhatsApp Web API
                    │                    │
                    │                    └── bridge/store/messages.db
                    │
                    └── Reads DB for queries, calls HTTP API for sends

发展

# Run tests (unit tests, no bridge needed)
mix test

# Run integration tests (requires bridge running)
mix test --include integration

# Check code quality
mix credo
mix dialyzer

# Generate docs
mix docs

故障排除

MCP服务器连接失败

  1. 确保Go桥正在运行(cd bridge && go run .)
  2. 检查一下 bridge/store/messages.db 存在
  3. 重新启动Claude Code或运行 /mcp 重新连接

找不到数据库错误

包装器脚本必须从项目目录运行。验证:

cat bin/whatsapp-mcp
# Should show: cd /path/to/whatsapp_mcp && exec mix run --no-halt -e "..."

未显示任何消息

Go桥实时同步消息。在WhatsApp同步之前,历史消息可能无法使用。发送/接收一些消息以填充数据库。

隐私

  • 所有数据都保持在本地,没有外部服务器
  • Go桥直接连接到WhatsApp的服务器
  • 消息存储在本地SQLite数据库中
  • MCP服务器仅通过stdio与Claude Code通信

致谢

Go桥基于 whatsapp mcp 卢克·哈里斯,其中使用了优秀的 怎么回事 WhatsApp Web协议实现库。

许可证

麻省理工学院-参见 许可证 了解详情。