Skip to main content
Glama
yulianheroes-lgtm

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 install

2. 環境変数の設定

cp .env.example .env

.env を編集して、Anthropic APIキーを追加します:

ANTHROPIC_API_KEY=your_anthropic_api_key_here
PORT=3000

3. サーバーの起動

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"
  }'

🛠️ 利用可能なツール

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 と連携します:

  1. Meta Business Platformでウェブフックを設定します

  2. ウェブフックURLを https://your-domain.com/webhook/whatsapp に指定します

  3. 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);

🧠 動作の仕組み

  1. メッセージ受信 → WhatsAppのウェブフックがメッセージを受信します

  2. Claude処理 → 利用可能なツールとともにメッセージがClaudeに送信されます

  3. ツール選択 → Claudeがツールが必要かどうかを判断します

  4. ツール実行 → MCPサーバーがツールを実行します(例: ジョークの取得)

  5. 応答生成 → Claudeがツールの結果を使って応答を生成します

  6. メッセージ送信 → 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連携の安全性を高めてください

📝 環境変数

変数

説明

設定例

ANTHROPIC_API_KEY

Claude APIキー

sk-ant-...

PORT

サーバーポート

3000

NODE_ENV

環境

development

JOKE_API_URL

ジョークAPIエンドポイント

https://official-joke-api.appspot.com/random_joke

コントリビューション

自由にフォークして、修正し、コントリビュートしてください!

📄 ライセンス

MIT License – 詳細はLICENSEファイルを参照してください

🛠️ トラブルシューティング

「APIキーが見つかりません」

  • .env ファイルが存在し、ANTHROPIC_API_KEY が設定されていることを確認してください

  • console.anthropic.com でキーが有効かどうか確認してください

「ツールの実行に失敗しました」

  • 外部APIにアクセスできるか確認してください

  • ネットワーク接続を確認してください

  • コンソール出力のエラーログを確認してください

「Claudeから応答がありません」

  • ANTHROPIC_API_KEY が正しいことを確認してください

  • Claudeモデルが利用可能か確認してください

  • APIのレート制限を確認してください

📞 サポート

問題や質問がある場合は:

  1. トラブルシューティングのセクションを確認してください

  2. Claude APIドキュメントを参照してください

  3. GitHubでイシューを開いてください

🎯 今後の拡張予定

  • WhatsAppメッセージでの画像・メディアサポート

  • 追加ツール(天気、ニュース、翻訳)

  • 永続的な会話履歴を実現するデータベース

  • レート制限と認証

  • 監視用の管理ダッシュボード

  • 多言語サポート

  • ユーザーごとのカスタムClaudeシステムプロンプト


yulianheroes-lgtm が❤️を込めて作成

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

  • A
    license
    A
    quality
    D
    maintenance
    Enables 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.
    6
    MIT
  • A
    license
    A
    quality
    D
    maintenance
    Enables Claude to interact with WhatsApp through a unified backend API, providing 20 tools for messaging, media, groups, contacts, and chat management.
    22
    40 npm
    MIT
  • A
    license
    Not graded
    quality
    C
    maintenance
    A 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 npm
    MIT