create_label
Create a new label or tag to organize your WhatsApp chats by session, name, and color.
Instructions
Create a new label/tag for organizing WhatsApp chats
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sessionId | Yes | Session ID | |
| name | Yes | Label name | |
| color | No | Label color hex code |
Implementation Reference
- src/tools/labels.ts:20-38 (registration)The tool is registered with the MCP server under the name 'create_label'.
server.registerTool( "create_label", { description: "Create a new label/tag for organizing WhatsApp chats", inputSchema: { sessionId: z.string().describe("Session ID"), name: z.string().describe("Label name"), color: z.string().optional().describe("Label color hex code"), }, }, async ({ sessionId, name, color }) => { const data = await openwaClient({ method: "POST", path: `/sessions/${sessionId}/labels`, body: { name, color }, }); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } ); - src/tools/labels.ts:30-38 (handler)The handler function that executes the 'create_label' tool logic: sends a POST request to the OpenWA API to create a new label with sessionId, name, and optional color.
async ({ sessionId, name, color }) => { const data = await openwaClient({ method: "POST", path: `/sessions/${sessionId}/labels`, body: { name, color }, }); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } ); - src/tools/labels.ts:22-29 (schema)Input schema for 'create_label' requiring sessionId (string), name (string), and optional color (hex string).
{ description: "Create a new label/tag for organizing WhatsApp chats", inputSchema: { sessionId: z.string().describe("Session ID"), name: z.string().describe("Label name"), color: z.string().optional().describe("Label color hex code"), }, }, - src/client.ts:10-35 (helper)Helper function used by the handler to make HTTP requests to the OpenWA API backend.
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:10-21 (registration)The label tool registration function is imported and invoked in the main entry point.
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); registerContactTools(server); registerWebhookTools(server); registerLabelTools(server);