Get Uptime Statistics
get_uptimeRetrieve uptime history and statistics for a registered MCP server by specifying its name and an optional time window from 1 to 720 hours.
Instructions
Get uptime history and statistics for a registered MCP server.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Server name | |
| hours | No |
Implementation Reference
- src/app.ts:481-522 (handler)The 'get_uptime' tool registration and handler in app.ts. It registers the tool with the MCP server, fetches uptime history via getUptimeHistory(), computes average response time, p50/p95 percentiles, and returns formatted response.
server.registerTool( 'get_uptime', { title: 'Get Uptime Statistics', description: 'Get uptime history and statistics for a registered MCP server.', inputSchema: GetUptimeSchema, annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false } }, async (input: GetUptimeInput) => { const history = getUptimeHistory(input.name, input.hours); const upCount = history.filter((row) => row.status === 'up').length; const responseTimes = history .map((row) => row.response_time_ms) .filter((value): value is number => value !== null) .sort((left, right) => left - right); const averageResponseTime = responseTimes.length > 0 ? Math.round(responseTimes.reduce((sum, value) => sum + value, 0) / responseTimes.length) : null; const p50 = responseTimes[Math.min(responseTimes.length - 1, Math.floor(responseTimes.length * 0.5))] ?? null; const p95 = responseTimes[ Math.min(responseTimes.length - 1, Math.floor(responseTimes.length * 0.95)) ] ?? null; return formatResponse({ name: input.name, period_hours: input.hours, total_checks: history.length, uptime_percent: history.length ? Math.round((upCount / history.length) * 100) : null, avg_response_time_ms: averageResponseTime, p50_response_time_ms: p50, p95_response_time_ms: p95, history: history.slice(-50) }); } - src/types.ts:43-46 (schema)Zod schema GetUptimeSchema defines input: name (string) and hours (number, 1-720, default 24). Also exports the inferred type GetUptimeInput.
export const GetUptimeSchema = z.object({ name: z.string().describe('Server name'), hours: z.number().int().min(1).max(720).default(24) }); - src/app.ts:481-492 (registration)Tool registration using server.registerTool('get_uptime', ...) with title, description, inputSchema, and annotations.
server.registerTool( 'get_uptime', { title: 'Get Uptime Statistics', description: 'Get uptime history and statistics for a registered MCP server.', inputSchema: GetUptimeSchema, annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false } }, - src/registry.ts:308-320 (helper)getUptimeHistory() helper function that queries the health_checks table for records matching server name and time window, ordered by timestamp.
export function getUptimeHistory(name: string, hours: number): HealthRecord[] { const since = Date.now() - hours * 60 * 60 * 1000; return getDb() .prepare( ` SELECT id, server_name, timestamp, status, response_time_ms, tool_count, error_message, tools_snapshot FROM health_checks WHERE server_name = ? AND timestamp > ? ORDER BY timestamp ASC, id ASC ` ) .all(name, since) as HealthRecord[]; } - src/registry.ts:378-400 (helper)getUptimePercent() helper used by alerts to calculate uptime percentage for a given server over a specified time window.
export function getUptimePercent( db: Database.Database, name: string, hours: number ): number | null { const since = Date.now() - hours * 60 * 60 * 1000; const rows = db .prepare( ` SELECT status FROM health_checks WHERE server_name = ? AND timestamp > ? ` ) .all(name, since) as Array<{ status: string }>; if (!rows.length) { return null; } const upCount = rows.filter((row) => row.status === 'up').length; return Math.round((upCount / rows.length) * 100); }