check_number
Check if a phone number is registered on WhatsApp to confirm account existence.
Instructions
Check if a phone number is registered on WhatsApp
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sessionId | Yes | Session ID | |
| phone | Yes | Phone number in international format without + prefix |
Implementation Reference
- src/tools/contacts.ts:44-48 (handler)The async handler function that executes the 'check_number' tool logic. It takes sessionId and phone, calls the OpenWA API endpoint `/sessions/{sessionId}/contacts/{phone}/check` via the openwaClient helper, and returns the result as text content.
async ({ sessionId, phone }) => { const data = await openwaClient({ method: "GET", path: `/sessions/${sessionId}/contacts/${phone}/check` }); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } ); - src/tools/contacts.ts:37-43 (schema)Input schema for the 'check_number' tool, defining sessionId (string) and phone (string in international format without + prefix) as required parameters, with a description stating it checks if a phone number is registered on WhatsApp.
{ description: "Check if a phone number is registered on WhatsApp", inputSchema: { sessionId: z.string().describe("Session ID"), phone: z.string().describe("Phone number in international format without + prefix"), }, }, - src/tools/contacts.ts:35-48 (registration)Registration of the 'check_number' tool on the McpServer via server.registerTool(), binding the tool name, its schema, and the handler function together.
server.registerTool( "check_number", { description: "Check if a phone number is registered on WhatsApp", inputSchema: { sessionId: z.string().describe("Session ID"), phone: z.string().describe("Phone number in international format without + prefix"), }, }, async ({ sessionId, phone }) => { const data = await openwaClient({ method: "GET", path: `/sessions/${sessionId}/contacts/${phone}/check` }); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } ); - src/tools/contacts.ts:5-18 (registration)The registerContactTools function is called from src/index.ts (line 19), which registers all contact-related tools including 'check_number' on the MCP server.
export function registerContactTools(server: McpServer) { 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/client.ts:10-35 (helper)The openwaClient helper function used by the 'check_number' handler to make HTTP requests to the OpenWA backend 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; } }