send_text
Send a text message to a WhatsApp contact or group. Provide session ID, target chat ID, and text content.
Instructions
Send a text message to a WhatsApp chat. chatId format: 5511999999999@c.us for contacts or 5511999999999-1234567890@g.us for groups.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sessionId | Yes | Session ID to send from | |
| chatId | Yes | Target chat ID | |
| text | Yes | Message text content |
Implementation Reference
- src/tools/messages.ts:5-24 (registration)The tool 'send_text' is registered via server.registerTool with name 'send_text', including its inputSchema (sessionId, chatId, text) and handler function.
export function registerMessageTools(server: McpServer) { server.registerTool( "send_text", { description: "Send a text message to a WhatsApp chat. chatId format: 5511999999999@c.us for contacts or 5511999999999-1234567890@g.us for groups.", inputSchema: { sessionId: z.string().describe("Session ID to send from"), chatId: z.string().describe("Target chat ID"), text: z.string().describe("Message text content"), }, }, async ({ sessionId, chatId, text }) => { const data = await openwaClient({ method: "POST", path: `/sessions/${sessionId}/messages/send-text`, body: { chatId, text }, }); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } ); - src/tools/messages.ts:16-23 (handler)The handler function that executes 'send_text' logic: calls openwaClient to POST to /sessions/{sessionId}/messages/send-text with chatId and text body.
async ({ sessionId, chatId, text }) => { const data = await openwaClient({ method: "POST", path: `/sessions/${sessionId}/messages/send-text`, body: { chatId, text }, }); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } - src/tools/messages.ts:10-14 (schema)The inputSchema for send_text defines three required string parameters: sessionId, chatId, and text.
inputSchema: { sessionId: z.string().describe("Session ID to send from"), chatId: z.string().describe("Target chat ID"), text: z.string().describe("Message text content"), }, - src/client.ts:10-35 (helper)The openwaClient helper function makes HTTP requests to the OpenWA API. It's used by the send_text handler to POST the message.
export async function openwaClient<T = unknown>(opts: RequestOptions): Promise<T> { const url = `${BASE_URL}${opts.path}`; const headers: Record<string, string> = { "Content-Type": "application/json", "X-API-Key": API_KEY, }; const res = await fetch(url, { method: opts.method, headers, body: opts.body ? JSON.stringify(opts.body) : undefined, }); const text = await res.text(); if (!res.ok) { throw new Error(`OpenWA API ${res.status}: ${text}`); } try { return JSON.parse(text) as T; } catch { return text as T; } } - src/index.ts:5-5 (registration)The registerMessageTools function is imported and called to register all message tools including send_text.
import { registerMessageTools } from "./tools/messages.js";