get_contacts
Retrieve all contacts saved in a WhatsApp session by providing the session ID.
Instructions
List all contacts stored in the WhatsApp session
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sessionId | Yes | Session ID |
Implementation Reference
- src/tools/contacts.ts:14-17 (handler)The handler function for 'get_contacts' — makes a GET request to /sessions/{sessionId}/contacts and returns the result as text content.
async ({ sessionId }) => { const data = await openwaClient({ method: "GET", path: `/sessions/${sessionId}/contacts` }); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } - src/tools/contacts.ts:8-12 (schema)Input schema for 'get_contacts' — expects a single 'sessionId' parameter of type string.
{ description: "List all contacts stored in the WhatsApp session", inputSchema: { sessionId: z.string().describe("Session ID"), }, - src/tools/contacts.ts:6-18 (registration)Registration of the 'get_contacts' tool via server.registerTool in the registerContactTools function.
server.registerTool( "get_contacts", { description: "List all contacts stored in the WhatsApp session", inputSchema: { sessionId: z.string().describe("Session ID"), }, }, async ({ sessionId }) => { const data = await openwaClient({ method: "GET", path: `/sessions/${sessionId}/contacts` }); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } ); - src/index.ts:19-19 (registration)Where registerContactTools is called to register all contact-related tools, including 'get_contacts', on the McpServer.
registerContactTools(server); - src/client.ts:10-35 (helper)The openwaClient helper function used by the handler to make HTTP requests to the OpenWA API.
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; } }