Skip to main content
Glama

waha_get_chats

Retrieve recent WhatsApp chats with ID, name, message preview, and unread count. Filter by chat IDs or paginate results to manage conversations efficiently.

Instructions

Get overview of recent WhatsApp chats. Returns chat ID, name, last message preview, and unread count. Default limit is 10 chats.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNoNumber of chats to retrieve (default: 10, max: 100)
offsetNoOffset for pagination
chatIdsNoOptional filter for specific chat IDs (format: number@c.us)

Implementation Reference

  • The primary handler function for the 'waha_get_chats' MCP tool. It extracts parameters from the input arguments, calls the WAHAClient.getChatsOverview method to fetch chat data from the WAHA API, formats the response using formatChatsOverview, and returns a structured text content response.
    private async handleGetChats(args: any) { const limit = args.limit || 10; const offset = args.offset; const chatIds = args.chatIds; const chats = await this.wahaClient.getChatsOverview({ limit, offset, ids: chatIds, }); const formattedResponse = formatChatsOverview(chats); return { content: [ { type: "text", text: formattedResponse, }, ], }; }
  • The input schema and metadata definition for the 'waha_get_chats' tool, provided in the ListTools MCP response. Defines parameters like limit, offset, and chatIds with descriptions and defaults.
    name: "waha_get_chats", description: "Get overview of recent WhatsApp chats. Returns chat ID, name, last message preview, and unread count. Default limit is 10 chats.", inputSchema: { type: "object", properties: { limit: { type: "number", description: "Number of chats to retrieve (default: 10, max: 100)", default: 10, }, offset: { type: "number", description: "Offset for pagination", }, chatIds: { type: "array", items: { type: "string" }, description: "Optional filter for specific chat IDs (format: number@c.us)", }, }, }, },
  • src/index.ts:1051-1053 (registration)
    Tool dispatch registration in the CallToolRequestSchema handler switch statement. Routes calls to 'waha_get_chats' to the handleGetChats method.
    case "waha_get_chats": return await this.handleGetChats(args); case "waha_get_messages":
  • Helper function that formats the array of ChatOverview objects into a human-readable string for LLM consumption, used by the tool handler.
    export function formatChatsOverview(chats: ChatOverview[]): string { if (chats.length === 0) { return "No chats found."; } const sections = chats.map((chat, index) => { return `\n[Chat ${index + 1}]\n${formatChatOverview(chat)}`; }); return `Found ${chats.length} chat${chats.length > 1 ? 's' : ''}:\n${sections.join('\n')}`; }
  • Underlying WAHA API client method that performs the HTTP GET request to /api/{session}/chats/overview with query parameters and returns the raw ChatOverview array, called by the tool handler.
    async getChatsOverview( params: GetChatsOverviewParams = {} ): Promise<ChatOverview[]> { const { limit = 10, offset, ids } = params; const queryParams: Record<string, any> = { limit: Math.min(limit, 100), // Max 100 offset, }; if (ids && ids.length > 0) { queryParams.ids = ids; } const queryString = this.buildQueryString(queryParams); const endpoint = `/api/${this.session}/chats/overview${queryString}`; return this.request<ChatOverview[]>(endpoint, { method: "GET", }); }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/seejux/waha-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server