create_alert
Create alerts in Redash to monitor query results and get notified when specified conditions are met.
Instructions
Create a new alert in Redash. Alerts notify you when a query result meets a specified condition.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Name of the alert | |
| query_id | Yes | ID of the query to monitor | |
| options | Yes | Alert options including column to monitor, operator (e.g., 'greater than', 'less than', 'equals'), and threshold value | |
| rearm | No | Number of seconds to wait before triggering again (null for never) |
Implementation Reference
- src/index.ts:961-980 (handler)The createAlert handler function that executes the 'create_alert' tool logic. It takes validated parameters (name, query_id, options, rearm), constructs a CreateAlertRequest, and calls redashClient.createAlert().
async function createAlert(params: z.infer<typeof createAlertSchema>) { try { const alertData: CreateAlertRequest = { name: params.name, query_id: params.query_id, options: params.options, rearm: params.rearm }; const result = await redashClient.createAlert(alertData); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; } catch (error) { logger.error(`Error creating alert: ${error}`); return { isError: true, content: [{ type: "text", text: `Error creating alert: ${error instanceof Error ? error.message : String(error)}` }] }; } } - src/index.ts:948-959 (schema)The Zod schema for validating create_alert input parameters. Defines fields: name (string), query_id (number), options (object with column, op, value, optional custom_subject/custom_body), and optional rearm.
const createAlertSchema = z.object({ name: z.string(), query_id: z.coerce.number(), options: z.object({ column: z.string(), op: z.string(), value: z.union([z.coerce.number(), z.string()]), custom_subject: z.string().optional(), custom_body: z.string().optional() }), rearm: z.coerce.number().nullable().optional() }); - src/index.ts:1979-2003 (registration)Registration of the 'create_alert' tool in the ListToolsRequestSchema handler, including its description and input schema for MCP tool discovery.
{ name: "create_alert", description: "Create a new alert in Redash. Alerts notify you when a query result meets a specified condition.", inputSchema: { type: "object", properties: { name: { type: "string", description: "Name of the alert" }, query_id: { type: "number", description: "ID of the query to monitor" }, options: { type: "object", description: "Alert options including column to monitor, operator (e.g., 'greater than', 'less than', 'equals'), and threshold value", properties: { column: { type: "string", description: "Column name to monitor" }, op: { type: "string", description: "Comparison operator: 'greater than', 'less than', 'equals', 'not equals', etc." }, value: { type: ["number", "string"], description: "Threshold value to compare against" }, custom_subject: { type: "string", description: "Custom email subject" }, custom_body: { type: "string", description: "Custom email body" } }, required: ["column", "op", "value"] }, rearm: { type: ["number", "null"], description: "Number of seconds to wait before triggering again (null for never)" } }, required: ["name", "query_id", "options"] } }, - src/index.ts:2455-2457 (registration)Dispatch handler in CallToolRequestSchema that routes the 'create_alert' tool call to the createAlert function with validated args.
case "create_alert": logger.debug(`Handling create_alert`); return await createAlert(createAlertSchema.parse(args)); - src/redashClient.ts:158-169 (helper)The CreateAlertRequest interface used as data contract for the API call in redashClient.createAlert().
export interface CreateAlertRequest { name: string; query_id: number; options: { column: string; op: string; value: number | string; custom_subject?: string; custom_body?: string; }; rearm?: number | null; }