WhatsApp Claude MCP
WhatsApp Claude MCP
Model Context Protocol(MCP)を利用してClaude AIと統合した、高性能なWhatsAppボットです。WhatsAppボットにメッセージを送ると、外部APIやツールにアクセスできるClaudeによるインテリジェントな応答が返ってきます。
🌟 機能
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/healthClaudeにメッセージを送信
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"
}'🛠️ 利用可能なツール
Joke Generator
Claudeは必要に応じてこのツールを自動的に使用できます:
トリガー: ユーザーがジョークを要求したとき
タイプ: random、programming、general
API: Official Joke API
対話例:
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との連携
オプション1: WhatsApp Cloud API
本番環境では、WhatsApp Cloud API と連携します:
Meta Business Platformでウェブフックを設定します
ウェブフックURLを
https://your-domain.com/webhook/whatsappに指定しますWhatsAppがメッセージを受信したら、このエンドポイントにメッセージを転送します
オプション2: ローカルでのテスト
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のウェブフックがメッセージを受信します
Claude処理 → 利用可能なツールとともにメッセージがClaudeに送信されます
ツール選択 → Claudeがツールが必要かどうかを判断します
ツール実行 → MCPサーバーがツールを実行します(例: ジョークの取得)
応答生成 → 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サーバーへの登録
// 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ファイルをバージョン管理にコミットしないでくださいレート制限: 本番環境ではレート制限の導入を検討してください
入力検証: ウェブフックのポッドを常に検証してください
HTTPS: 本番環境ではHTTPSを使用してください
認証: サイン検証を追加して、WhatsApp連携の安全性を高めてください
📝 環境変数
変数 | 説明 | 設定例 |
| Claude APIキー |
|
| サーバーポート |
|
| 環境 |
|
| ジョークAPIエンドポイント |
|
コントリビューション
自由にフォークして、修正し、コントリビュートしてください!
📄 ライセンス
MIT License – 詳細はLICENSEファイルを参照してください
🛠️ トラブルシューティング
「APIキーが見つかりません」
.envファイルが存在し、ANTHROPIC_API_KEYが設定されていることを確認してくださいconsole.anthropic.com でキーが有効かどうか確認してください
「ツールの実行に失敗しました」
外部APIにアクセスできるか確認してください
ネットワーク接続を確認してください
コンソール出力のエラーログを確認してください
「Claudeから応答がありません」
ANTHROPIC_API_KEYが正しいことを確認してくださいClaudeモデルが利用可能か確認してください
APIのレート制限を確認してください
📞 サポート
問題や質問がある場合は:
トラブルシューティングのセクションを確認してください
Claude APIドキュメントを参照してください
GitHubでイシューを開いてください
🎯 今後の拡張予定
WhatsAppメッセージでの画像・メディアサポート
追加ツール(天気、ニュース、翻訳)
永続的な会話履歴を実現するデータベース
レート制限と認証
監視用の管理ダッシュボード
多言語サポート
ユーザーごとのカスタムClaudeシステムプロンプト
yulianheroes-lgtm が❤️を込めて作成
This server cannot be deployed
Maintenance
Related MCP Connectors
WhatsMCP connects Claude and other MCP-compatible AI agents directly to WhatsApp. Send and receive text, images, documents, and voice notes; manage groups (create, add/remove members, promote admins); look up contacts and profiles; follow channels; and read call and message history — all through a standard MCP interface. For voice use cases, WhatsMCP offers SIP-based calling plans (inbound-only, or full inbound/outbound) so AI voice agents can answer and place WhatsApp calls, plus low-latency WebSocket integrations with voice agent providers like ElevenLabs. Multiple WhatsApp accounts can be paired and managed per workspace, with webhook support for real-time inbound message delivery to your own infrastructure.
Let Claude or ChatGPT search, read and send your WhatsApp messages over MCP. OAuth sign-in.
Ask questions across your WhatsApp inbox from Claude, ChatGPT, Cursor or any MCP client.
Your own WhatsApp in Claude and ChatGPT: read chats, draft replies, send messages you approve.
1
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
- AlicenseAqualityDmaintenanceEnables Claude to interact with WhatsApp through a unified backend API, providing 20 tools for messaging, media, groups, contacts, and chat management.2240 npmMIT
- AlicenseNot gradedqualityDmaintenanceConnects WhatsApp to Claude Code, enabling message reading, audio transcription, image analysis, and message sending with full codebase context.36 npmMIT
- 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.36 npmMIT