WhatsApp Claude MCP
WhatsApp Claude MCP
一个功能强大的 WhatsApp 机器人,通过 Model Context Protocol (MCP) 与 Claude AI 集成。向你的 WhatsApp 机器人发送消息,即可获得由 Claude 驱动的智能回复,并能访问外部 API 和工具。
🌟 主要功能
Claude AI 集成:使用 Claude 3.5 Sonnet 进行智能对话
MCP 工具:可扩展的工具系统,让 Claude 与外部 API 交互
笑话生成器:内置工具,可从外部 API 获取随机笑话
对话记忆:为每个用户维护多轮上下文的往返
WhatsApp Webhook:用于与 WhatsApp 服务集成的简单 REST API
轻松部署:基于 express 服务器,方便部署到云端
Related MCP server: WAHA WhatsApp MCP Server
📋 环境准备
Node.js 18+
npm 或 yarn
Anthropic API 密钥(可在 console.anthropic.com 获取)
WhatsApp Cloud API 访问权限(用于生产接入)
🚀 快速开始
1. 克隆并安装
git clone https://github.com/yulianheroes-lgtm/whatsapp-claude-mcp.git
cd whatsapp-claude-mcp
npm install2. 设置环境变量
cp .env.example .env编辑 .env 并添加你的 Anthropic API 密钥:
ANTHROPIC_API_KEY=your_anthropic_api_key_here
PORT=30003. 启动服务
npm start你应该会看到:
✅ WhatsApp Claude MCP Server running on http://localhost:3000
🤖 Ready to process WhatsApp messages!📡 API 使用方法
健康检查
curl http://localhost:3000/health发送消息给 Claude
curl -X POST http://localhost:3000/webhook/whatsapp \
-H "Content-Type: application/json" \
-d '{
"userId": "1234567890",
"message": "Tell me a joke"
}'响应:
{
"success": true,
"userId": "1234567890",
"message": "😂 Here's a programming joke for you!\n\nWhy do programmers prefer dark mode?\n\nBecause light attracts bugs! 🐛"
}清除会话记录
curl -X POST http://localhost:3000/webhook/clear-history \
-H "Content-Type: application/json" \
-d '{
"userId": "1234567890"
}'🛠️ 可用工具
笑话生成器
Claude 会在合适的时候自动使用该工具:
触发条件:时长用户请求讲笑话
类型:random、programming、general
交互示例:
User: Tell me a funny programming joke
Bot: [Uses joke_generator tool] 😂 Here's a programming joke...📁 项目结构
whatsapp-claude-mcp/
├── src/
│ ├── index.js # Main Express server
│ ├── whatsapp-handler.js # Message handling & Claude integration
│ ├── mcp-server.js # MCP tool definitions & execution
│ └── tools/
│ └── joke-generator.js # Joke generator tool implementation
├── .env.example # Environment variables template
├── .gitignore # Git ignore rules
├── package.json # Dependencies
└── README.md # This file🔌 与 WhatsApp 集成
方案一:WhatsApp Cloud API
生产环境请与 WhatsApp Cloud API 集成:
在 Meta 商务平台上配置 webhook
将 webhook URL 设为:
https://your-domain.com/webhook/whatsapp当 WhatsApp 收到消息时,将其转发到此端点
方案二:本地测试
可使用 curl、Postman 或测试脚本发送消息:
// test.js
const userId = '1234567890';
const message = 'Tell me a joke';
const response = await fetch('http://localhost:3000/webhook/whatsapp', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ userId, message })
});
const result = await response.json();
console.log(result.message);🧠 工作原理
收到消息 → WhatsApp webhook 接收消息
Claude 处理 → 消息与可用工具一并发送给 Claude
工具选择 → Claude 判断是否需要工具
工具执行 → MCP server 执行工具(例如获取笑话)
生成回复 → Claude 利用工具结果生成回复
消息回应 → 通过 WhatsApp 发回回复
🚀 添加更多工具
要新增工具(如天气、翻译):
1. 创建工具文件
// src/tools/weather.js
export const weatherTool = {
name: 'get_weather',
description: 'Get current weather for a location',
inputSchema: {
type: 'object',
properties: {
location: { type: 'string', description: 'City name' }
}
}
};
export async function executeWeather(location) {
// Fetch weather data
return { /* weather data */ };
}2. 在 MCP Server 中注册
// src/mcp-server.js
import { weatherTool, executeWeather } from './tools/weather.js';
export class MCPServer {
constructor() {
this.tools = [
jokeGeneratorTool,
weatherTool // Add here
];
}
async processTool(toolName, toolInput) {
switch (toolName) {
case 'get_weather':
return await executeWeather(toolInput.location);
// ...
}
}
}📚 API 参考
POST /webhook/whatsapp
请求体:
{
"userId": "string (required)",
"message": "string (required)"
}响应:
{
"success": boolean,
"userId": "string",
"message": "string"
}POST /webhook/clear-history
请求体:
{
"userId": "string (required)"
}响应:
{
"success": boolean,
"message": "string"
}🔐 安全注意事项
API 密钥:切勿将
.env文件提交到版本控制中限速策略:生产环境建议开启限速
输入校验:始终验证 webhook 的请求负载
HTTPS:生产环境使用 HTTPS
认证机制:为 WhatsApp 集成增加 webhook 签名验证
📝 环境变量
变量 | 说明 | 示例 |
| Claude API 密钥 |
|
| 服务端口 |
|
| 运行环境 |
|
| 笑话 API 地址 |
|
🤝 一起贡献
欢迎 fork、修改并贡献代码!
📄 许可证
MIT License · 详情参阅 LICENSE 文件
🆘 疑难排查
"API key not found"
确认
.env文件存在,且ANTHROPIC_API_KEY已设置在 console.anthropic.com 检查密钥是否有效
"Tool execution failed"
检查外部 API 是否可访问
确认网络连接正常
查看控制台输出中的日志报错
"No response from Claude"
检查
ANTHROPIC_API_KEY是否正确确认 Claude 模型可用
检查 API 限速设置
📞 支持
如遇问题或有疑问:
查看以上“疑难排查”部分
阅读 Claude API 相关文档
在 GitHub 上提交 issue
🎯 未来规划
支持 WhatsApp 消息中的图片/媒体
增加更多工具(天气、新闻、翻译等)
使用数据库存储持久化的聊天记录
增加限流和身份认证
提供管理后台监控面板
多种语言支持
支持为每个用户自定义 Claude 系统提示词
由 yulianheroes-lgtm 用 ❤️ 制作
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- AlicenseAqualityDmaintenanceEnables sending, reading, and deleting WhatsApp messages through Claude Desktop and other MCP clients with granular per-chat permissions. Built on whatsapp-web.js using a headless browser to automate WhatsApp Web.6MIT
- AlicenseAqualityCmaintenanceEnables Claude to interact with WhatsApp through a unified backend API, providing 20 tools for messaging, media, groups, contacts, and chat management.22107MIT
- AlicenseNot gradedqualityBmaintenanceConnects WhatsApp to Claude Code, enabling message reading, audio transcription, image analysis, and message sending with full codebase context.51MIT
- AlicenseNot gradedqualityCmaintenanceA local MCP server that connects WhatsApp to Claude via QR code, enabling chat listing, message retrieval, and sending with automatic rate limiting for anti-ban protection.51MIT
Related MCP Connectors
Drive your real WhatsApp inbox from Claude — send, reply, label, assign, and triage via TimelinesAI.
Hosted MCP server connecting claude.ai, ChatGPT and other AI apps to your own computer
Security-first WordPress MCP server. 129 tools for Claude, ChatGPT, Gemini. Free on wp.org.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/yulianheroes-lgtm/whatsapp-claude-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server