add_alert_subscription
Subscribe to an alert to receive notifications when it triggers. Specify the alert ID; optionally select a destination (defaults to email).
Instructions
Subscribe to an alert to receive notifications
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| alertId | Yes | ID of the alert to subscribe to | |
| destination_id | No | ID of the notification destination (optional, defaults to email) |
Implementation Reference
- src/index.ts:1079-1101 (handler)Handler function for the 'add_alert_subscription' tool. Parses input via addAlertSubscriptionSchema, optionally sets destination_id from params, and calls redashClient.addAlertSubscription(). Returns the subscription result or an error.
// Tool: add_alert_subscription const addAlertSubscriptionSchema = z.object({ alertId: z.coerce.number(), destination_id: z.coerce.number().optional() }); async function addAlertSubscription(params: z.infer<typeof addAlertSubscriptionSchema>) { try { const subscriptionData: CreateAlertSubscriptionRequest = {}; if (params.destination_id !== undefined) subscriptionData.destination_id = params.destination_id; const result = await redashClient.addAlertSubscription(params.alertId, subscriptionData); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; } catch (error) { logger.error(`Error adding subscription to alert ${params.alertId}: ${error}`); return { isError: true, content: [{ type: "text", text: `Error adding subscription to alert ${params.alertId}: ${error instanceof Error ? error.message : String(error)}` }] }; } } - src/index.ts:1080-1083 (schema)Zod schema for add_alert_subscription input validation: requires alertId (number) and optionally destination_id (number).
const addAlertSubscriptionSchema = z.object({ alertId: z.coerce.number(), destination_id: z.coerce.number().optional() }); - src/redashClient.ts:199-201 (schema)TypeScript type (CreateAlertSubscriptionRequest) defining the request body shape: optional destination_id.
export interface CreateAlertSubscriptionRequest { destination_id?: number; } - src/redashClient.ts:983-992 (helper)Client helper method addAlertSubscription() that POSTs to /api/alerts/{alertId}/subscriptions with optional subscription data.
// Add alert subscription async addAlertSubscription(alertId: number, data?: CreateAlertSubscriptionRequest): Promise<AlertSubscription> { try { const response = await this.client.post(`/api/alerts/${alertId}/subscriptions`, data || {}); return response.data; } catch (error) { logger.error(`Error adding subscription to alert ${alertId}: ${error}`); throw new Error(`Failed to add subscription to alert ${alertId}: ${error instanceof Error ? error.message : String(error)}`); } } - src/index.ts:2475-2477 (registration)MCP tool dispatch: case 'add_alert_subscription' in the CallToolRequestSchema handler routes the request to addAlertSubscription() with validated args.
case "add_alert_subscription": logger.debug(`Handling add_alert_subscription`); return await addAlertSubscription(addAlertSubscriptionSchema.parse(args));