logly_events
Retrieve custom event counts for a site, using events sent via logly('event', ...), over a configurable time period (days or date range).
Instructions
Custom event counts for a site (events sent via logly('event', ...)) over the given period.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| site | Yes | Logly site ID (slug). Call logly_list_sites to discover it. | |
| days | No | Days to look back: 7, 30 or 90. Defaults to 30. Ignored when 'from'/'to' are set. | |
| from | No | Range start, YYYY-MM-DD. Use together with 'to'. | |
| to | No | Range end, YYYY-MM-DD. Use together with 'from'. |
Implementation Reference
- index.js:83-89 (handler)The logly_events tool handler: calls the Logly API at /api/sites/{site}/events with a date range, returning custom event counts for the site.
tool( "logly_events", "Custom event counts for a site (events sent via logly('event', ...)) over the given period.", { site: siteArg, days: daysArg, from: fromArg, to: toArg }, ({ site, days, from, to }) => loglyApi(`/api/sites/${encodeURIComponent(site)}/events`, range({ days, from, to })) ); - index.js:47-51 (schema)Zod schemas reused by logly_events: siteArg (required string), daysArg (optional positive int), fromArg/toArg (optional date strings).
const siteArg = z.string().describe("Logly site ID (slug). Call logly_list_sites to discover it."); const daysArg = z.number().int().positive().optional() .describe("Days to look back: 7, 30 or 90. Defaults to 30. Ignored when 'from'/'to' are set."); const fromArg = z.string().optional().describe("Range start, YYYY-MM-DD. Use together with 'to'."); const toArg = z.string().optional().describe("Range end, YYYY-MM-DD. Use together with 'from'."); - index.js:37-45 (registration)Helper function that registers any tool with the McpServer. logly_events is registered via this helper on line 83.
function tool(name, description, shape, fn) { server.tool(name, description, shape, async (args) => { try { return { content: [{ type: "text", text: await fn(args || {}) }] }; } catch (e) { return { content: [{ type: "text", text: "Error: " + e.message }], isError: true }; } }); } - index.js:30-33 (helper)Date range helper: if explicit from/to provided, uses those; otherwise falls back to a days window (default 30). Used by logly_events to build query params.
function range({ days, from, to }) { if (from || to) return { from, to }; return { days: days ?? 30 }; } - index.js:8-27 (helper)Core API helper used by logly_events: authenticates with LOGLY_API_KEY, builds URL with query params, and fetches data from the Logly API.
async function loglyApi(path, params) { const key = process.env.LOGLY_API_KEY; if (!key) { throw new Error( "LOGLY_API_KEY is not set. Create one in Logly → Settings → API keys." ); } const url = new URL(BASE + path); for (const [k, v] of Object.entries(params || {})) { if (v !== undefined && v !== null && v !== "") url.searchParams.set(k, String(v)); } const res = await fetch(url, { headers: { Authorization: `Bearer ${key}`, Accept: "application/json" }, }); const text = await res.text(); if (!res.ok) { throw new Error(`Logly API ${res.status} on ${path}: ${text.slice(0, 300)}`); } return text; }