waha_get_all_contacts
Retrieve and organize all WhatsApp contacts with pagination, sorting options, and result limits for efficient contact management.
Instructions
List all contacts with pagination.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sortBy | No | Sort field (default: id) | |
| sortOrder | No | Sort order (default: asc) | |
| limit | No | Limit results (default: 100, max: 100) | |
| offset | No | Offset for pagination |
Implementation Reference
- src/index.ts:2451-2467 (handler)Core handler function for the 'waha_get_all_contacts' MCP tool. Processes input arguments, invokes WAHAClient.getAllContacts(), and returns a formatted text content block with the JSON-stringified list of contacts.private async handleGetAllContacts(args: any) { const contacts = await this.wahaClient.getAllContacts({ sortBy: args.sortBy, sortOrder: args.sortOrder, limit: args.limit, offset: args.offset, }); return { content: [ { type: "text", text: `Found ${contacts.length} contact(s):\n${JSON.stringify(contacts, null, 2)}`, }, ], }; }
- src/index.ts:898-923 (schema)Input schema definition for the tool, specifying optional parameters for sorting (by id or name), sort order (asc/desc), limit (max 100), and offset for pagination.description: "Sort order (default: asc)", }, limit: { type: "number", description: "Limit results (default: 100, max: 100)", }, offset: { type: "number", description: "Offset for pagination", }, }, }, }, { name: "waha_check_contact_exists", description: "Check if phone number is registered on WhatsApp.", inputSchema: { type: "object", properties: { phone: { type: "string", description: "Phone number to check (e.g., '1234567890')", }, }, required: ["phone"], },
- src/index.ts:1137-1138 (registration)Tool registration in the MCP CallToolRequestSchema handler's switch statement, mapping the tool name to its handler method.case "waha_check_contact_exists": return await this.handleCheckContactExists(args);
- src/client/waha-client.ts:1251-1272 (helper)WAHAClient helper method that constructs and sends the GET request to the WAHA API endpoint /api/contacts/all with session, sorting, and pagination query parameters.async getAllContacts(params?: { sortBy?: "id" | "name"; sortOrder?: "asc" | "desc"; limit?: number; offset?: number; }): Promise<any[]> { const queryParams: Record<string, any> = { session: this.session }; if (params?.sortBy) queryParams.sortBy = params.sortBy; if (params?.sortOrder) queryParams.sortOrder = params.sortOrder; if (params?.limit) queryParams.limit = Math.min(params.limit, 100); if (params?.offset) queryParams.offset = params.offset; const queryString = this.buildQueryString(queryParams); const endpoint = `/api/contacts/all${queryString}`; return this.request<any[]>(endpoint, { method: "GET", }); }