whatsapp_send_text
Send text messages to WhatsApp contacts or groups with support for mentions and replies using the WSAPI WhatsApp MCP Server.
Instructions
Send a text message to a WhatsApp contact or group. Supports mentions and replies.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| isForwarded | No | Whether the message should be marked as forwarded | |
| mentions | No | List of phone numbers to mention in the message | |
| replyTo | No | ID of the message being replied to | |
| text | Yes | Message text content (max 4096 characters) | |
| to | Yes | Recipient phone number (with @s.whatsapp.net) or group ID (with @g.us) |
Input Schema (JSON Schema)
{
"properties": {
"isForwarded": {
"description": "Whether the message should be marked as forwarded",
"optional": true,
"type": "boolean"
},
"mentions": {
"description": "List of phone numbers to mention in the message",
"items": {
"type": "string"
},
"optional": true,
"type": "array"
},
"replyTo": {
"description": "ID of the message being replied to",
"optional": true,
"type": "string"
},
"text": {
"description": "Message text content (max 4096 characters)",
"type": "string"
},
"to": {
"description": "Recipient phone number (with @s.whatsapp.net) or group ID (with @g.us)",
"type": "string"
}
},
"required": [
"to",
"text"
],
"type": "object"
}
Implementation Reference
- src/tools/messaging.ts:25-73 (handler)The complete ToolHandler for 'whatsapp_send_text' including MCP inputSchema, description, and execution logic that validates input with Zod schema and calls the WSAPI endpoint.export const sendTextMessage: ToolHandler = { name: 'whatsapp_send_text', description: 'Send a text message to a WhatsApp contact or group. Supports mentions and replies.', inputSchema: { type: 'object', properties: { to: { type: 'string', description: 'Recipient phone number (with @s.whatsapp.net) or group ID (with @g.us)', }, text: { type: 'string', description: 'Message text content (max 4096 characters)', }, mentions: { type: 'array', items: { type: 'string' }, description: 'List of phone numbers to mention in the message', optional: true, }, replyTo: { type: 'string', description: 'ID of the message being replied to', optional: true, }, isForwarded: { type: 'boolean', description: 'Whether the message should be marked as forwarded', optional: true, }, }, required: ['to', 'text'], }, handler: async (args: any) => { const input = validateInput(sendTextMessageSchema, args) as SendTextMessageInput; logger.info('Sending text message', { to: input.to, textLength: input.text.length }); const result = await wsapiClient.post('/messages/text', input); logger.info('Text message sent successfully', { messageId: result.id }); return { success: true, messageId: result.id, message: 'Text message sent successfully', }; }, };
- src/validation/schemas.ts:12-18 (schema)Zod validation schema (sendTextMessageSchema) used in the handler for input validation, defining structure and constraints for the tool arguments.export const sendTextMessageSchema = z.object({ to: chatIdSchema, text: z.string().min(1).max(4096), mentions: z.array(phoneNumberSchema).optional(), replyTo: messageIdSchema.optional(), isForwarded: z.boolean().optional(), });
- src/server.ts:57-76 (registration)Registration logic in the MCP server setup where messagingTools (containing whatsapp_send_text) is added to the tools Map for handling list_tools and call_tool requests.const toolCategories = [ messagingTools, contactTools, groupTools, chatTools, sessionTools, instanceTools, accountTools, ]; toolCategories.forEach(category => { Object.values(category).forEach(tool => { if (this.tools.has(tool.name)) { logger.warn(`Tool ${tool.name} already registered, skipping`); return; } this.tools.set(tool.name, tool); logger.debug(`Registered tool: ${tool.name}`); }); });
- src/server.ts:15-15 (registration)Import of messagingTools which includes the whatsapp_send_text handler.import { messagingTools } from './tools/messaging.js';
- src/validation/schemas.ts:305-312 (helper)validateInput helper function used in the handler to validate arguments against the Zod schema.export function validateInput<T>(schema: z.ZodSchema<T>, data: unknown): T { const result = schema.safeParse(data); if (!result.success) { const errors = result.error.errors.map(err => `${err.path.join('.')}: ${err.message}`); throw new Error(`Validation failed: ${errors.join(', ')}`); } return result.data; }