create_group
Create a new WhatsApp group by specifying a group name and adding participants using their phone IDs.
Instructions
Create a new WhatsApp group with specified participants
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sessionId | Yes | Session ID | |
| name | Yes | Group name | |
| participants | Yes | Array of participant phone IDs to add |
Implementation Reference
- src/tools/groups.ts:30-38 (handler)The handler function for the 'create_group' tool. It accepts sessionId, name, and participants, then makes a POST request to /sessions/{sessionId}/groups with the group name and participants array.
async ({ sessionId, name, participants }) => { const data = await openwaClient({ method: "POST", path: `/sessions/${sessionId}/groups`, body: { name, participants }, }); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } ); - src/tools/groups.ts:24-28 (schema)Input schema/type definitions for the 'create_group' tool using Zod: sessionId (string), name (string), and participants (array of strings).
inputSchema: { sessionId: z.string().describe("Session ID"), name: z.string().describe("Group name"), participants: z.array(z.string()).describe("Array of participant phone IDs to add"), }, - src/tools/groups.ts:20-38 (registration)Registration of the 'create_group' tool on the MCP server via server.registerTool().
server.registerTool( "create_group", { description: "Create a new WhatsApp group with specified participants", inputSchema: { sessionId: z.string().describe("Session ID"), name: z.string().describe("Group name"), participants: z.array(z.string()).describe("Array of participant phone IDs to add"), }, }, async ({ sessionId, name, participants }) => { const data = await openwaClient({ method: "POST", path: `/sessions/${sessionId}/groups`, body: { name, participants }, }); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } ); - src/index.ts:7-18 (registration)Import of registerGroupTools from groups.ts and invocation at line 18 to register all group tools including 'create_group'.
import { registerGroupTools } from "./tools/groups.js"; import { registerContactTools } from "./tools/contacts.js"; import { registerWebhookTools } from "./tools/webhooks.js"; import { registerLabelTools } from "./tools/labels.js"; import { registerMediaTools } from "./tools/media.js"; const server = new McpServer({ name: "openwa-mcp", version: "1.0.0" }); registerSessionTools(server); registerMessageTools(server); registerBulkTools(server); registerGroupTools(server); - src/client.ts:10-30 (helper)The openwaClient helper function used by the handler to make HTTP requests to the OpenWA API.
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 {