Labsco
jlucaso1 logo

WhatsApp

β˜… 66

from jlucaso1

Connect your personal WhatsApp account to an AI agent using the WhatsApp Web multi-device API.

πŸ”₯πŸ”₯πŸ”₯πŸ”₯βœ“ VerifiedFreeQuick setup

WhatsApp MCP Server (TypeScript/Baileys)

smithery badge

This is a Model Context Protocol (MCP) server for WhatsApp, built with TypeScript and using the @whiskeysockets/baileys library.

It allows you to connect your personal WhatsApp account to an AI agent (like Anthropic Claude via its desktop app or Cursor) enabling it to:

  • Search your personal WhatsApp messages.
  • Search your contacts (individuals, not groups).
  • List your recent chats.
  • Retrieve message history for specific chats.
  • Send messages to individuals or groups.

It connects directly to your personal WhatsApp account using the WhatsApp Web multi-device API. All your messages and authentication details are stored locally in a SQLite database (./data/) and authentication cache (./auth_info/). Data is only sent to the connected AI agent when it explicitly uses the provided MCP tools (which you control via the agent's interface).

(Optional: Consider adding a screenshot or GIF similar to the reference example here)

Example

User: Send a whatsapp message to "Meu amor" in whatsapp saying "Te amo"


Assistant: Okay, I need to find the contact first. Using tool: whatsapp.search_contacts

Copy & paste β€” that's it
{
  "query": "Meu amor"
}

Tool Result:

Copy & paste β€” that's it
[
  {
    "jid": "5599xxxxxx@s.whatsapp.net",
    "name": "Meu Amor"
  }
]

Assistant: Found the contact. Now sending the message. Using tool: whatsapp.send_message

Copy & paste β€” that's it
{
  "recipient": "5599xxxxxx@s.whatsapp.net",
  "message": "Te amo"
}

Tool Result:

Copy & paste β€” that's it
Message sent successfully to 5599xxxxxx@s.whatsapp.net (ID: XXXXXXXXXXX).

Key Features (MCP Tools)

The server exposes the following tools to the connected AI agent:

  • search_contacts: Search for contacts by name or phone number part (JID).
  • list_messages: Retrieve message history for a specific chat, with pagination.
  • list_chats: List your chats, sortable by activity or name, filterable, paginated, optionally includes last message details.
  • get_chat: Get detailed information about a specific chat.
  • get_message_context: Retrieve messages sent immediately before and after a specific message ID for context.
  • send_message: Send a text message to a specified recipient JID (user or group).

Architecture Overview

This application is a single Node.js process that:

  1. Uses @whiskeysockets/baileys to connect to the WhatsApp Web API, handling authentication and real-time events.
  2. Stores WhatsApp chats and messages locally in a SQLite database (./data/whatsapp.db) using node:sqlite.
  3. Runs an MCP server using @modelcontextprotocol/sdk that listens for requests from an AI client over standard input/output (stdio).
  4. Provides MCP tools that query the local SQLite database or use the Baileys socket to send messages.
  5. Uses pino for logging activity (wa-logs.txt for WhatsApp events, mcp-logs.txt for MCP server activity).

Data Storage & Privacy

  • Authentication: Your WhatsApp connection credentials are stored locally in the ./auth_info/ directory.
  • Messages & Chats: Your message history and chat metadata are stored locally in the ./data/whatsapp.db SQLite file.
  • Local Data: Both auth_info/ and data/ are included in .gitignore to prevent accidental commits. Treat these directories as sensitive.
  • LLM Interaction: Data is only sent to the connected Large Language Model (LLM) when the AI agent actively uses one of the provided MCP tools (e.g., list_messages, send_message). The server itself does not proactively send your data anywhere else.

Technical Details

  • Language: TypeScript
  • Runtime: Node.js (>= v23.10.0)
  • WhatsApp API: @whiskeysockets/baileys
  • MCP SDK: @modelcontextprotocol/sdk
  • Database: node:sqlite (Bundled SQLite)
  • Logging: pino
  • Schema Validation: zod (for MCP tool inputs)

Credits

License

This project is licensed under the ISC License (see package.json).