WhatsApp MCP服务器
MCP(模型上下文协议)服务器,使AI能够通过对话在Meta上创建和管理WhatsApp模板。
特性
- 无需手动操作仪表板 -通过AI对话创建模板
- 多应用支持 -适用于多个WhatsApp商业帐户
- 验证 -Zod模式确保格式正确,AI自动纠正错误
- 直接到Meta -无存储,所有操作直接进入Meta API
工具
| 工具 | 目的 |
|---|---|
get_template_format | 获取所需的模板格式 |
create_whatsapp_template | 在Meta上创建一个模板 |
list_whatsapp_templates | 列出Meta中的模板 |
delete_whatsapp_template | 删除一个模板 |
get_template_status | 获取模板审批状态 |
安装
# Clone the repo
cd WhatsappMCP
# Install dependencies
npm install
# Build
npm run build配置
1.添加访问令牌
创建 .env 文件:
WHATSAPP_ACCESS_TOKEN=your_meta_access_token_here令牌必须具有 whatsapp_business_management 许可。2.配置光标
增添 ~/.cursor/mcp_settings.json:
{
"mcpServers": {
"whatsapp": {
"command": "node",
"args": ["c:/coding-line/WhatsappMCP/dist/server.js"]
}
}
}3.重新启动游标
用法
设计阶段(无MCP)
YOU: I need a booking confirmation template
AI: Here's a draft:
Hi {{customer_name}}!
Your booking for {{service_name}} is confirmed.
Date: {{date}}
YOU: Add booking ID
AI: Updated:
Hi {{customer_name}}!
Your booking for {{service_name}} is confirmed.
Date: {{date}}
Booking ID: {{booking_id}}创建阶段(使用MCP)
YOU: Create this on WhatsApp
AI: Let me check the format...
[calls get_template_format()]
Converting to correct format:
- name: booking_confirmation
- variables: {{1}}, {{2}}, {{3}}, {{4}}
I need your WABA ID to create this.
YOU: 278469610073775
AI: Creating...
[calls create_whatsapp_template()]
✅ Created! Status: Pending Approval其他操作
YOU: List templates for WABA 278469610073775
AI: [calls list_whatsapp_templates()]
Shows all templates from Meta
YOU: Delete booking_confirmation from WABA 278469610073775
AI: [calls delete_whatsapp_template()]
✅ Deleted!
YOU: Why was my template rejected?
AI: [calls get_template_status()]
Reason: "URL in body without URL button"项目结构
WhatsappMCP/
├── src/
│ ├── server.ts # MCP entry point
│ ├── tools/
│ │ ├── get-format.ts # get_template_format
│ │ ├── create.ts # create_whatsapp_template
│ │ ├── list.ts # list_whatsapp_templates
│ │ ├── delete.ts # delete_whatsapp_template
│ │ └── status.ts # get_template_status
│ ├── schemas/
│ │ └── template.ts # Zod validation schemas
│ └── lib/
│ └── meta-api.ts # Meta Graph API client
├── .env # Access token (not committed)
├── package.json
├── tsconfig.json
└── README.md安全
| 项目 | 位置 | 是否暴露? |
|---|---|---|
| 访问令牌 | .env | ❌ 从来没有 |
| WABA ID | 对话 | ✅ 安全 |
许可证
麻省理工学院
