The WhatsApp MCP Server is a server implementation using the Model Context Protocol (MCP) SDK. It provides a standardized interface for interacting with WhatsApp through the GreenAPI service, enabling seamless integration and management of WhatsApp sessions.
Before you begin, ensure you have the following:
- Node.js (v14 or higher)
- npm or yarn
- A GreenAPI account and credentials
shell
git clone <repository-url>
cd whatsapp-mcp-server
shell
npm install
The server requires the following environment variables:
- GREENAPI_API_URL
: The base URL for the GreenAPI service.
- GREENAPI_API_TOKEN
: Your GreenAPI API token.
shell
npm start
Opens a new WhatsApp session using GreenAPI credentials.
Parameters:
- sessionId
: A unique session ID.
- instanceId
: GreenAPI instance ID.
- apiTokenInstance
: GreenAPI API token.
Sends a message to a specified chat.
Parameters:
- sessionId
: Session ID from open_session
.
- chatId
: Recipient chat ID (e.g., [email protected]
or [email protected]
).
- message
: The message to send.
Retrieves the list of available chats.
Parameters:
- sessionId
: Session ID from open_session
.
Creates a new WhatsApp group.
Parameters:
- sessionId
: Session ID from open_session
.
- groupName
: Name of the group to create.
- participants
: Array of phone numbers with domain (e.g., [email protected]
).
Retrieves recent messages from a specified chat (personal or group).
Parameters:
- sessionId
: Session ID from open_session
.
- chatId
: Chat ID to retrieve messages from (e.g., [email protected]
or [email protected]
).
- count
: Number of messages to retrieve (default: 50).
Important: Enable "Receive webhooks on incoming messages and files" in GreenAPI settings to include incoming messages in the chat history.
Sends a file to a specified chat.
Parameters:
- sessionId
: Session ID from open_session
.
- chatId
: WhatsApp chat ID (e.g., [email protected]
).
- fileUrl
: Public URL of the file to send.
- fileName
: (Optional) Name of the file as seen by the recipient.
- caption
: (Optional) Caption text to display below the file.
Adds a participant to an existing WhatsApp group.
Parameters:
- sessionId
: Session ID from open_session
.
- groupId
: ID of the WhatsApp group (e.g., [email protected]
).
- participantChatId
: Chat ID of the participant to add (e.g., [email protected]
).
Removes a participant from an existing WhatsApp group.
Parameters:
- sessionId
: Session ID from open_session
.
- groupId
: ID of the WhatsApp group (e.g., [email protected]
).
- participantChatId
: Chat ID of the participant to remove (e.g., [email protected]
).
The WhatsApp MCP Server is a powerful tool for integrating WhatsApp functionality into your applications using the GreenAPI service. It simplifies session management and provides a standardized interface for various WhatsApp operations.
No releases published.
No packages published.