get_session_qr
Retrieve QR code data to authenticate a WhatsApp session by scanning with the mobile app.
Instructions
Get the QR code data for authenticating a WhatsApp session. Use this when a session needs to be scanned with WhatsApp mobile.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sessionId | Yes | ID of the session to get QR for |
Implementation Reference
- src/tools/sessions.ts:74-86 (registration)Tool 'get_session_qr' is registered via server.registerTool with description, input schema (sessionId), and handler.
server.registerTool( "get_session_qr", { description: "Get the QR code data for authenticating a WhatsApp session. Use this when a session needs to be scanned with WhatsApp mobile.", inputSchema: { sessionId: z.string().describe("ID of the session to get QR for"), }, }, async ({ sessionId }) => { const data = await openwaClient({ method: "GET", path: `/sessions/${sessionId}/qr` }); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } ); - src/tools/sessions.ts:78-80 (schema)Input schema for get_session_qr: sessionId (string) via Zod.
inputSchema: { sessionId: z.string().describe("ID of the session to get QR for"), }, - src/tools/sessions.ts:82-85 (handler)Handler function that makes a GET request to /sessions/{sessionId}/qr via openwaClient and returns the QR code data as JSON text.
async ({ sessionId }) => { const data = await openwaClient({ method: "GET", path: `/sessions/${sessionId}/qr` }); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } - src/client.ts:10-34 (helper)The openwaClient helper function that performs HTTP requests to the OpenWA API. Used by the handler to fetch QR data.
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; } - src/index.ts:4-4 (registration)Registration is triggered by calling registerSessionTools(server) in the main entry point.
import { registerSessionTools } from "./tools/sessions.js";