Repository navigation
feat(mcp): accept note and numConsecutiveWindows in clickstack_save_alert #3694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| --- | ||
| '@hyperdx/common-utils': patch | ||
| '@hyperdx/api': patch | ||
| --- | ||
|
|
||
| feat: `clickstack_save_alert` accepts `note` and `numConsecutiveWindows` | ||
|
|
||
| Updates that omit either field now keep the stored value instead of clearing it; | ||
| send `null` to clear. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ import * as config from '@/config'; | |
| import { | ||
| type AlertInput, | ||
| createAlert, | ||
| getAlertById, | ||
| updateAlert, | ||
| validateAlertInput, | ||
| } from '@/controllers/alerts'; | ||
|
|
@@ -54,9 +55,9 @@ export function registerSaveAlert({ | |
| 'required: pass "channels", or the legacy singular "channel" for one ' + | ||
| '(webhook IDs come from clickstack_get_webhook). Updates replace the ' + | ||
| 'alert configuration rather than merging it: channels you do not resend are ' + | ||
| 'removed, omitted name and message are cleared, omitted displayName and tags ' + | ||
| 'are re-derived from the source, and settings this tool cannot set ' + | ||
| '(note, consecutive-window count) are cleared. Omitting both ' + | ||
| 'removed, omitted name and message are cleared, and omitted displayName ' + | ||
| 'and tags are re-derived from the source. Omitted note and ' + | ||
| 'numConsecutiveWindows keep their stored values. Omitting both ' + | ||
| 'scheduleStartAt and scheduleOffsetMinutes keeps the stored schedule; ' + | ||
| 'clearing scheduleStartAt without an offset resets the offset to 0. Read the alert with ' + | ||
| 'clickstack_get_alert first and resend every field you want to keep.', | ||
|
|
@@ -76,6 +77,14 @@ export function registerSaveAlert({ | |
| if (idError) return idError; | ||
| } | ||
|
|
||
| const mongoTeamId = new mongoose.Types.ObjectId(teamId); | ||
| const existing = alertId | ||
| ? await getAlertById(alertId, mongoTeamId) | ||
| : null; | ||
| if (alertId && !existing) { | ||
| return mcpUserError('Alert not found'); | ||
| } | ||
|
|
||
| // Inline alerts: run the chart config through the shared external | ||
| // schema (same one the v2 REST API parses) so formula validation and | ||
| // the number single-select rule cannot drift between the surfaces, | ||
|
|
@@ -114,6 +123,14 @@ export function registerSaveAlert({ | |
| scheduleStartAt: input.scheduleStartAt, | ||
| name: input.name, | ||
| message: input.message, | ||
| // Unlike name and message, an omitted note or window count keeps the | ||
| // stored value: callers written before this tool accepted them would | ||
| // otherwise wipe what was set in the UI. null still clears. | ||
| note: input.note === undefined ? existing?.note : input.note, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 minor — Keeping the stored note/window count by reading first and writing later can overwrite a concurrent UI edit
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe the tool already works this way for every other field: an update replaces the alert with whatever the caller read from
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 minor — Keeping the stored note/window count by reading and re-writing it can undo a concurrent UI edit The tool reads the alert, then runs Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Answered in #3694 (comment) |
||
| numConsecutiveWindows: | ||
| input.numConsecutiveWindows === undefined | ||
| ? existing?.numConsecutiveWindows | ||
| : input.numConsecutiveWindows, | ||
| displayName: input.displayName, | ||
| tags: input.tags, | ||
| groupBy: input.groupBy, | ||
|
|
@@ -124,7 +141,6 @@ export function registerSaveAlert({ | |
| }; | ||
|
|
||
| // ── Validate referenced entities exist ── | ||
| const mongoTeamId = new mongoose.Types.ObjectId(teamId); | ||
| let refs; | ||
| try { | ||
| refs = await validateAlertInput(mongoTeamId, alertInput); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔵 minor — Keep-on-omit uses read-then-write, so a concurrent UI edit to note or numConsecutiveWindows can be reverted
existingis read at line 82, but the write happens at line 163, aftervalidateAlertInputhas made several awaited DB queries. If someone saves a new note or window count in the UI in that gap, the update writes the staleexistingvalues back over it. Do this the waymakeAlertalready handlesscheduleStartAt(packages/api/src/controllers/alerts.ts:259-294): leavenote/numConsecutiveWindowsout of$setwhen they areundefined, behind an opt-in flag so the external and internal APIs keep clearing omitted fields. Then the update is atomic, and the extragetAlertByIdlookup can go (theupdateAlertnull check at line 170 already returns 'Alert not found').Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Answered in #3694 (comment)