create_monitor
Set up automated URL monitoring to detect downtime by scheduling periodic checks and configuring alerts for failures.
Instructions
Create a new uptime monitor that periodically checks a URL and alerts on failure.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Display name for the monitor | |
| url | Yes | URL to monitor | |
| checkInterval | No | Check interval in seconds (default 180) | |
| method | No | HTTP method (default GET) | GET |
| expectedStatusCode | No | Expected HTTP status code (default 200) |
Implementation Reference
- src/index.ts:98-104 (handler)The create_monitor handler function that executes when the tool is called. It constructs a request with name, url, checkInterval, method, and expectedStatusCode, then POSTs to /monitors endpoint via apiRequest.
async ({ name, url, checkInterval, method, expectedStatusCode }) => { const data = await apiRequest("/monitors", { method: "POST", body: JSON.stringify({ name, url, checkInterval, method, expectedStatusCode }), }); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } - src/index.ts:85-91 (schema)Input schema validation for create_monitor using zod. Defines required fields: name (string), url (string with URL validation), and optional fields: checkInterval (number, default 180), method (enum, default GET), expectedStatusCode (number, default 200).
{ name: z.string().describe("Display name for the monitor"), url: z.string().url().describe("URL to monitor"), checkInterval: z.number().int().positive().optional().default(180).describe("Check interval in seconds (default 180)"), method: z.enum(["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD"]).optional().default("GET").describe("HTTP method (default GET)"), expectedStatusCode: z.number().int().optional().default(200).describe("Expected HTTP status code (default 200)"), }, - src/index.ts:82-105 (registration)Full tool registration for create_monitor using server.tool(). Includes tool name, description, schema definition, execution hints (readOnlyHint: false, destructiveHint: true), and the async handler function.
server.tool( "create_monitor", "Create a new uptime monitor that periodically checks a URL and alerts on failure.", { name: z.string().describe("Display name for the monitor"), url: z.string().url().describe("URL to monitor"), checkInterval: z.number().int().positive().optional().default(180).describe("Check interval in seconds (default 180)"), method: z.enum(["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD"]).optional().default("GET").describe("HTTP method (default GET)"), expectedStatusCode: z.number().int().optional().default(200).describe("Expected HTTP status code (default 200)"), }, { readOnlyHint: false, destructiveHint: true, openWorldHint: false, }, async ({ name, url, checkInterval, method, expectedStatusCode }) => { const data = await apiRequest("/monitors", { method: "POST", body: JSON.stringify({ name, url, checkInterval, method, expectedStatusCode }), }); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } ); - src/index.ts:20-42 (helper)The apiRequest helper function used by create_monitor handler. Handles API authentication via Bearer token, sets Content-Type headers, makes HTTP requests to the CronAlert API, and handles error responses.
async function apiRequest( path: string, options: RequestInit = {} ): Promise<unknown> { const apiKey = getApiKey(); const url = `${API_BASE}${path}`; const response = await fetch(url, { ...options, headers: { "Content-Type": "application/json", Authorization: `Bearer ${apiKey}`, ...options.headers, }, }); if (!response.ok) { const body = await response.text(); throw new Error(`API error ${response.status}: ${body}`); } return response.json(); }