Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(alerts): add Discord as an insight alert destination (#63601)

Vasco de Krijgerb342a148bfed
diff --git a/frontend/src/lib/components/Alerts/alertNotificationLogic.test.ts b/frontend/src/lib/components/Alerts/alertNotificationLogic.test.ts
new file mode 100644
index 000000000000..a73fb4262861
--- /dev/null
+++ b/frontend/src/lib/components/Alerts/alertNotificationLogic.test.ts
@@ -0,0 +1,63 @@
+import { expectLogic } from 'kea-test-utils'
+
+import api from 'lib/api'
+import { ALERT_NOTIFICATION_TYPE_DISCORD } from 'lib/utils/alerts'
+
+import { initKeaTests } from '~/test/init'
+import { HogFunctionType } from '~/types'
+
+import { alertNotificationLogic } from './alertNotificationLogic'
+
+describe('alertNotificationLogic', () => {
+ let logic: ReturnType<typeof alertNotificationLogic.build>
+ let createSpy: jest.SpyInstance
+ let listSpy: jest.SpyInstance
+
+ beforeEach(() => {
+ initKeaTests()
+ listSpy = jest.spyOn(api.hogFunctions, 'list').mockResolvedValue({ results: [], count: 0 })
+ createSpy = jest
+ .spyOn(api.hogFunctions, 'create')
+ .mockImplementation(async (data) => ({ id: 'hf-1', ...data }) as HogFunctionType)
+ })
+
+ afterEach(() => {
+ logic?.unmount()
+ createSpy.mockRestore()
+ listSpy.mockRestore()
+ })
+
+ it('creates a Discord destination HogFunction end-to-end', async () => {
+ logic = alertNotificationLogic({ alertId: 'alert-123' })
+ logic.mount()
+
+ // Drive the inline editor: pick Discord, enter a webhook URL, stage it
+ logic.actions.setSelectedType(ALERT_NOTIFICATION_TYPE_DISCORD)
+ logic.actions.setWebhookUrl('https://discord.com/api/webhooks/123/abc')
+ logic.actions.addPendingNotification({
+ type: ALERT_NOTIFICATION_TYPE_DISCORD,
+ webhookUrl: 'https://discord.com/api/webhooks/123/abc',
+ })
+
+ await expectLogic(logic).toMatchValues({
+ pendingNotifications: [
+ { type: ALERT_NOTIFICATION_TYPE_DISCORD, webhookUrl: 'https://discord.com/api/webhooks/123/abc' },
+ ],
+ })
+
+ // Saving the alert flushes pending notifications through the real payload builder + API
+ logic.actions.createPendingHogFunctions('alert-123', 'Daily revenue check')
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(createSpy).toHaveBeenCalledTimes(1)
+ const payload = createSpy.mock.calls[0][0]
+ expect(payload.template_id).toBe('template-discord')
+ expect(payload.name).toBe('Daily revenue check: Discord')
+ expect(payload.enabled).toBe(true)
+ expect(payload.inputs?.webhookUrl).toEqual({ value: 'https://discord.com/api/webhooks/123/abc' })
+ expect(payload.inputs?.content?.value).toContain('{event.properties.alert_name}')
+
+ // Pending list clears once creation succeeds
+ await expectLogic(logic).toMatchValues({ pendingNotifications: [] })
+ })
+})
diff --git a/frontend/src/lib/components/Alerts/alertNotificationLogic.ts b/frontend/src/lib/components/Alerts/alertNotificationLogic.ts
index c1dad6c57853..2dfbfa009e3d 100644
--- a/frontend/src/lib/components/Alerts/alertNotificationLogic.ts
+++ b/frontend/src/lib/components/Alerts/alertNotificationLogic.ts
@@ -5,6 +5,7 @@ import api from 'lib/api'
import { integrationsLogic } from 'lib/integrations/integrationsLogic'
import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'
import {
+ ALERT_NOTIFICATION_TYPE_DISCORD,
ALERT_NOTIFICATION_TYPE_SLACK,
ALERT_NOTIFICATION_TYPE_WEBHOOK,
AlertNotificationType,
@@ -21,6 +22,7 @@ import type { alertNotificationLogicType } from './alertNotificationLogicType'
export const ALERT_NOTIFICATION_TYPE_OPTIONS = [
{ label: 'Slack', value: ALERT_NOTIFICATION_TYPE_SLACK },
+ { label: 'Discord', value: ALERT_NOTIFICATION_TYPE_DISCORD },
{ label: 'Webhook', value: ALERT_NOTIFICATION_TYPE_WEBHOOK },
]
diff --git a/frontend/src/lib/components/Alerts/views/InlineAlertNotifications.tsx b/frontend/src/lib/components/Alerts/views/InlineAlertNotifications.tsx
index 5a6edeb74674..429557b4db52 100644
--- a/frontend/src/lib/components/Alerts/views/InlineAlertNotifications.tsx
+++ b/frontend/src/lib/components/Alerts/views/InlineAlertNotifications.tsx
@@ -7,6 +7,7 @@ import { LemonButton, LemonInput, LemonSelect, LemonSkeleton, LemonTag } from '@
import { SlackChannelPicker, SlackNotConfiguredBanner } from 'lib/integrations/SlackIntegrationHelpers'
import { slackIntegrationLogic } from 'lib/integrations/slackIntegrationLogic'
import {
+ ALERT_NOTIFICATION_TYPE_DISCORD,
ALERT_NOTIFICATION_TYPE_SLACK,
ALERT_NOTIFICATION_TYPE_WEBHOOK,
PendingAlertNotification,
@@ -34,6 +35,10 @@ function getHogFunctionDestination(
if (channelValue) {
return { type: 'Slack', detail: null }
}
+ if (hf.template_id === 'template-discord') {
+ const webhookUrl = hf.inputs?.webhookUrl?.value
+ return { type: 'Discord', detail: typeof webhookUrl === 'string' ? webhookUrl : null }
+ }
const urlValue = hf.inputs?.url?.value
if (urlValue && typeof urlValue === 'string') {
return { type: 'Webhook', detail: urlValue }
@@ -84,27 +89,35 @@ export function InlineAlertNotifications({ alertId }: InlineAlertNotificationsPr
const channelId = parts[0]
const channelName = parts[1]?.replace('#', '') ?? channelId
- const notification: PendingAlertNotification = {
+ addPendingNotification({
type: ALERT_NOTIFICATION_TYPE_SLACK,
slackWorkspaceId: firstSlackIntegration.id,
slackChannelId: channelId,
slackChannelName: channelName,
- }
- addPendingNotification(notification)
+ })
setSlackChannelValue(null)
- } else {
- if (!webhookUrl) {
- return
- }
- addPendingNotification({ type: ALERT_NOTIFICATION_TYPE_WEBHOOK, webhookUrl })
- setWebhookUrl('')
+ return
}
+
+ // Discord and generic webhook are both just a single webhook URL
+ if (!webhookUrl) {
+ return
+ }
+ addPendingNotification(
+ selectedType === ALERT_NOTIFICATION_TYPE_DISCORD
+ ? { type: ALERT_NOTIFICATION_TYPE_DISCORD, webhookUrl }
+ : { type: ALERT_NOTIFICATION_TYPE_WEBHOOK, webhookUrl }
+ )
+ setWebhookUrl('')
}
const getNotificationLabel = (notification: PendingAlertNotification): string => {
if (notification.type === ALERT_NOTIFICATION_TYPE_SLACK) {
return `Slack: #${notification.slackChannelName ?? 'channel'}`
}
+ if (notification.type === ALERT_NOTIFICATION_TYPE_DISCORD) {
+ return `Discord: ${notification.webhookUrl}`
+ }
return `Webhook: ${notification.webhookUrl}`
}
@@ -205,9 +218,14 @@ export function InlineAlertNotifications({ alertId }: InlineAlertNotificationsPr
</>
)}
- {selectedType === ALERT_NOTIFICATION_TYPE_WEBHOOK && (
+ {(selectedType === ALERT_NOTIFICATION_TYPE_WEBHOOK ||
+ selectedType === ALERT_NOTIFICATION_TYPE_DISCORD) && (
<LemonInput
- placeholder="https://example.com/webhook"
+ placeholder={
+ selectedType === ALERT_NOTIFICATION_TYPE_DISCORD
+ ? 'https://discord.com/api/webhooks/...'
+ : 'https://example.com/webhook'
+ }
value={webhookUrl}
onChange={setWebhookUrl}
fullWidth
@@ -226,7 +244,9 @@ export function InlineAlertNotifications({ alertId }: InlineAlertNotificationsPr
? 'Select a Slack channel'
: undefined
: !webhookUrl
- ? 'Enter a webhook URL'
+ ? selectedType === ALERT_NOTIFICATION_TYPE_DISCORD
+ ? 'Enter a Discord webhook URL'
+ : 'Enter a webhook URL'
: undefined
}
>
diff --git a/frontend/src/lib/utils/alerts.test.ts b/frontend/src/lib/utils/alerts.test.ts
index 65c6a2fb568f..8ffff594ee22 100644
--- a/frontend/src/lib/utils/alerts.test.ts
+++ b/frontend/src/lib/utils/alerts.test.ts
@@ -64,6 +64,17 @@ describe('alertUtils', () => {
expectedTemplateId: 'template-webhook',
expectedInputKeys: ['url', 'body'],
},
+ {
+ name: 'discord notification',
+ notification: {
+ type: 'discord' as const,
+ webhookUrl: 'https://discord.com/api/webhooks/123/abc',
+ },
+ alertName: 'Spike detector',
+ expectedName: 'Spike detector: Discord',
+ expectedTemplateId: 'template-discord',
+ expectedInputKeys: ['content', 'webhookUrl'],
+ },
])(
'builds correct payload for $name',
({ notification, alertName, expectedName, expectedTemplateId, expectedInputKeys }) => {
@@ -93,6 +104,20 @@ describe('alertUtils', () => {
expect(result.inputs?.channel).toEqual({ value: 'C12345' })
})
+ it('sets correct discord input values', () => {
+ const notification: PendingAlertNotification = {
+ type: 'discord',
+ webhookUrl: 'https://discord.com/api/webhooks/123/abc',
+ }
+
+ const result = buildHogFunctionPayload('alert-789', 'My alert', notification)
+
+ expect(result.inputs?.webhookUrl).toEqual({ value: 'https://discord.com/api/webhooks/123/abc' })
+ expect(result.inputs?.content).toEqual({
+ value: expect.stringContaining('{event.properties.alert_name}'),
+ })
+ })
+
it('sets correct webhook input values', () => {
const notification: PendingAlertNotification = {
type: 'webhook',
diff --git a/frontend/src/lib/utils/alerts.ts b/frontend/src/lib/utils/alerts.ts
index 60b33b2e69bb..d5a6caf01844 100644
--- a/frontend/src/lib/utils/alerts.ts
+++ b/frontend/src/lib/utils/alerts.ts
@@ -8,7 +8,11 @@ import { CyclotronJobFiltersType, HogFunctionType, PropertyFilterType, PropertyO
export const ALERT_NOTIFICATION_TYPE_SLACK = 'slack' as const
export const ALERT_NOTIFICATION_TYPE_WEBHOOK = 'webhook' as const
-export type AlertNotificationType = typeof ALERT_NOTIFICATION_TYPE_SLACK | typeof ALERT_NOTIFICATION_TYPE_WEBHOOK
+export const ALERT_NOTIFICATION_TYPE_DISCORD = 'discord' as const
+export type AlertNotificationType =
+ | typeof ALERT_NOTIFICATION_TYPE_SLACK
+ | typeof ALERT_NOTIFICATION_TYPE_WEBHOOK
+ | typeof ALERT_NOTIFICATION_TYPE_DISCORD
export const buildAlertFilterConfig = (alertId: string): CyclotronJobFiltersType => ({
properties: [
@@ -31,6 +35,10 @@ const INSIGHT_ALERT_SLACK_INPUTS =
HOG_FUNCTION_SUB_TEMPLATES[INSIGHT_ALERT_FIRING_SUB_TEMPLATE_ID].find((t) => t.template_id === 'template-slack')
?.inputs ?? {}
+const INSIGHT_ALERT_DISCORD_INPUTS =
+ HOG_FUNCTION_SUB_TEMPLATES[INSIGHT_ALERT_FIRING_SUB_TEMPLATE_ID].find((t) => t.template_id === 'template-discord')
+ ?.inputs ?? {}
+
export type PendingAlertNotification =
| {
type: typeof ALERT_NOTIFICATION_TYPE_SLACK
@@ -42,6 +50,10 @@ export type PendingAlertNotification =
type: typeof ALERT_NOTIFICATION_TYPE_WEBHOOK
webhookUrl: string
}
+ | {
+ type: typeof ALERT_NOTIFICATION_TYPE_DISCORD
+ webhookUrl: string
+ }
export function buildHogFunctionPayload(
alertId: string,
@@ -56,7 +68,7 @@ export function buildHogFunctionPayload(
filters: buildAlertFilterConfig(alertId),
}
- if (notification.type === 'slack') {
+ if (notification.type === ALERT_NOTIFICATION_TYPE_SLACK) {
return {
...base,
name: `${alertName ?? 'Alert'}: Slack #${notification.slackChannelName ?? 'channel'}`,
@@ -69,6 +81,18 @@ export function buildHogFunctionPayload(
}
}
+ if (notification.type === ALERT_NOTIFICATION_TYPE_DISCORD) {
+ return {
+ ...base,
+ name: `${alertName ?? 'Alert'}: Discord`,
+ template_id: 'template-discord',
+ inputs: {
+ ...INSIGHT_ALERT_DISCORD_INPUTS,
+ webhookUrl: { value: notification.webhookUrl },
+ },
+ }
+ }
+
return {
...base,
name: `${alertName ?? 'Alert'}: Webhook ${notification.webhookUrl}`,
diff --git a/frontend/src/scenes/hog-functions/sub-templates/sub-templates.ts b/frontend/src/scenes/hog-functions/sub-templates/sub-templates.ts
index 32ceb843b9ed..009d29dc1ce6 100644
--- a/frontend/src/scenes/hog-functions/sub-templates/sub-templates.ts
+++ b/frontend/src/scenes/hog-functions/sub-templates/sub-templates.ts
@@ -993,6 +993,17 @@ export const HOG_FUNCTION_SUB_TEMPLATES: Record<HogFunctionSubTemplateIdType, Ho
},
},
},
+ {
+ ...HOG_FUNCTION_SUB_TEMPLATE_COMMON_PROPERTIES[INSIGHT_ALERT_FIRING_SUB_TEMPLATE_ID],
+ template_id: 'template-discord',
+ name: 'Post to Discord on insight alert firing',
+ description: 'Post to a Discord channel when this insight alert fires',
+ inputs: {
+ content: {
+ value: "**Alert '{event.properties.alert_name}' firing** for insight '{event.properties.insight_name}'\n{event.properties.breaches}\n{project.url}/insights/{event.properties.insight_id}/alerts?alert_id={event.properties.alert_id}",
+ },
+ },
+ },
],
'logs-alert-firing': [
{
diff --git a/products/alerts/mcp/tools.yaml b/products/alerts/mcp/tools.yaml
index fc0783b263c1..484870e51571 100644
--- a/products/alerts/mcp/tools.yaml
+++ b/products/alerts/mcp/tools.yaml
@@ -28,8 +28,8 @@ tools:
window size. Ensemble detectors combine 2+ sub-detectors with AND/OR logic. Requires an insight ID and at
least one subscribed user.
- Note: subscribed_users only controls email recipients. For Slack or HTTPS webhook delivery, see the recipe
- on cdp-functions-create — it covers integration lookup (integrations-channels-retrieve), dedupe
+ Note: subscribed_users only controls email recipients. For Slack, HTTPS webhook, or Discord delivery, see
+ the recipe on cdp-functions-create — it covers integration lookup (integrations-channels-retrieve), dedupe
(cdp-functions-list filtered by alert id, limit=1000), and the exact filters/inputs shape to pass.
exclude_params:
- state
@@ -101,10 +101,10 @@ tools:
or upper in threshold.configuration.bounds). To snooze an alert, set snoozed_until to a relative date string
(e.g. '2h', '1d'). To unsnooze, set snoozed_until to null.
- Note: Slack/webhook delivery for this alert lives as a HogFunction. See the recipe on cdp-functions-create
- for the dedupe-and-create flow; to change or remove an existing destination, find it via cdp-functions-list
- (type=internal_destination, limit=1000) by matching filters.properties value against this alert's id, then
- use cdp-functions-partial-update or cdp-functions-delete.
+ Note: Slack/webhook/Discord delivery for this alert lives as a HogFunction. See the recipe on
+ cdp-functions-create for the dedupe-and-create flow; to change or remove an existing destination, find it
+ via cdp-functions-list (type=internal_destination, limit=1000) by matching filters.properties value against
+ this alert's id, then use cdp-functions-partial-update or cdp-functions-delete.
exclude_params:
- state
- last_notified_at
diff --git a/products/cdp/mcp/cdp_functions.yaml b/products/cdp/mcp/cdp_functions.yaml
index eaf806971b07..d8160afec2c5 100644
--- a/products/cdp/mcp/cdp_functions.yaml
+++ b/products/cdp/mcp/cdp_functions.yaml
@@ -26,19 +26,21 @@ tools:
their values. Use 'filters' to control which events trigger the function. Transformations run during
ingestion and have an 'execution_order' field.
- Recipe — deliver an insight alert to Slack or a webhook (canonical reference; alert-create / alert-update
- point here):
+ Recipe — deliver an insight alert to Slack, a webhook, or Discord (canonical reference; alert-create /
+ alert-update point here):
1. Pick the integration. For Slack, call integrations-list (filter by kind=slack) to find the integration
id, then call integrations-channels-retrieve with that id to list channels. For a webhook, the user
- provides the destination URL directly.
+ provides the destination URL directly. For Discord, the user provides an incoming webhook URL
+ (https://discord.com/api/webhooks/...) directly — no integration needed, like a webhook.
2. Dedupe before creating. Call cdp-functions-list with type=internal_destination and limit=1000; the
response now includes filters. Look for an existing function whose filters.properties has an entry
with key=alert_id and value equal to <alert.id>. If one exists, call cdp-functions-partial-update on
that id; if not, proceed to step 3. (Paginate until you have checked every page or found a match.)
- 3. Create. Use type=internal_destination, template_id=template-slack (or template-webhook), and:
+ 3. Create. Use type=internal_destination, template_id=template-slack (or template-webhook or
+ template-discord), and:
filters = {
"events": [{"id": "$insight_alert_firing", "type": "events"}],
"properties": [{"key": "alert_id", "value": "<alert.id>", "operator": "exact", "type": "event"}]
@@ -69,6 +71,15 @@ tools:
}
# Webhook — must be an https:// URL.
inputs = {"url": {"value": "<destination_url>"}}
+ # Discord — incoming webhook URL (https://discord.com/api/webhooks/...). No integration.
+ # Override content with the same shape the alert-wizard UI uses, so agent-created and
+ # UI-created alerts produce identical Discord messages.
+ # Source of truth: HOG_FUNCTION_SUB_TEMPLATES['insight-alert-firing'] for
+ # template-discord in frontend/src/scenes/hog-functions/sub-templates/sub-templates.ts.
+ inputs = {
+ "webhookUrl": {"value": "<discord_webhook_url>"},
+ "content": {"value": "**Alert '{event.properties.alert_name}' firing** for insight '{event.properties.insight_name}'\n{event.properties.breaches}\n{project.url}/insights/{event.properties.insight_id}/alerts?alert_id={event.properties.alert_id}"}
+ }
4. $insight_alert_firing event properties available for templating: alert_id, alert_name, insight_name,
insight_id (short_id), state (always "Firing" — the event is only emitted on a firing transition,
diff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.json
index c9ffc2030d11..c4108e8c2aef 100644
--- a/services/mcp/schema/generated-tool-definitions.json
+++ b/services/mcp/schema/generated-tool-definitions.json
@@ -757,7 +757,7 @@
"feature_flag": "agent-platform-mcp"
},
"alert-create": {
- "description": "Create a new alert on an insight. Alerts can use either threshold-based conditions or anomaly detection. For threshold alerts: set condition (absolute_value, relative_increase, relative_decrease) and threshold configuration with bounds — at least one of lower or upper is required (omit detector_config). For anomaly detection: set detector_config with a detector type (zscore, mad, iqr, threshold, copod, ecod, hbos, isolation_forest, knn, lof, ocsvm, pca) and parameters like threshold (sensitivity 0-1, default 0.9) and window size. Ensemble detectors combine 2+ sub-detectors with AND/OR logic. Requires an insight ID and at least one subscribed user.\nNote: subscribed_users only controls email recipients. For Slack or HTTPS webhook delivery, see the recipe on cdp-functions-create — it covers integration lookup (integrations-channels-retrieve), dedupe (cdp-functions-list filtered by alert id, limit=1000), and the exact filters/inputs shape to pass.",
+ "description": "Create a new alert on an insight. Alerts can use either threshold-based conditions or anomaly detection. For threshold alerts: set condition (absolute_value, relative_increase, relative_decrease) and threshold configuration with bounds — at least one of lower or upper is required (omit detector_config). For anomaly detection: set detector_config with a detector type (zscore, mad, iqr, threshold, copod, ecod, hbos, isolation_forest, knn, lof, ocsvm, pca) and parameters like threshold (sensitivity 0-1, default 0.9) and window size. Ensemble detectors combine 2+ sub-detectors with AND/OR logic. Requires an insight ID and at least one subscribed user.\nNote: subscribed_users only controls email recipients. For Slack, HTTPS webhook, or Discord delivery, see the recipe on cdp-functions-create — it covers integration lookup (integrations-channels-retrieve), dedupe (cdp-functions-list filtered by alert id, limit=1000), and the exact filters/inputs shape to pass.",
"category": "Alerts",
"feature": "alerts",
"summary": "Create alert",
@@ -813,7 +813,7 @@
}
},
"alert-update": {
- "description": "Update an existing alert by ID. Can update name, threshold, condition, config, detector_config, subscribed users, enabled state, calculation interval, and weekend skipping. Set detector_config to switch to anomaly detection, or set it to null to switch back to threshold mode (threshold mode requires at least one of lower or upper in threshold.configuration.bounds). To snooze an alert, set snoozed_until to a relative date string (e.g. '2h', '1d'). To unsnooze, set snoozed_until to null.\nNote: Slack/webhook delivery for this alert lives as a HogFunction. See the recipe on cdp-functions-create for the dedupe-and-create flow; to change or remove an existing destination, find it via cdp-functions-list (type=internal_destination, limit=1000) by matching filters.properties value against this alert's id, then use cdp-functions-partial-update or cdp-functions-delete.",
+ "description": "Update an existing alert by ID. Can update name, threshold, condition, config, detector_config, subscribed users, enabled state, calculation interval, and weekend skipping. Set detector_config to switch to anomaly detection, or set it to null to switch back to threshold mode (threshold mode requires at least one of lower or upper in threshold.configuration.bounds). To snooze an alert, set snoozed_until to a relative date string (e.g. '2h', '1d'). To unsnooze, set snoozed_until to null.\nNote: Slack/webhook/Discord delivery for this alert lives as a HogFunction. See the recipe on cdp-functions-create for the dedupe-and-create flow; to change or remove an existing destination, find it via cdp-functions-list (type=internal_destination, limit=1000) by matching filters.properties value against this alert's id, then use cdp-functions-partial-update or cdp-functions-delete.",
"category": "Alerts",
"feature": "alerts",
"summary": "Update alert",
@@ -1277,7 +1277,7 @@
}
},
"cdp-functions-create": {
- "description": "Create a new function. Requires 'type' (destination, site_destination, internal_destination, source_webhook, warehouse_source_webhook, site_app, or transformation) and either 'hog' source code or a 'template_id' to derive code from a template. Provide 'inputs_schema' to define configurable parameters and 'inputs' with their values. Use 'filters' to control which events trigger the function. Transformations run during ingestion and have an 'execution_order' field.\nRecipe — deliver an insight alert to Slack or a webhook (canonical reference; alert-create / alert-update point here):\n1. Pick the integration. For Slack, call integrations-list (filter by kind=slack) to find the integration\n id, then call integrations-channels-retrieve with that id to list channels. For a webhook, the user\n provides the destination URL directly.\n\n2. Dedupe before creating. Call cdp-functions-list with type=internal_destination and limit=1000; the\n response now includes filters. Look for an existing function whose filters.properties has an entry\n with key=alert_id and value equal to <alert.id>. If one exists, call cdp-functions-partial-update on\n that id; if not, proceed to step 3. (Paginate until you have checked every page or found a match.)\n\n3. Create. Use type=internal_destination, template_id=template-slack (or template-webhook), and:\n filters = {\n \"events\": [{\"id\": \"$insight_alert_firing\", \"type\": \"events\"}],\n \"properties\": [{\"key\": \"alert_id\", \"value\": \"<alert.id>\", \"operator\": \"exact\", \"type\": \"event\"}]\n }\n # Slack. Channel id is preferred (e.g. C0123ABC); \"#general\" is also accepted.\n # Override text + blocks with the same shape the alert-wizard UI uses, so\n # agent-created and UI-created alerts produce identical Slack messages.\n # Source of truth: HOG_FUNCTION_SUB_TEMPLATES['insight-alert-firing'] for\n # template-slack in frontend/src/scenes/hog-functions/sub-templates/sub-templates.ts.\n inputs = {\n \"slack_workspace\": {\"value\": <slack_integration_id_int>},\n \"channel\": {\"value\": \"<channel_id>\"},\n \"text\": {\"value\": \"Alert triggered: {event.properties.insight_name}\"},\n \"blocks\": {\"value\": [\n {\"type\": \"header\", \"text\": {\"type\": \"plain_text\",\n \"text\": \"Alert '{event.properties.alert_name}' firing for insight '{event.properties.insight_name}'\"}},\n {\"type\": \"section\", \"text\": {\"type\": \"plain_text\", \"text\": \"{event.properties.breaches}\"}},\n {\"type\": \"context\", \"elements\": [{\"type\": \"mrkdwn\",\n \"text\": \"Project: <{project.url}|{project.name}>\"}]},\n {\"type\": \"divider\"},\n {\"type\": \"actions\", \"elements\": [\n {\"type\": \"button\", \"text\": {\"type\": \"plain_text\", \"text\": \"View Insight\"},\n \"url\": \"{project.url}/insights/{event.properties.insight_id}\"},\n {\"type\": \"button\", \"text\": {\"type\": \"plain_text\", \"text\": \"View Alert\"},\n \"url\": \"{project.url}/insights/{event.properties.insight_id}/alerts?alert_id={event.properties.alert_id}\"}\n ]}\n ]}\n }\n # Webhook — must be an https:// URL.\n inputs = {\"url\": {\"value\": \"<destination_url>\"}}\n\n4. $insight_alert_firing event properties available for templating: alert_id, alert_name, insight_name,\n insight_id (short_id), state (always \"Firing\" — the event is only emitted on a firing transition,\n not on recovery), last_checked_at (ISO 8601 string or null), breaches (human-readable summary, e.g.\n \"Series A is below 1000\"), and detector metadata: alert_mode (always present), detector_type and\n ensemble_operator (null for threshold alerts, set for anomaly detection). Project context is\n available as {project.url} (already includes /project/<team_id>), {project.id}, {project.name}. Do\n not reference value, threshold_lower, or insight_url — those are not emitted.",
+ "description": "Create a new function. Requires 'type' (destination, site_destination, internal_destination, source_webhook, warehouse_source_webhook, site_app, or transformation) and either 'hog' source code or a 'template_id' to derive code from a template. Provide 'inputs_schema' to define configurable parameters and 'inputs' with their values. Use 'filters' to control which events trigger the function. Transformations run during ingestion and have an 'execution_order' field.\nRecipe — deliver an insight alert to Slack, a webhook, or Discord (canonical reference; alert-create / alert-update point here):\n1. Pick the integration. For Slack, call integrations-list (filter by kind=slack) to find the integration\n id, then call integrations-channels-retrieve with that id to list channels. For a webhook, the user\n provides the destination URL directly. For Discord, the user provides an incoming webhook URL\n (https://discord.com/api/webhooks/...) directly — no integration needed, like a webhook.\n\n2. Dedupe before creating. Call cdp-functions-list with type=internal_destination and limit=1000; the\n response now includes filters. Look for an existing function whose filters.properties has an entry\n with key=alert_id and value equal to <alert.id>. If one exists, call cdp-functions-partial-update on\n that id; if not, proceed to step 3. (Paginate until you have checked every page or found a match.)\n\n3. Create. Use type=internal_destination, template_id=template-slack (or template-webhook or\n template-discord), and:\n filters = {\n \"events\": [{\"id\": \"$insight_alert_firing\", \"type\": \"events\"}],\n \"properties\": [{\"key\": \"alert_id\", \"value\": \"<alert.id>\", \"operator\": \"exact\", \"type\": \"event\"}]\n }\n # Slack. Channel id is preferred (e.g. C0123ABC); \"#general\" is also accepted.\n # Override text + blocks with the same shape the alert-wizard UI uses, so\n # agent-created and UI-created alerts produce identical Slack messages.\n # Source of truth: HOG_FUNCTION_SUB_TEMPLATES['insight-alert-firing'] for\n # template-slack in frontend/src/scenes/hog-functions/sub-templates/sub-templates.ts.\n inputs = {\n \"slack_workspace\": {\"value\": <slack_integration_id_int>},\n \"channel\": {\"value\": \"<channel_id>\"},\n \"text\": {\"value\": \"Alert triggered: {event.properties.insight_name}\"},\n \"blocks\": {\"value\": [\n {\"type\": \"header\", \"text\": {\"type\": \"plain_text\",\n \"text\": \"Alert '{event.properties.alert_name}' firing for insight '{event.properties.insight_name}'\"}},\n {\"type\": \"section\", \"text\": {\"type\": \"plain_text\", \"text\": \"{event.properties.breaches}\"}},\n {\"type\": \"context\", \"elements\": [{\"type\": \"mrkdwn\",\n \"text\": \"Project: <{project.url}|{project.name}>\"}]},\n {\"type\": \"divider\"},\n {\"type\": \"actions\", \"elements\": [\n {\"type\": \"button\", \"text\": {\"type\": \"plain_text\", \"text\": \"View Insight\"},\n \"url\": \"{project.url}/insights/{event.properties.insight_id}\"},\n {\"type\": \"button\", \"text\": {\"type\": \"plain_text\", \"text\": \"View Alert\"},\n \"url\": \"{project.url}/insights/{event.properties.insight_id}/alerts?alert_id={event.properties.alert_id}\"}\n ]}\n ]}\n }\n # Webhook — must be an https:// URL.\n inputs = {\"url\": {\"value\": \"<destination_url>\"}}\n # Discord — incoming webhook URL (https://discord.com/api/webhooks/...). No integration.\n # Override content with the same shape the alert-wizard UI uses, so agent-created and\n # UI-created alerts produce identical Discord messages.\n # Source of truth: HOG_FUNCTION_SUB_TEMPLATES['insight-alert-firing'] for\n # template-discord in frontend/src/scenes/hog-functions/sub-templates/sub-templates.ts.\n inputs = {\n \"webhookUrl\": {\"value\": \"<discord_webhook_url>\"},\n \"content\": {\"value\": \"**Alert '{event.properties.alert_name}' firing** for insight '{event.properties.insight_name}'\\n{event.properties.breaches}\\n{project.url}/insights/{event.properties.insight_id}/alerts?alert_id={event.properties.alert_id}\"}\n }\n\n4. $insight_alert_firing event properties available for templating: alert_id, alert_name, insight_name,\n insight_id (short_id), state (always \"Firing\" — the event is only emitted on a firing transition,\n not on recovery), last_checked_at (ISO 8601 string or null), breaches (human-readable summary, e.g.\n \"Series A is below 1000\"), and detector metadata: alert_mode (always present), detector_type and\n ensemble_operator (null for threshold alerts, set for anomaly detection). Project context is\n available as {project.url} (already includes /project/<team_id>), {project.id}, {project.name}. Do\n not reference value, threshold_lower, or insight_url — those are not emitted.",
"category": "Functions",
"feature": "hog_functions",
"summary": "Create function",
diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.json
index 27c84f3accaf..f0f1d3c3be90 100644
--- a/services/mcp/schema/tool-definitions-all.json
+++ b/services/mcp/schema/tool-definitions-all.json
@@ -773,7 +773,7 @@
"feature_flag": "agent-platform-mcp"
},
"alert-create": {
- "description": "Create a new alert on an insight. Alerts can use either threshold-based conditions or anomaly detection. For threshold alerts: set condition (absolute_value, relative_increase, relative_decrease) and threshold configuration with bounds — at least one of lower or upper is required (omit detector_config). For anomaly detection: set detector_config with a detector type (zscore, mad, iqr, threshold, copod, ecod, hbos, isolation_forest, knn, lof, ocsvm, pca) and parameters like threshold (sensitivity 0-1, default 0.9) and window size. Ensemble detectors combine 2+ sub-detectors with AND/OR logic. Requires an insight ID and at least one subscribed user.\nNote: subscribed_users only controls email recipients. For Slack or HTTPS webhook delivery, see the recipe on cdp-functions-create — it covers integration lookup (integrations-channels-retrieve), dedupe (cdp-functions-list filtered by alert id, limit=1000), and the exact filters/inputs shape to pass.",
+ "description": "Create a new alert on an insight. Alerts can use either threshold-based conditions or anomaly detection. For threshold alerts: set condition (absolute_value, relative_increase, relative_decrease) and threshold configuration with bounds — at least one of lower or upper is required (omit detector_config). For anomaly detection: set detector_config with a detector type (zscore, mad, iqr, threshold, copod, ecod, hbos, isolation_forest, knn, lof, ocsvm, pca) and parameters like threshold (sensitivity 0-1, default 0.9) and window size. Ensemble detectors combine 2+ sub-detectors with AND/OR logic. Requires an insight ID and at least one subscribed user.\nNote: subscribed_users only controls email recipients. For Slack, HTTPS webhook, or Discord delivery, see the recipe on cdp-functions-create — it covers integration lookup (integrations-channels-retrieve), dedupe (cdp-functions-list filtered by alert id, limit=1000), and the exact filters/inputs shape to pass.",
"category": "Alerts",
"feature": "alerts",
"summary": "Create alert",
@@ -829,7 +829,7 @@
}
},
"alert-update": {
- "description": "Update an existing alert by ID. Can update name, threshold, condition, config, detector_config, subscribed users, enabled state, calculation interval, and weekend skipping. Set detector_config to switch to anomaly detection, or set it to null to switch back to threshold mode (threshold mode requires at least one of lower or upper in threshold.configuration.bounds). To snooze an alert, set snoozed_until to a relative date string (e.g. '2h', '1d'). To unsnooze, set snoozed_until to null.\nNote: Slack/webhook delivery for this alert lives as a HogFunction. See the recipe on cdp-functions-create for the dedupe-and-create flow; to change or remove an existing destination, find it via cdp-functions-list (type=internal_destination, limit=1000) by matching filters.properties value against this alert's id, then use cdp-functions-partial-update or cdp-functions-delete.",
+ "description": "Update an existing alert by ID. Can update name, threshold, condition, config, detector_config, subscribed users, enabled state, calculation interval, and weekend skipping. Set detector_config to switch to anomaly detection, or set it to null to switch back to threshold mode (threshold mode requires at least one of lower or upper in threshold.configuration.bounds). To snooze an alert, set snoozed_until to a relative date string (e.g. '2h', '1d'). To unsnooze, set snoozed_until to null.\nNote: Slack/webhook/Discord delivery for this alert lives as a HogFunction. See the recipe on cdp-functions-create for the dedupe-and-create flow; to change or remove an existing destination, find it via cdp-functions-list (type=internal_destination, limit=1000) by matching filters.properties value against this alert's id, then use cdp-functions-partial-update or cdp-functions-delete.",
"category": "Alerts",
"feature": "alerts",
"summary": "Update alert",
@@ -1293,7 +1293,7 @@
}
},
"cdp-functions-create": {
- "description": "Create a new function. Requires 'type' (destination, site_destination, internal_destination, source_webhook, warehouse_source_webhook, site_app, or transformation) and either 'hog' source code or a 'template_id' to derive code from a template. Provide 'inputs_schema' to define configurable parameters and 'inputs' with their values. Use 'filters' to control which events trigger the function. Transformations run during ingestion and have an 'execution_order' field.\nRecipe — deliver an insight alert to Slack or a webhook (canonical reference; alert-create / alert-update point here):\n1. Pick the integration. For Slack, call integrations-list (filter by kind=slack) to find the integration\n id, then call integrations-channels-retrieve with that id to list channels. For a webhook, the user\n provides the destination URL directly.\n\n2. Dedupe before creating. Call cdp-functions-list with type=internal_destination and limit=1000; the\n response now includes filters. Look for an existing function whose filters.properties has an entry\n with key=alert_id and value equal to <alert.id>. If one exists, call cdp-functions-partial-update on\n that id; if not, proceed to step 3. (Paginate until you have checked every page or found a match.)\n\n3. Create. Use type=internal_destination, template_id=template-slack (or template-webhook), and:\n filters = {\n \"events\": [{\"id\": \"$insight_alert_firing\", \"type\": \"events\"}],\n \"properties\": [{\"key\": \"alert_id\", \"value\": \"<alert.id>\", \"operator\": \"exact\", \"type\": \"event\"}]\n }\n # Slack. Channel id is preferred (e.g. C0123ABC); \"#general\" is also accepted.\n # Override text + blocks with the same shape the alert-wizard UI uses, so\n # agent-created and UI-created alerts produce identical Slack messages.\n # Source of truth: HOG_FUNCTION_SUB_TEMPLATES['insight-alert-firing'] for\n # template-slack in frontend/src/scenes/hog-functions/sub-templates/sub-templates.ts.\n inputs = {\n \"slack_workspace\": {\"value\": <slack_integration_id_int>},\n \"channel\": {\"value\": \"<channel_id>\"},\n \"text\": {\"value\": \"Alert triggered: {event.properties.insight_name}\"},\n \"blocks\": {\"value\": [\n {\"type\": \"header\", \"text\": {\"type\": \"plain_text\",\n \"text\": \"Alert '{event.properties.alert_name}' firing for insight '{event.properties.insight_name}'\"}},\n {\"type\": \"section\", \"text\": {\"type\": \"plain_text\", \"text\": \"{event.properties.breaches}\"}},\n {\"type\": \"context\", \"elements\": [{\"type\": \"mrkdwn\",\n \"text\": \"Project: <{project.url}|{project.name}>\"}]},\n {\"type\": \"divider\"},\n {\"type\": \"actions\", \"elements\": [\n {\"type\": \"button\", \"text\": {\"type\": \"plain_text\", \"text\": \"View Insight\"},\n \"url\": \"{project.url}/insights/{event.properties.insight_id}\"},\n {\"type\": \"button\", \"text\": {\"type\": \"plain_text\", \"text\": \"View Alert\"},\n \"url\": \"{project.url}/insights/{event.properties.insight_id}/alerts?alert_id={event.properties.alert_id}\"}\n ]}\n ]}\n }\n # Webhook — must be an https:// URL.\n inputs = {\"url\": {\"value\": \"<destination_url>\"}}\n\n4. $insight_alert_firing event properties available for templating: alert_id, alert_name, insight_name,\n insight_id (short_id), state (always \"Firing\" — the event is only emitted on a firing transition,\n not on recovery), last_checked_at (ISO 8601 string or null), breaches (human-readable summary, e.g.\n \"Series A is below 1000\"), and detector metadata: alert_mode (always present), detector_type and\n ensemble_operator (null for threshold alerts, set for anomaly detection). Project context is\n available as {project.url} (already includes /project/<team_id>), {project.id}, {project.name}. Do\n not reference value, threshold_lower, or insight_url — those are not emitted.",
+ "description": "Create a new function. Requires 'type' (destination, site_destination, internal_destination, source_webhook, warehouse_source_webhook, site_app, or transformation) and either 'hog' source code or a 'template_id' to derive code from a template. Provide 'inputs_schema' to define configurable parameters and 'inputs' with their values. Use 'filters' to control which events trigger the function. Transformations run during ingestion and have an 'execution_order' field.\nRecipe — deliver an insight alert to Slack, a webhook, or Discord (canonical reference; alert-create / alert-update point here):\n1. Pick the integration. For Slack, call integrations-list (filter by kind=slack) to find the integration\n id, then call integrations-channels-retrieve with that id to list channels. For a webhook, the user\n provides the destination URL directly. For Discord, the user provides an incoming webhook URL\n (https://discord.com/api/webhooks/...) directly — no integration needed, like a webhook.\n\n2. Dedupe before creating. Call cdp-functions-list with type=internal_destination and limit=1000; the\n response now includes filters. Look for an existing function whose filters.properties has an entry\n with key=alert_id and value equal to <alert.id>. If one exists, call cdp-functions-partial-update on\n that id; if not, proceed to step 3. (Paginate until you have checked every page or found a match.)\n\n3. Create. Use type=internal_destination, template_id=template-slack (or template-webhook or\n template-discord), and:\n filters = {\n \"events\": [{\"id\": \"$insight_alert_firing\", \"type\": \"events\"}],\n \"properties\": [{\"key\": \"alert_id\", \"value\": \"<alert.id>\", \"operator\": \"exact\", \"type\": \"event\"}]\n }\n # Slack. Channel id is preferred (e.g. C0123ABC); \"#general\" is also accepted.\n # Override text + blocks with the same shape the alert-wizard UI uses, so\n # agent-created and UI-created alerts produce identical Slack messages.\n # Source of truth: HOG_FUNCTION_SUB_TEMPLATES['insight-alert-firing'] for\n # template-slack in frontend/src/scenes/hog-functions/sub-templates/sub-templates.ts.\n inputs = {\n \"slack_workspace\": {\"value\": <slack_integration_id_int>},\n \"channel\": {\"value\": \"<channel_id>\"},\n \"text\": {\"value\": \"Alert triggered: {event.properties.insight_name}\"},\n \"blocks\": {\"value\": [\n {\"type\": \"header\", \"text\": {\"type\": \"plain_text\",\n \"text\": \"Alert '{event.properties.alert_name}' firing for insight '{event.properties.insight_name}'\"}},\n {\"type\": \"section\", \"text\": {\"type\": \"plain_text\", \"text\": \"{event.properties.breaches}\"}},\n {\"type\": \"context\", \"elements\": [{\"type\": \"mrkdwn\",\n \"text\": \"Project: <{project.url}|{project.name}>\"}]},\n {\"type\": \"divider\"},\n {\"type\": \"actions\", \"elements\": [\n {\"type\": \"button\", \"text\": {\"type\": \"plain_text\", \"text\": \"View Insight\"},\n \"url\": \"{project.url}/insights/{event.properties.insight_id}\"},\n {\"type\": \"button\", \"text\": {\"type\": \"plain_text\", \"text\": \"View Alert\"},\n \"url\": \"{project.url}/insights/{event.properties.insight_id}/alerts?alert_id={event.properties.alert_id}\"}\n ]}\n ]}\n }\n # Webhook — must be an https:// URL.\n inputs = {\"url\": {\"value\": \"<destination_url>\"}}\n # Discord — incoming webhook URL (https://discord.com/api/webhooks/...). No integration.\n # Override content with the same shape the alert-wizard UI uses, so agent-created and\n # UI-created alerts produce identical Discord messages.\n # Source of truth: HOG_FUNCTION_SUB_TEMPLATES['insight-alert-firing'] for\n # template-discord in frontend/src/scenes/hog-functions/sub-templates/sub-templates.ts.\n inputs = {\n \"webhookUrl\": {\"value\": \"<discord_webhook_url>\"},\n \"content\": {\"value\": \"**Alert '{event.properties.alert_name}' firing** for insight '{event.properties.insight_name}'\\n{event.properties.breaches}\\n{project.url}/insights/{event.properties.insight_id}/alerts?alert_id={event.properties.alert_id}\"}\n }\n\n4. $insight_alert_firing event properties available for templating: alert_id, alert_name, insight_name,\n insight_id (short_id), state (always \"Firing\" — the event is only emitted on a firing transition,\n not on recovery), last_checked_at (ISO 8601 string or null), breaches (human-readable summary, e.g.\n \"Series A is below 1000\"), and detector metadata: alert_mode (always present), detector_type and\n ensemble_operator (null for threshold alerts, set for anomaly detection). Project context is\n available as {project.url} (already includes /project/<team_id>), {project.id}, {project.name}. Do\n not reference value, threshold_lower, or insight_url — those are not emitted.",
"category": "Functions",
"feature": "hog_functions",
"summary": "Create function",