check_auth_status
Verify whether your WhatsApp client is authenticated and ready. This status check enables you to confirm connection before sending messages or managing contacts, ensuring operations proceed only when authenticated.
Instructions
Check if the WhatsApp client is authenticated and ready
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/auth.ts:166-203 (handler)The `checkAuthStatus` function is the actual handler for the 'check_auth_status' tool. It calls `whatsappService.isAuthenticated()` and `whatsappService.isReady()` to determine the current authentication state, then returns a human-readable text result indicating whether the user is authenticated, ready, or needs to authenticate via QR code.
async function checkAuthStatus( whatsappService: WhatsAppService, ): Promise<CallToolResult> { try { const isAuthenticated = whatsappService.isAuthenticated(); const isReady = whatsappService.isReady(); log.info( `Auth status checked: ${isAuthenticated ? "authenticated" : "not authenticated"}, ` + `ready: ${isReady ? "yes" : "no"}`, ); return { content: [ { type: "text", text: !isAuthenticated ? "You are not authenticated. Use get_qr_code to authenticate." : isReady ? "Authenticated and ready." : "Authenticated, but not ready yet. Please wait a few seconds and try again.", }, ], isError: false, }; } catch (error) { log.error("Error checking authentication status:", error); return { content: [ { type: "text", text: `Error checking authentication status: ${error instanceof Error ? error.message : String(error)}`, }, ], isError: true, }; } } - src/tools/auth.ts:29-36 (registration)The tool is registered with the MCP server via `server.tool('check_auth_status', ...)` inside the `registerAuthTools` function. It has no input schema and delegates to the `checkAuthStatus` handler.
server.tool( "check_auth_status", "Check if the WhatsApp client is authenticated and ready", {}, async (): Promise<CallToolResult> => { return await checkAuthStatus(whatsappService); }, ); - src/server.ts:241-261 (registration)The `registerAuthTools` function is called in `WhatsAppMcpServer.registerTools()` to register all auth-related tools including 'check_auth_status'.
private registerTools(server: McpServer) { log.info("Registering MCP tools..."); registerAuthTools(server, this.whatsapp); registerContactTools(server, this.whatsapp); registerChatTools(server, this.whatsapp); registerMessageTools(server, this.whatsapp); registerMediaTools(server, this.whatsapp); // Remove example dummy tool if no longer needed, or keep for testing // this.server.tool('ping', async () => ({ // content: [{ type: 'text', text: 'pong' }], // })); // Let's keep ping for now for basic testing server.tool("ping", async () => ({ content: [{ type: "text", text: "pong" }], })); this.overrideListToolsHandler(server); log.info("MCP tools registered."); } - src/server.ts:55-200 (helper)Execution metadata in `TOOL_EXECUTION_METADATA` defines 'check_auth_status' as read-only, idempotent, and not open-world. This metadata is attached to the tool listing response via the custom `ListToolsRequestSchema` handler.
const TOOL_EXECUTION_METADATA: Record<string, ExecutionMetadata> = { ping: { readOnlyHint: true, idempotentHint: true, openWorldHint: false, }, get_qr_code: { readOnlyHint: true, idempotentHint: true, openWorldHint: false, }, check_auth_status: { readOnlyHint: true, idempotentHint: true, openWorldHint: false, }, send_message: { readOnlyHint: false, idempotentHint: true, destructiveHint: false, openWorldHint: true, }, send_media: { readOnlyHint: false, idempotentHint: true, destructiveHint: false, openWorldHint: true, }, logout: { readOnlyHint: false, idempotentHint: true, destructiveHint: true, openWorldHint: false, }, force_resync: { readOnlyHint: false, idempotentHint: false, destructiveHint: true, openWorldHint: false, }, search_contacts: { readOnlyHint: true, idempotentHint: true, openWorldHint: true, }, resolve_contact: { readOnlyHint: true, idempotentHint: true, openWorldHint: true, }, get_contact_by_id: { readOnlyHint: true, idempotentHint: true, openWorldHint: false, }, get_profile_pic: { readOnlyHint: true, idempotentHint: true, openWorldHint: true, }, get_group_info: { readOnlyHint: true, idempotentHint: true, openWorldHint: true, }, list_chats: { readOnlyHint: true, idempotentHint: true, openWorldHint: false, }, list_system_chats: { readOnlyHint: true, idempotentHint: true, openWorldHint: false, }, list_groups: { readOnlyHint: true, idempotentHint: true, openWorldHint: false, }, get_chat_by_id: { readOnlyHint: true, idempotentHint: true, openWorldHint: false, }, get_direct_chat_by_contact_number: { readOnlyHint: true, idempotentHint: true, openWorldHint: false, }, get_chat_by_contact: { readOnlyHint: true, idempotentHint: true, openWorldHint: false, }, analyze_group_overlaps: { readOnlyHint: true, idempotentHint: true, openWorldHint: true, }, find_members_without_direct_chat: { readOnlyHint: true, idempotentHint: true, openWorldHint: true, }, find_members_not_in_contacts: { readOnlyHint: true, idempotentHint: true, openWorldHint: true, }, run_group_audit: { readOnlyHint: true, idempotentHint: true, openWorldHint: true, }, list_messages: { readOnlyHint: true, idempotentHint: true, openWorldHint: false, }, get_message_by_id: { readOnlyHint: true, idempotentHint: true, openWorldHint: false, }, search_messages: { readOnlyHint: true, idempotentHint: true, openWorldHint: false, }, get_message_context: { readOnlyHint: true, idempotentHint: true, openWorldHint: false, }, get_last_interaction: { readOnlyHint: true, idempotentHint: true, openWorldHint: false, }, download_media: { readOnlyHint: true, idempotentHint: true, openWorldHint: false, }, };