get_sessions
Retrieve all active WhatsApp sessions to manage and monitor your connected messaging accounts.
Instructions
List all WhatsApp sessions currently managed by OpenWA
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "get_sessions"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/sessions.ts:12-15 (handler)The async handler function for the 'get_sessions' tool. It calls the OpenWA API GET /sessions endpoint and returns the list of all WhatsApp sessions as formatted JSON text.
async () => { const data = await openwaClient({ method: "GET", path: "/sessions" }); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } - src/tools/sessions.ts:8-10 (schema)The input schema definition for 'get_sessions'. It has an empty object (no inputs required) and a description explaining the tool lists all WhatsApp sessions.
{ description: "List all WhatsApp sessions currently managed by OpenWA", inputSchema: {}, - src/tools/sessions.ts:6-16 (registration)Registration of the 'get_sessions' tool via server.registerTool(), which wires the tool name, schema, and handler together.
server.registerTool( "get_sessions", { description: "List all WhatsApp sessions currently managed by OpenWA", inputSchema: {}, }, async () => { const data = await openwaClient({ method: "GET", path: "/sessions" }); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } ); - src/index.ts:15-22 (registration)Where registerSessionTools (which includes get_sessions registration) is called in the main entry point.
registerSessionTools(server); registerMessageTools(server); registerBulkTools(server); registerGroupTools(server); registerContactTools(server); registerWebhookTools(server); registerLabelTools(server); registerMediaTools(server); - src/client.ts:10-35 (helper)The openwaClient helper function that the get_sessions handler uses to make the actual HTTP GET request 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; } }