WhatsApp MCP Server
WhatsApp MCP 服务器
提供模型上下文协议 (MCP) 接口以使用 FastMCP 与 WhatsApp Business API 交互的服务器。
介绍
WhatsApp MCP 服务器是一个 Python 实现,它允许 Claude 等语言模型通过GreenAPI与 WhatsApp 功能进行交互。它利用 FastMCP 来提升性能、改善开发者体验,并实现更简洁的实现。
Related MCP server: YCloud WhatsApp API MCP Server
特征
消息传递:向 WhatsApp 联系人发送短信
群组管理:创建群组、列出成员、添加/删除参与者
会话处理:管理 WhatsApp API 会话
聊天记录:检索聊天列表和消息历史记录
WhatsApp API 客户端
该项目使用whatsapp-api-client-python库与 WhatsApp 交互。该客户端提供对 WhatsApp Cloud API 的访问,需要GreenAPI帐户才能使用。
环境变量
本项目使用环境变量进行配置:
GREENAPI_ID_INSTANCE:您的 GreenAPI ID 实例GREENAPI_API_TOKEN:您的 GreenAPI API 令牌
您可以在您的环境中设置这些,也可以使用提供的.env文件(请参阅安装说明)。
安装
# Clone the repository
git clone https://github.com/yourusername/whatsapp-mcp-server.git
cd whatsapp-mcp-server
# Install dependencies
pip install -e .
# Set up environment variables
cp .env-template .env
# Edit the .env file with your GreenAPI credentials用法
运行 MCP 服务器:
# Run the MCP server on default host (127.0.0.1) and port (8000)
whatsapp-mcp
# Specify host and port
whatsapp-mcp --host 0.0.0.0 --port 9000用于调试:
whatsapp-mcp --debug服务器使用模型上下文协议 (MCP) 进行通信,在使用 FastMCP 运行时可以通过 HTTP 或 WebSockets 访问。
可用工具
open_session:打开新的 WhatsApp 会话send_message:向聊天发送消息get_chats:获取聊天列表create_group:创建一个新的 WhatsApp 群组get_group_participants:获取群组的参与者
FastMCP API 参考
WhatsApp MCP 服务器使用 FastMCP 提供 WebSocket 和 HTTP 端点:
WebSocket:
ws://localhost:8000/mcpHTTP:
http://localhost:8000/mcp
您可以使用 curl 等工具直接测试 API:
# List available tools
curl -X POST http://localhost:8000/mcp/listTools
# Call a tool
curl -X POST http://localhost:8000/mcp/callTool \
-H "Content-Type: application/json" \
-d '{"name": "open_session", "arguments": {}}'如何将其添加到 Claude Code
要将 WhatsApp 服务器添加到 Claude,请使用claude mcp add命令:
# Add the WhatsApp MCP server
$ claude mcp add whatsapp -- whatsapp-mcp
# List existing MCP servers - Validate that the server is running
claude mcp list
# Start claude code
claude与 Claude 一起使用
一旦 WhatsApp MCP 服务器运行,您就可以在对话中使用 Claude 与其进行交互:
使用 WhatsApp 进行身份验证
Login to WhatsApp发送消息
Send the "Hello" message to John Doe与 Claude Desktop 一起使用
要将 WhatsApp MCP 服务器与 Claude Desktop 一起使用,您需要将其添加到您的claude_desktop_config.json文件中:
使用pip安装(推荐)
"mcpServers": {
"whatsapp": {
"command": "python",
"args": ["-m", "whatsapp_mcp"]
}
}使用可执行文件
"mcpServers": {
"whatsapp": {
"command": "whatsapp-mcp"
}
}使用 Docker
"mcpServers": {
"whatsapp": {
"command": "docker",
"args": ["run", "--rm", "-i", "-e", "GREENAPI_ID_INSTANCE=your_instance_id", "-e", "GREENAPI_API_TOKEN=your_api_token", "whatsapp-mcp-server"]
}
}在启动 Claude Desktop 之前,请记住将您的 GreenAPI 凭据设置为环境变量或在您的.env文件中。
命令行选项
WhatsApp MCP 服务器接受以下命令行参数:
--debug:增加调试的详细程度--host:绑定服务器的主机(默认值:127.0.0.1)--port:绑定服务器的端口(默认值:8000)
调试
调试 MCP 服务器:
使用 MCP 检查器:
npx @modelcontextprotocol/inspector whatsapp-mcp查看 Claude Desktop 日志目录中的日志(在 macOS 上通常为
~/Library/Logs/Claude/)访问 FastMCP 网页界面http://localhost:8000获取交互式 API 文档
发展
# Install development dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Run linting
flake8 src/
# Run type checking
mypy src/该项目使用现代pyproject.toml配置,其中包括:
运行应用程序所需的核心依赖项
使用
pip install -e ".[dev]"可以获取开发依赖项
执照
该项目根据 MIT 许可证获得许可 - 有关详细信息,请参阅 LICENSE 文件。
Available Tools
5 toolscreate_groupC
Create a new WhatsApp group.
Parameters:
- group_name: Name of the group to create
- participants: List of participant phone numbers
| Name | Required | Description | Default |
|---|---|---|---|
| group_name | Yes | ||
| participants | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries full burden for behavioral disclosure. It states the action but doesn't cover critical aspects: whether this requires specific permissions, if it's idempotent, what happens on failure, rate limits, or the expected return format. The description is minimal and lacks necessary operational context.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is appropriately concise with a clear heading and bullet points for parameters. Every sentence adds value, and it's front-loaded with the core purpose. No redundant information is present, though it could benefit from more structured behavioral details.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given the complexity of a creation tool with no annotations and no output schema, the description is incomplete. It lacks information on success/failure responses, error handling, dependencies (e.g., session requirements), and behavioral traits. For a mutation tool, this leaves significant gaps for an AI agent to operate effectively.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 0%, so the description must compensate. It lists both parameters with brief explanations ('Name of the group to create', 'List of participant phone numbers'), adding basic meaning beyond the schema's titles. However, it doesn't specify format constraints (e.g., phone number format, group name length limits), leaving gaps in parameter understanding.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the verb 'Create' and resource 'new WhatsApp group', making the purpose unambiguous. However, it doesn't explicitly distinguish this from sibling tools like 'get_chats' or 'send_message', though the creation action is inherently different from retrieval/messaging operations.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing an active session via 'open_session'), exclusions, or comparative context with sibling tools like managing existing groups versus creating new ones.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
get_chatsC
Get a list of chats.
Parameters:
- limit: Maximum number of chats to return (default: 50)
- offset: Offset for pagination (default: 0)
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | ||
| offset | No |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions parameters for pagination but does not describe key traits like whether this is a read-only operation, potential rate limits, authentication needs, or what the output looks like (e.g., format, fields). For a list tool with no annotation coverage, this leaves significant gaps in understanding its behavior.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is appropriately sized and front-loaded, starting with the main purpose followed by parameter details in a clear list format. Every sentence adds value, with no redundant or wasted words. However, the structure could be slightly improved by integrating the purpose and parameters more seamlessly, but it remains efficient.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given the complexity (a list tool with 2 parameters), lack of annotations, and no output schema, the description is incomplete. It covers basic purpose and parameters but misses critical context like output format, error handling, or how it fits with sibling tools. For adequate agent use, it should provide more behavioral and contextual details beyond the minimal information given.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The description adds meaningful semantics beyond the input schema, which has 0% description coverage. It explains that 'limit' is the 'Maximum number of chats to return' with a default of 50, and 'offset' is for 'pagination' with a default of 0, clarifying their purposes. Since there are only 2 parameters and the schema lacks descriptions, this compensates well, though it could detail constraints like min/max values.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description states 'Get a list of chats,' which clearly indicates the verb ('Get') and resource ('chats'), providing a basic purpose. However, it lacks specificity about what 'chats' entails (e.g., types, scope) and does not differentiate from sibling tools like 'get_group_participants' or 'open_session,' leaving room for ambiguity. This is a minimal viable description but vague in context.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description provides no guidance on when to use this tool versus alternatives. It does not mention any context, prerequisites, or exclusions, such as how it relates to sibling tools like 'get_group_participants' for participant details or 'open_session' for active chats. Without such information, the agent must infer usage, which reduces effectiveness.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
get_group_participantsB
Get the participants of a WhatsApp group.
Parameters:
- group_id: The WhatsApp ID of the group
| Name | Required | Description | Default |
|---|---|---|---|
| group_id | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries full burden for behavioral disclosure. It states what the tool does but doesn't mention whether this is a read-only operation, requires authentication, has rate limits, or what the return format looks like. For a tool with zero annotation coverage, this is inadequate.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is perfectly concise: one clear purpose statement followed by a parameter explanation. Every sentence earns its place with no wasted words, and the information is front-loaded appropriately.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
For a simple single-parameter tool with no output schema, the description covers the basic purpose and parameter meaning adequately. However, the lack of behavioral information (especially with no annotations) and usage guidance relative to siblings leaves gaps that could hinder effective tool selection.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The description explicitly documents the single parameter 'group_id' and explains it as 'The WhatsApp ID of the group', adding meaningful context beyond the schema's basic type information. With 0% schema description coverage, this fully compensates for the schema's lack of detail.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the verb ('Get') and resource ('participants of a WhatsApp group'), making the purpose immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'get_chats' which might also involve group data, so it doesn't reach the highest score.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description provides no guidance on when to use this tool versus alternatives like 'get_chats' or 'create_group'. It doesn't mention prerequisites, context, or exclusions, leaving the agent to infer usage from the tool name alone.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
open_sessionB
Open a new WhatsApp session.
| Name | Required | Description | Default |
|---|---|---|---|
No parameters | |||
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries full burden for behavioral disclosure. While 'Open a new WhatsApp session' implies initialization or connection, it lacks critical details: whether this requires credentials, if it's idempotent, what happens to existing sessions, potential side effects, or error conditions. This leaves significant behavioral gaps for a session management tool.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is a single, efficient sentence that directly states the tool's purpose with zero wasted words. It's appropriately sized for a simple tool and front-loaded with the essential information, making it easy for an agent to parse quickly.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given the complexity of session management (which often involves authentication, state persistence, and error handling), the description is insufficient. With no annotations, no output schema, and minimal behavioral context, it fails to provide complete guidance. The agent would need to guess about return values, success/failure states, and operational constraints.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The tool has 0 parameters with 100% schema description coverage, so the schema fully documents the absence of inputs. The description appropriately doesn't discuss parameters, maintaining focus on the tool's purpose without redundancy. A baseline of 4 is appropriate for zero-parameter tools when the schema coverage is complete.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the action ('Open') and target resource ('a new WhatsApp session'), providing a specific verb+resource combination. However, it doesn't distinguish this tool from its siblings like 'create_group' or 'send_message', which would require explicit differentiation for a perfect score.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description provides no guidance on when to use this tool versus alternatives like 'get_chats' or 'send_message'. There's no mention of prerequisites (e.g., authentication status), timing considerations, or explicit exclusions, leaving the agent with minimal contextual direction.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
send_messageC
Send a message to a chat.
Parameters:
- phone_number: The phone number of the recipient
- content: The content of the message to send
- reply_to: ID of the message to reply to (optional)
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes | ||
| phone_number | Yes | ||
| reply_to | No |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries the full burden of behavioral disclosure. While 'Send a message' implies a write/mutation operation, the description doesn't address critical behavioral aspects like required permissions, rate limits, whether messages are encrypted, delivery confirmation, or what happens on failure. This leaves significant gaps for an agent to understand the tool's behavior.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is efficiently structured with a clear purpose statement followed by a bulleted parameter list. Every sentence serves a purpose, though the parameter explanations could be slightly more detailed given the lack of schema descriptions. The formatting is clean and easy to parse.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
For a 3-parameter mutation tool with no annotations and no output schema, the description is insufficiently complete. It doesn't explain what the tool returns (success/failure indicators, message ID, etc.), doesn't address error conditions, and provides minimal behavioral context. The parameter explanations help but don't compensate for the overall contextual gaps.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The description explicitly lists all three parameters with brief explanations, adding meaningful context beyond the schema's 0% description coverage. It clarifies that 'reply_to' is optional and identifies what each parameter represents. However, it doesn't provide format details (e.g., phone number format, content length limits) or deeper semantic constraints.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the action ('Send a message') and the target resource ('to a chat'), providing a specific verb+resource combination. However, it doesn't differentiate this tool from potential sibling tools like 'create_group' or 'open_session', which might also involve messaging functionality in some contexts.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description provides no guidance on when to use this tool versus alternatives like 'create_group' for group messaging or 'get_chats' for retrieving messages. There's no mention of prerequisites, appropriate contexts, or exclusions for this messaging operation.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
5 tool updates
v1.0.0- First observed
create_group - First observed
get_chats - First observed
get_group_participants - First observed
open_session - First observed
send_message
TDQS
Scored across 5 tools
Most tools have distinct purposes: creating groups, listing chats, getting group participants, opening sessions, and sending messages. However, 'get_chats' could potentially overlap with group-related functionality since groups are a type of chat, but the descriptions clarify their focus areas.
The naming follows a consistent verb_noun pattern (e.g., create_group, get_chats, send_message) with clear, descriptive names. The only minor deviation is 'open_session', which uses a verb_adjective_noun structure but remains readable and fits the pattern conceptually.
With 5 tools, the count is reasonable for a WhatsApp server, covering core operations like messaging, group management, and session handling. It might benefit from additional tools for actions like deleting messages or managing contacts, but it's well-scoped for basic functionality.
The toolset covers key areas such as sending messages, creating groups, and retrieving chats/participants, but has notable gaps. For example, there are no tools for updating or deleting groups, managing contacts, or handling message reactions, which could limit agent workflows in a messaging domain.
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.
Your own WhatsApp in Claude and ChatGPT: read chats, draft replies, send messages you approve.
1Your WhatsApp Business inbox in Claude or ChatGPT: who's waiting, follow-ups and replies.
1WhatsApp for AI agents — your own number or the official Cloud API: messages, media, templates.
Related MCP Servers
- AlicenseCqualityFmaintenanceA Model Context Protocol server that connects your personal WhatsApp account to AI agents like Claude, enabling them to search messages, view contacts, retrieve chat history, and send messages via WhatsApp.711 npm74ISC
- FlicenseCqualityFmaintenanceA server that enables AI models like Claude to directly interact with YCloud WhatsApp API through natural language, automatically generating tools from the OpenAPI specification.1911-
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol server that enables interaction with WhatsApp through local stdio or remote HTTP/SSE connections. It allows users to send messages, manage groups, and access chat history using natural language.23 npm3MIT
- AlicenseNot gradedqualityDmaintenanceAn MCP server that connects Claude and other LLM clients to WhatsApp via the Baileys library. Enables sending and receiving messages, listing chats, downloading media, and more.19 npmMIT