get_session_data_values
Retrieve aggregated counts of session property values for your website. Filter by property name and date range to analyze session data and uncover usage patterns.
Instructions
Get session data values (aggregated counts for session properties) for a website
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| websiteId | Yes | Website UUID | |
| startAt | Yes | Start timestamp in milliseconds | |
| endAt | Yes | End timestamp in milliseconds | |
| propertyName | No | Filter by property name |
Implementation Reference
- src/tools/sessions.ts:73-91 (handler)The handler function that executes the 'get_session_data_values' tool logic. It calls GET /api/websites/{websiteId}/session-data/values with startAt, endAt, and optional propertyName query parameters, returning aggregated session data values.
server.tool( "get_session_data_values", "Get session data values (aggregated counts for session properties) for a website", { websiteId: z.string().describe("Website UUID"), startAt: z.number().describe("Start timestamp in milliseconds"), endAt: z.number().describe("End timestamp in milliseconds"), propertyName: z.string().optional().describe("Filter by property name"), }, async ({ websiteId, startAt, endAt, propertyName }) => { const data = await client.call( "GET", `/api/websites/${websiteId}/session-data/values`, undefined, { startAt, endAt, propertyName } ); return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] }; } ); - src/tools/sessions.ts:76-81 (schema)Input schema definition using Zod for the tool, defining websiteId (string), startAt (number), endAt (number), and optional propertyName (string) parameters.
{ websiteId: z.string().describe("Website UUID"), startAt: z.number().describe("Start timestamp in milliseconds"), endAt: z.number().describe("End timestamp in milliseconds"), propertyName: z.string().optional().describe("Filter by property name"), }, - src/tools/sessions.ts:73-92 (registration)Registration of the tool via server.tool() call with the name 'get_session_data_values' and description. The containing function registerSessionTools is called in src/index.ts line 31.
server.tool( "get_session_data_values", "Get session data values (aggregated counts for session properties) for a website", { websiteId: z.string().describe("Website UUID"), startAt: z.number().describe("Start timestamp in milliseconds"), endAt: z.number().describe("End timestamp in milliseconds"), propertyName: z.string().optional().describe("Filter by property name"), }, async ({ websiteId, startAt, endAt, propertyName }) => { const data = await client.call( "GET", `/api/websites/${websiteId}/session-data/values`, undefined, { startAt, endAt, propertyName } ); return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] }; } ); } - src/client.ts:68-113 (helper)The UmamiClient.call() helper method used by the handler to make authenticated HTTP requests to the Umami API, handling tokens, query parameters, and error responses.
async call( method: string, path: string, body?: Record<string, unknown>, query?: Record<string, string | number | boolean | undefined> ): Promise<unknown> { this.ensureConfigured(); const token = await this.getToken(); let url = `${this.config.baseUrl}${path}`; if (query) { const params = new URLSearchParams(); for (const [k, v] of Object.entries(query)) { if (v !== undefined && v !== null && v !== "") { params.set(k, String(v)); } } const qs = params.toString(); if (qs) url += `?${qs}`; } const headers: Record<string, string> = { Authorization: `Bearer ${token}`, }; if (body) { headers["Content-Type"] = "application/json"; } const res = await fetch(url, { method, headers, body: body ? JSON.stringify(body) : undefined, signal: AbortSignal.timeout(30_000), }); if (!res.ok) { const text = await res.text().catch(() => ""); throw new Error(`Umami API error ${method} ${path} (${res.status}): ${text}`); } // Some endpoints return 200 with no body (e.g. DELETE) const contentType = res.headers.get("content-type") || ""; if (contentType.includes("application/json")) { return res.json(); }