Handle Label
handle_labelAssign or unassign a WhatsApp label to a chat by providing the chat number, label ID, and action (add or remove). Requires WhatsApp Business instance.
Instructions
Add or remove a WhatsApp label from a chat via the pinned instance (requires WhatsApp Business).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| number | Yes | Recipient JID or phone number (e.g. 5511999999999 or group@g.us) | |
| labelId | Yes | Label ID to add or remove (get IDs from find_labels) | |
| action | Yes | add: assign label to chat; remove: unassign label from chat |
Implementation Reference
- src/tools/handle-label.ts:13-35 (handler)Registration function (registerHandleLabel) that creates the 'handle_label' tool. The handler makes a POST request to /label/handleLabel/{instanceName} with number, labelId, and action (add/remove) to assign or unassign a WhatsApp label from a chat.
export function registerHandleLabel(server: McpServer, client: EvolutionClient): void { server.registerTool( "handle_label", { title: "Handle Label", description: "Add or remove a WhatsApp label from a chat via the pinned instance (requires WhatsApp Business).", inputSchema: schema, }, async (args) => { try { const data = await client.post(`/label/handleLabel/${client.instanceName}`, { number: args.number, labelId: args.labelId, action: args.action, }); 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/handle-label.ts:7-11 (schema)Input schema for the handle_label tool: number (PhoneOrJidSchema), labelId (string), and action (enum: add/remove).
const schema = { number: PhoneOrJidSchema, labelId: z.string().min(1).describe("Label ID to add or remove (get IDs from find_labels)"), action: z.enum(["add", "remove"]).describe("add: assign label to chat; remove: unassign label from chat"), }; - src/tools/index.ts:70-70 (registration)Import of registerHandleLabel from handle-label.js.
import { registerHandleLabel } from "./handle-label.js"; - src/tools/index.ts:143-143 (registration)Call to registerHandleLabel(server, client) inside registerAllTools, registering the tool with the MCP server.
registerHandleLabel(server, client); - src/schemas.ts:8-11 (helper)PhoneOrJidSchema used as the type validator for the 'number' parameter of handle_label.
export const PhoneOrJidSchema = z .string() .min(1) .describe("Recipient JID or phone number (e.g. 5511999999999 or group@g.us)");