Leave Group
leave_groupLeave a WhatsApp group by providing the group JID. Removes the pinned instance from the specified group.
Instructions
Leave a WhatsApp group via the pinned instance.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| groupJid | Yes | Group JID to leave (e.g. 120363000000000000@g.us) |
Implementation Reference
- src/tools/leave-group.ts:10-30 (handler)The registerLeaveGroup function registers the 'leave_group' tool with the MCP server. The handler sends a DELETE request to /group/leaveGroup/{instanceName}?groupJid={encodedJid} via the EvolutionClient, returning the response as text content.
export function registerLeaveGroup(server: McpServer, client: EvolutionClient): void { server.registerTool( "leave_group", { title: "Leave Group", description: "Leave a WhatsApp group via the pinned instance.", inputSchema: schema, }, async (args) => { try { const data = await client.delete( `/group/leaveGroup/${client.instanceName}?groupJid=${encodeURIComponent(args.groupJid)}` ); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } catch (e) { if (e instanceof McpError) return { isError: true, content: [{ type: "text" as const, text: e.message }] }; throw e; } } ); } - src/tools/leave-group.ts:6-8 (schema)Input schema for 'leave_group': requires a single 'groupJid' parameter (string) describing the WhatsApp group JID to leave.
const schema = { groupJid: z.string().min(1).describe("Group JID to leave (e.g. 120363000000000000@g.us)"), }; - src/tools/index.ts:54-54 (registration)Import of registerLeaveGroup from the leave-group module into the central tools index.
import { registerLeaveGroup } from "./leave-group.js"; - src/tools/index.ts:127-127 (registration)Registration call: registerLeaveGroup(server, client) within registerAllTools, called from src/server.ts line 16.
registerLeaveGroup(server, client); - src/evolution-client.ts:28-59 (helper)EvolutionClient.delete method is the HTTP helper used by the leave_group handler to send the DELETE request to the Evolution API.
async delete<T = unknown>(path: string, body?: unknown): Promise<T> { return this.request<T>("DELETE", path, body); } private async request<T>(method: string, path: string, body?: unknown): Promise<T> { const url = `${this.baseUrl}${path}`; const headers: Record<string, string> = { apikey: this.apiKey, "Content-Type": "application/json", }; const res = await fetch(url, { method, headers, body: body !== undefined ? JSON.stringify(body) : undefined, }); const text = await res.text(); if (!res.ok) { throw new McpError( ErrorCode.InternalError, `Evolution API error ${res.status}: ${text}` ); } try { return JSON.parse(text) as T; } catch { return text as unknown as T; } }