@centrali-io/centrali-mcp 6.16.1 → 6.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -0
- package/dist/index.js +2 -0
- package/dist/tools/alerts.d.ts +3 -0
- package/dist/tools/alerts.js +251 -0
- package/dist/tools/describe.js +46 -0
- package/package.json +2 -2
- package/src/index.ts +2 -0
- package/src/tools/alerts.ts +262 -0
- package/src/tools/describe.ts +55 -0
package/README.md
CHANGED
|
@@ -262,6 +262,41 @@ AI assistants should not propose saved queries (or join chains) against collecti
|
|
|
262
262
|
|
|
263
263
|
**Reserved clauses.** Saved-query create/update/test surfaces reject `text` (full-text search) and `include` (relation expansion) with 422 `unsupported_clause`. Those clauses are available on the ad-hoc `POST /records/query` surface only — don't author saved queries that use them.
|
|
264
264
|
|
|
265
|
+
### Alerts
|
|
266
|
+
|
|
267
|
+
Run a saved query on a cron and notify people when its result meets a condition.
|
|
268
|
+
|
|
269
|
+
| Tool | Description |
|
|
270
|
+
|------|-------------|
|
|
271
|
+
| `list_alerts` | List alerts, optionally filtered to one saved query |
|
|
272
|
+
| `get_alert` | Get an alert by ID, including its evaluation history |
|
|
273
|
+
| `create_alert` | Create a scheduled alert on a saved query |
|
|
274
|
+
| `update_alert` | Update an alert's schedule, condition, recipients, bindings, or enabled state |
|
|
275
|
+
| `delete_alert` | Delete an alert and unschedule its job |
|
|
276
|
+
|
|
277
|
+
**Conditions.** Two kinds ship today — `{ kind: 'rowCount', op, value }` (`op` one of `eq`/`neq`/`gt`/`gte`/`lt`/`lte`) and `{ kind: 'rowsChanged' }`, which fires when the row count differs from the previous evaluation and never fires on its first run (it only seeds the baseline). There is no `aggregate` kind: an alert reasons about how many rows came back, not about a sum or average of their contents. To alert on an aggregate, author the saved query so the rows it returns *are* the exception set and alert on `rowCount`.
|
|
278
|
+
|
|
279
|
+
**Scheduling.** `cronExpression` is a 5-field cron expression interpreted in `timezone` (IANA name, default `UTC`). Notifications are throttled to 1 per recipient per 15 minutes per alert, so a sub-15-minute cron evaluates more often than it can notify.
|
|
280
|
+
|
|
281
|
+
**Recipients.** `recipients` is an explicit list — `[{ type: 'user', id: '<userId>' }]` — not a subscription list. No MCP tool enumerates workspace users, so an assistant must ask the user for IDs rather than constructing them.
|
|
282
|
+
|
|
283
|
+
**Binding variables — stricter than execute.** If the saved query declares parameters, bind them via `variables`. The server validates the map on create and on any update that submits it, and requires **every declaration the query body references that has no `default`**, regardless of `required`:
|
|
284
|
+
|
|
285
|
+
```json
|
|
286
|
+
{
|
|
287
|
+
"savedQueryId": "…",
|
|
288
|
+
"name": "Failed payments spiked",
|
|
289
|
+
"cronExpression": "0 * * * *",
|
|
290
|
+
"condition": { "kind": "rowCount", "op": "gt", "value": 10 },
|
|
291
|
+
"recipients": [{ "type": "user", "id": "…" }],
|
|
292
|
+
"variables": { "status": "failed" }
|
|
293
|
+
}
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
`execute_saved_query` accepts an unbound optional and leaves the raw `${name}` in the body; the query then filters on the literal placeholder, matches nothing, and reports no error. Interactively that's visible — the caller sees an empty result. On a cron nobody is watching, so the alert would simply never fire and `lastEvaluatedAt` would keep advancing as though healthy. Authoring is the last point where the gap is noticeable, so it fails there with a 400 naming each offending variable.
|
|
297
|
+
|
|
298
|
+
**Diagnosing "it never fired".** `get_alert` exposes `lastEvaluatedAt`, `lastTriggeredAt`, and `lastRowCount`. A null or stale `lastEvaluatedAt` means the alert is disabled or its evaluations are erroring (failures are logged and skipped, leaving the row untouched). A current `lastEvaluatedAt` with a null `lastTriggeredAt` means the query runs fine and the condition isn't matching — compare the alert's `variables` against the saved query's declarations.
|
|
299
|
+
|
|
265
300
|
### Orchestrations
|
|
266
301
|
| Tool | Description |
|
|
267
302
|
|------|-------------|
|
package/dist/index.js
CHANGED
|
@@ -18,6 +18,7 @@ const records_js_1 = require("./tools/records.js");
|
|
|
18
18
|
const search_js_1 = require("./tools/search.js");
|
|
19
19
|
const compute_js_1 = require("./tools/compute.js");
|
|
20
20
|
const saved_queries_js_1 = require("./tools/saved-queries.js");
|
|
21
|
+
const alerts_js_1 = require("./tools/alerts.js");
|
|
21
22
|
const orchestrations_js_1 = require("./tools/orchestrations.js");
|
|
22
23
|
const insights_js_1 = require("./tools/insights.js");
|
|
23
24
|
const validation_js_1 = require("./tools/validation.js");
|
|
@@ -75,6 +76,7 @@ function main() {
|
|
|
75
76
|
(0, search_js_1.registerSearchTools)(server, sdk);
|
|
76
77
|
(0, compute_js_1.registerComputeTools)(server, sdk, baseUrl, workspaceId);
|
|
77
78
|
(0, saved_queries_js_1.registerSavedQueryTools)(server, sdk);
|
|
79
|
+
(0, alerts_js_1.registerAlertTools)(server, sdk);
|
|
78
80
|
(0, orchestrations_js_1.registerOrchestrationTools)(server, sdk);
|
|
79
81
|
(0, insights_js_1.registerInsightTools)(server, sdk);
|
|
80
82
|
(0, validation_js_1.registerValidationTools)(server, sdk);
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.registerAlertTools = registerAlertTools;
|
|
13
|
+
const zod_1 = require("zod");
|
|
14
|
+
const _register_js_1 = require("./_register.js");
|
|
15
|
+
// Saved-query alerts (CEN-1123). An alert runs a saved query on a cron,
|
|
16
|
+
// checks the row count against a condition, and notifies explicit
|
|
17
|
+
// recipients by email + in-app inbox when it matches.
|
|
18
|
+
const CONDITION_HINT = `The 'condition' decides when the alert fires. Two kinds ship today:
|
|
19
|
+
|
|
20
|
+
{ "kind": "rowCount", "op": "gt", "value": 10 } // op: eq | neq | gt | gte | lt | lte
|
|
21
|
+
{ "kind": "rowsChanged" }
|
|
22
|
+
|
|
23
|
+
'rowCount' compares the execution's row count against 'value'. 'rowsChanged' fires whenever the row count differs from the previous evaluation — its FIRST run only records a baseline and never fires, so don't propose it when the user wants an immediate one-off check.
|
|
24
|
+
|
|
25
|
+
There is no 'aggregate' kind yet: an alert can only reason about how many rows came back, not about a sum or average of their contents. If the user wants "alert when total revenue drops below X", author the saved query so that the rows it returns ARE the exception set (e.g. filter to the offending rows) and alert on 'rowCount', rather than promising an aggregate comparison that doesn't exist.`;
|
|
26
|
+
const SCHEDULE_HINT = `'cronExpression' is a standard 5-field cron expression ("minute hour day-of-month month day-of-week"), interpreted in 'timezone' (an IANA name like "Europe/London"; defaults to "UTC"). Examples: "0 9 * * 1-5" = 9am every weekday, "*/15 * * * *" = every 15 minutes, "0 0 1 * *" = midnight on the 1st.
|
|
27
|
+
|
|
28
|
+
Each evaluation runs the saved query in full, so prefer the least frequent schedule that satisfies the user's need. Notifications are additionally throttled to 1 per recipient per 15 minutes per alert, so a sub-15-minute cron will evaluate more often than it can notify.`;
|
|
29
|
+
const VARIABLES_HINT = `If the saved query declares parameters, bind them via 'variables' — a map of variable name to concrete value, validated against the query's declarations by JS typeof (no coercion, so 123 not "123" for a number).
|
|
30
|
+
|
|
31
|
+
Call get_saved_query first and read its 'variables' declarations. Bind EVERY declaration that the query body references and that has no 'default'. This is stricter than executing the query by hand, and the server enforces it: an unbound reference is legal at execute time and gets left in the body verbatim, so the alert would filter on the literal "\${name}", match nothing, and never fire — with no error anywhere, because nobody watches a cron. Declarations the body never references may be omitted.
|
|
32
|
+
|
|
33
|
+
An incomplete map is rejected with a 400 naming each offending variable.`;
|
|
34
|
+
const RECIPIENTS_HINT = `'recipients' is an explicit list of users — [{ "type": "user", "id": "<userId>" }] — not a subscription list. At least one is required, and only the people listed here are notified.
|
|
35
|
+
|
|
36
|
+
There is no MCP tool that enumerates workspace users, so do NOT guess or construct user IDs. Ask the user for the IDs (they can copy them from the console's workspace members page), or have them create the alert in the console UI where the recipient picker searches members by name.`;
|
|
37
|
+
function registerAlertTools(server, sdk) {
|
|
38
|
+
(0, _register_js_1.registerTool)(server, "list_alerts", "List saved-query alerts in the workspace. Each row includes the alert's schedule, condition, recipients, whether it is enabled, and its evaluation history ('lastEvaluatedAt', 'lastTriggeredAt', 'lastRowCount'). Alerts on saved queries the caller can't read are omitted rather than failing the call. Optionally filter to one saved query.", {
|
|
39
|
+
savedQueryId: zod_1.z
|
|
40
|
+
.string()
|
|
41
|
+
.optional()
|
|
42
|
+
.describe("Only return alerts attached to this saved query (UUID). If omitted, lists every readable alert in the workspace."),
|
|
43
|
+
}, (_a) => __awaiter(this, [_a], void 0, function* ({ savedQueryId }) {
|
|
44
|
+
try {
|
|
45
|
+
const result = yield sdk.alerts.list(savedQueryId ? { savedQueryId } : undefined);
|
|
46
|
+
return {
|
|
47
|
+
content: [
|
|
48
|
+
{ type: "text", text: JSON.stringify(result.data, null, 2) },
|
|
49
|
+
],
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
return {
|
|
54
|
+
content: [
|
|
55
|
+
{ type: "text", text: (0, _register_js_1.formatError)(error, "listing alerts") },
|
|
56
|
+
],
|
|
57
|
+
isError: true,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}));
|
|
61
|
+
(0, _register_js_1.registerTool)(server, "get_alert", `Get a saved-query alert by ID, including its bound 'variables', schedule, condition, recipients, and evaluation history.
|
|
62
|
+
|
|
63
|
+
Diagnosing an alert that "never fires": check 'lastEvaluatedAt' first. If it is null or stale, the alert is disabled or its evaluations are failing (a query error is logged and skipped, leaving the row untouched). If it is current but 'lastTriggeredAt' stays null, the query is running fine and the condition simply isn't matching — compare the alert's 'variables' against the saved query's declarations via get_saved_query, since a placeholder the alert leaves unbound filters on a literal that matches nothing.`, {
|
|
64
|
+
alertId: zod_1.z.string().describe("The alert ID (UUID)"),
|
|
65
|
+
}, (_a) => __awaiter(this, [_a], void 0, function* ({ alertId }) {
|
|
66
|
+
try {
|
|
67
|
+
const result = yield sdk.alerts.get(alertId);
|
|
68
|
+
return {
|
|
69
|
+
content: [
|
|
70
|
+
{ type: "text", text: JSON.stringify(result.data, null, 2) },
|
|
71
|
+
],
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
return {
|
|
76
|
+
content: [
|
|
77
|
+
{ type: "text", text: (0, _register_js_1.formatError)(error, `getting alert '${alertId}'`) },
|
|
78
|
+
],
|
|
79
|
+
isError: true,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
}));
|
|
83
|
+
(0, _register_js_1.registerTool)(server, "create_alert", `Create a scheduled alert on a saved query. Unless 'enabled' is false, it is scheduled immediately and will start notifying people.
|
|
84
|
+
|
|
85
|
+
Authorization: creating an alert requires permission to manage alerts AND 'execute' on the saved query itself — scheduling recurring runs of a query you can't run yourself is refused with a 403.
|
|
86
|
+
|
|
87
|
+
${CONDITION_HINT}
|
|
88
|
+
|
|
89
|
+
${SCHEDULE_HINT}
|
|
90
|
+
|
|
91
|
+
${VARIABLES_HINT}
|
|
92
|
+
|
|
93
|
+
${RECIPIENTS_HINT}`, {
|
|
94
|
+
savedQueryId: zod_1.z.string().describe("The saved query (UUID) to evaluate on the schedule. Must be in this workspace."),
|
|
95
|
+
name: zod_1.z.string().describe("Display name, max 255 characters. Used as the notification subject, so make it read as the situation being reported (e.g. 'No open orders') rather than as a job name."),
|
|
96
|
+
description: zod_1.z.string().optional().describe("Optional context for the alert, max 2000 characters"),
|
|
97
|
+
cronExpression: zod_1.z.string().describe("5-field cron expression driving evaluation, e.g. '0 9 * * 1-5'"),
|
|
98
|
+
timezone: zod_1.z.string().optional().describe("IANA timezone the cron is interpreted in, e.g. 'Europe/London'. Defaults to 'UTC' — set it explicitly whenever the user states a wall-clock time."),
|
|
99
|
+
condition: zod_1.z
|
|
100
|
+
.record(zod_1.z.string(), zod_1.z.any())
|
|
101
|
+
.describe("The trigger condition: { kind: 'rowCount', op, value } or { kind: 'rowsChanged' }"),
|
|
102
|
+
recipients: zod_1.z
|
|
103
|
+
.array(zod_1.z.record(zod_1.z.string(), zod_1.z.any()))
|
|
104
|
+
.describe("Users to notify: [{ type: 'user', id: '<userId>' }]. At least one required."),
|
|
105
|
+
variables: zod_1.z
|
|
106
|
+
.record(zod_1.z.string(), zod_1.z.any())
|
|
107
|
+
.optional()
|
|
108
|
+
.describe("Values bound to the saved query's '${varName}' placeholders on every evaluation. Required for any referenced declaration without a default — see the tool description."),
|
|
109
|
+
enabled: zod_1.z
|
|
110
|
+
.boolean()
|
|
111
|
+
.optional()
|
|
112
|
+
.describe("Defaults to true. Pass false to author the alert without scheduling it yet."),
|
|
113
|
+
}, (_a) => __awaiter(this, [_a], void 0, function* ({ savedQueryId, name, description, cronExpression, timezone, condition, recipients, variables, enabled }) {
|
|
114
|
+
try {
|
|
115
|
+
const input = {
|
|
116
|
+
savedQueryId,
|
|
117
|
+
name,
|
|
118
|
+
cronExpression,
|
|
119
|
+
condition,
|
|
120
|
+
recipients,
|
|
121
|
+
};
|
|
122
|
+
if (description !== undefined)
|
|
123
|
+
input.description = description;
|
|
124
|
+
if (timezone !== undefined)
|
|
125
|
+
input.timezone = timezone;
|
|
126
|
+
if (variables !== undefined)
|
|
127
|
+
input.variables = variables;
|
|
128
|
+
if (enabled !== undefined)
|
|
129
|
+
input.enabled = enabled;
|
|
130
|
+
const result = yield sdk.alerts.create(input);
|
|
131
|
+
return {
|
|
132
|
+
content: [
|
|
133
|
+
{ type: "text", text: JSON.stringify(result.data, null, 2) },
|
|
134
|
+
],
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
return {
|
|
139
|
+
content: [
|
|
140
|
+
{ type: "text", text: (0, _register_js_1.formatError)(error, `creating alert '${name}'`) },
|
|
141
|
+
],
|
|
142
|
+
isError: true,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
}));
|
|
146
|
+
(0, _register_js_1.registerTool)(server, "update_alert", `Update an alert. Only include the fields you want to change.
|
|
147
|
+
|
|
148
|
+
'savedQueryId' is immutable — to point an alert at a different query, delete it and create a new one.
|
|
149
|
+
|
|
150
|
+
Toggling 'enabled' or changing 'cronExpression'/'timezone' reschedules the underlying job. If another request changes the same alert concurrently, this fails with 409; refetch with get_alert and reapply rather than retrying the same body.
|
|
151
|
+
|
|
152
|
+
Passing 'variables' REPLACES the stored bindings wholesale (it is not merged), and the replacement is validated under the same rule as create — see below. Omit it to leave the existing bindings untouched.
|
|
153
|
+
|
|
154
|
+
${CONDITION_HINT}
|
|
155
|
+
|
|
156
|
+
${SCHEDULE_HINT}
|
|
157
|
+
|
|
158
|
+
${VARIABLES_HINT}
|
|
159
|
+
|
|
160
|
+
${RECIPIENTS_HINT}`, {
|
|
161
|
+
alertId: zod_1.z.string().describe("The alert ID (UUID) to update"),
|
|
162
|
+
name: zod_1.z.string().optional().describe("Updated display name"),
|
|
163
|
+
description: zod_1.z
|
|
164
|
+
.union([zod_1.z.string(), zod_1.z.null()])
|
|
165
|
+
.optional()
|
|
166
|
+
.describe("Updated description. Pass null to clear it; omit to leave it unchanged."),
|
|
167
|
+
cronExpression: zod_1.z.string().optional().describe("Updated cron expression — reschedules the job"),
|
|
168
|
+
timezone: zod_1.z.string().optional().describe("Updated IANA timezone — reschedules the job"),
|
|
169
|
+
condition: zod_1.z
|
|
170
|
+
.record(zod_1.z.string(), zod_1.z.any())
|
|
171
|
+
.optional()
|
|
172
|
+
.describe("Updated trigger condition"),
|
|
173
|
+
recipients: zod_1.z
|
|
174
|
+
.array(zod_1.z.record(zod_1.z.string(), zod_1.z.any()))
|
|
175
|
+
.optional()
|
|
176
|
+
.describe("Replacement recipient list: [{ type: 'user', id: '<userId>' }]. Replaces the existing list wholesale."),
|
|
177
|
+
variables: zod_1.z
|
|
178
|
+
.record(zod_1.z.string(), zod_1.z.any())
|
|
179
|
+
.optional()
|
|
180
|
+
.describe("Replacement variable bindings. Replaces the stored map wholesale; omit to leave it unchanged."),
|
|
181
|
+
enabled: zod_1.z
|
|
182
|
+
.boolean()
|
|
183
|
+
.optional()
|
|
184
|
+
.describe("Pause (false) or resume (true) the alert. Pausing keeps the definition and its evaluation history."),
|
|
185
|
+
}, (_a) => __awaiter(this, [_a], void 0, function* ({ alertId, name, description, cronExpression, timezone, condition, recipients, variables, enabled }) {
|
|
186
|
+
try {
|
|
187
|
+
const input = {};
|
|
188
|
+
if (name !== undefined)
|
|
189
|
+
input.name = name;
|
|
190
|
+
if (description !== undefined)
|
|
191
|
+
input.description = description;
|
|
192
|
+
if (cronExpression !== undefined)
|
|
193
|
+
input.cronExpression = cronExpression;
|
|
194
|
+
if (timezone !== undefined)
|
|
195
|
+
input.timezone = timezone;
|
|
196
|
+
if (condition !== undefined)
|
|
197
|
+
input.condition = condition;
|
|
198
|
+
if (recipients !== undefined)
|
|
199
|
+
input.recipients = recipients;
|
|
200
|
+
if (variables !== undefined)
|
|
201
|
+
input.variables = variables;
|
|
202
|
+
if (enabled !== undefined)
|
|
203
|
+
input.enabled = enabled;
|
|
204
|
+
if (Object.keys(input).length === 0) {
|
|
205
|
+
return {
|
|
206
|
+
content: [
|
|
207
|
+
{
|
|
208
|
+
type: "text",
|
|
209
|
+
text: `Error updating alert '${alertId}': no fields to change — pass at least one of name, description, cronExpression, timezone, condition, recipients, variables, enabled.`,
|
|
210
|
+
},
|
|
211
|
+
],
|
|
212
|
+
isError: true,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
const result = yield sdk.alerts.update(alertId, input);
|
|
216
|
+
return {
|
|
217
|
+
content: [
|
|
218
|
+
{ type: "text", text: JSON.stringify(result.data, null, 2) },
|
|
219
|
+
],
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
catch (error) {
|
|
223
|
+
return {
|
|
224
|
+
content: [
|
|
225
|
+
{ type: "text", text: (0, _register_js_1.formatError)(error, `updating alert '${alertId}'`) },
|
|
226
|
+
],
|
|
227
|
+
isError: true,
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
}));
|
|
231
|
+
(0, _register_js_1.registerTool)(server, "delete_alert", "Delete an alert and unschedule its job. This is permanent and drops the alert's evaluation history — to stop notifications while keeping the definition, call update_alert with enabled: false instead.", {
|
|
232
|
+
alertId: zod_1.z.string().describe("The alert ID (UUID) to delete"),
|
|
233
|
+
}, (_a) => __awaiter(this, [_a], void 0, function* ({ alertId }) {
|
|
234
|
+
try {
|
|
235
|
+
yield sdk.alerts.delete(alertId);
|
|
236
|
+
return {
|
|
237
|
+
content: [
|
|
238
|
+
{ type: "text", text: `Alert '${alertId}' deleted.` },
|
|
239
|
+
],
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
catch (error) {
|
|
243
|
+
return {
|
|
244
|
+
content: [
|
|
245
|
+
{ type: "text", text: (0, _register_js_1.formatError)(error, `deleting alert '${alertId}'`) },
|
|
246
|
+
],
|
|
247
|
+
isError: true,
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
}));
|
|
251
|
+
}
|
package/dist/tools/describe.js
CHANGED
|
@@ -102,6 +102,17 @@ function registerDescribeTools(server) {
|
|
|
102
102
|
"test_saved_query",
|
|
103
103
|
],
|
|
104
104
|
},
|
|
105
|
+
alerts: {
|
|
106
|
+
summary: "Scheduled alerts on saved queries. Run a saved query on a cron, compare its row count against a condition, and notify named recipients by email + inbox when it matches — no compute function required.",
|
|
107
|
+
describeWith: "describe_saved_queries",
|
|
108
|
+
tools: [
|
|
109
|
+
"list_alerts",
|
|
110
|
+
"get_alert",
|
|
111
|
+
"create_alert",
|
|
112
|
+
"update_alert",
|
|
113
|
+
"delete_alert",
|
|
114
|
+
],
|
|
115
|
+
},
|
|
105
116
|
orchestrations: {
|
|
106
117
|
summary: "Multi-step workflows that chain compute functions. Support sequential execution with input/output passing between steps.",
|
|
107
118
|
describeWith: "describe_orchestrations",
|
|
@@ -1161,6 +1172,40 @@ function registerDescribeTools(server) {
|
|
|
1161
1172
|
required_params: ["recordSlug", "queryDefinition"],
|
|
1162
1173
|
optional_params: ["variables"],
|
|
1163
1174
|
},
|
|
1175
|
+
list_alerts: {
|
|
1176
|
+
description: "List scheduled alerts on saved queries. Alerts on queries the caller can't read are omitted rather than failing the call.",
|
|
1177
|
+
optional_params: ["savedQueryId"],
|
|
1178
|
+
},
|
|
1179
|
+
get_alert: {
|
|
1180
|
+
description: "Get an alert by ID, including its bound 'variables' and evaluation history ('lastEvaluatedAt', 'lastTriggeredAt', 'lastRowCount').",
|
|
1181
|
+
required_params: ["alertId"],
|
|
1182
|
+
},
|
|
1183
|
+
create_alert: {
|
|
1184
|
+
description: "Create a scheduled alert on a saved query. Requires 'execute' on that saved query, not just alert permissions.",
|
|
1185
|
+
required_params: ["savedQueryId", "name", "cronExpression", "condition", "recipients"],
|
|
1186
|
+
optional_params: ["description", "timezone", "variables", "enabled"],
|
|
1187
|
+
},
|
|
1188
|
+
update_alert: {
|
|
1189
|
+
description: "Update an alert. 'savedQueryId' is immutable. Toggling 'enabled' or changing the cron/timezone reschedules the job; a concurrent change to those fields fails with 409.",
|
|
1190
|
+
required_params: ["alertId"],
|
|
1191
|
+
optional_params: ["name", "description", "cronExpression", "timezone", "condition", "recipients", "variables", "enabled"],
|
|
1192
|
+
},
|
|
1193
|
+
delete_alert: {
|
|
1194
|
+
description: "Delete an alert and unschedule its job. To stop notifications while keeping the definition, use update_alert with enabled: false.",
|
|
1195
|
+
required_params: ["alertId"],
|
|
1196
|
+
},
|
|
1197
|
+
},
|
|
1198
|
+
alerts: {
|
|
1199
|
+
summary: "An alert runs a saved query on a cron, checks the row count against a condition, and notifies explicit recipients by email + inbox. Evaluation is server-side; nothing needs to poll.",
|
|
1200
|
+
condition_kinds: {
|
|
1201
|
+
rowCount: "{ kind: 'rowCount', op, value } — compares the execution's row count against 'value'. 'op' is one of eq, neq, gt, gte, lt, lte.",
|
|
1202
|
+
rowsChanged: "{ kind: 'rowsChanged' } — fires when the row count differs from the previous evaluation. The FIRST run only records a baseline and never fires.",
|
|
1203
|
+
},
|
|
1204
|
+
no_aggregate_kind: "There is no 'aggregate' condition — an alert reasons about how many rows came back, not about a sum or average of their contents. For 'alert when total revenue drops below X', author the saved query so the rows it returns ARE the exception set, then alert on rowCount.",
|
|
1205
|
+
schedule: "'cronExpression' is a 5-field cron expression interpreted in 'timezone' (IANA name, default 'UTC'). Notifications are throttled to 1 per recipient per 15 minutes per alert, so a sub-15-minute cron evaluates more often than it can notify.",
|
|
1206
|
+
recipients: "'recipients' is an explicit list — [{ type: 'user', id: '<userId>' }] — not a subscription list. No MCP tool enumerates workspace users, so ask the user for IDs instead of constructing them.",
|
|
1207
|
+
variable_binding: "Bind the saved query's parameters via 'variables'. The server requires EVERY declaration the query body references that has no 'default', regardless of 'required' — stricter than execute_saved_query. An unbound reference is accepted at execute time and left in the body verbatim, so the alert would filter on the literal '${name}', match nothing, and never fire, with no error anywhere. Authoring is the last point where that's noticeable, so it fails there with a 400 naming each offending variable.",
|
|
1208
|
+
diagnosing: "For 'it never fired': a null/stale 'lastEvaluatedAt' means the alert is disabled or its evaluations are erroring (failures are logged and skipped, leaving the row untouched). A current 'lastEvaluatedAt' with null 'lastTriggeredAt' means the query runs fine and the condition isn't matching — compare the alert's 'variables' against the saved query's declarations.",
|
|
1164
1209
|
},
|
|
1165
1210
|
tips: [
|
|
1166
1211
|
"Use list_saved_queries to discover available queries (optionally filter by collection slug); each row's 'variables' field tells you what to pass",
|
|
@@ -1171,6 +1216,7 @@ function registerDescribeTools(server) {
|
|
|
1171
1216
|
"DO NOT author new saved queries with legacy '$'-prefixed operators ('$eq', '$gte', …) or '{{var}}' placeholders. Both still translate during the deprecation window, but new saved queries must use canonical operators ('eq', 'gte', …) and '${var}' placeholders.",
|
|
1172
1217
|
"For multi-collection reporting, use 'joins[]' (see top-level 'joins' field) — up to 4 joined collections; joinType is 'inner' | 'left' | 'right' | 'full' (RIGHT/FULL gated server-side by 'DATA_QUERY_OUTER_JOINS_ENABLED' — coordinate with ops if you need them). Joined rows arrive under '_joined[alias]' on each primary row. Identifiers ('foreignSlug', 'localField', 'foreignField', 'alias', 'joinType') are literal-only — no '${var}' placeholders. 'text' and 'joins' cannot be combined; 'include' and 'joins' cannot be combined either.",
|
|
1173
1218
|
"Before authoring a join, confirm the user has 'records:list' on every joined collection — saved queries run under SECURITY DEFINER and the data service enforces author-time auth on the primary + every join.",
|
|
1219
|
+
"To notify people when a saved query's result changes, use create_alert rather than a scheduled compute function — see the 'alerts' section above. Read the query's 'variables' first and bind every referenced declaration without a default, or the alert will run clean and never fire.",
|
|
1174
1220
|
],
|
|
1175
1221
|
}, null, 2),
|
|
1176
1222
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@centrali-io/centrali-mcp",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.17.0",
|
|
4
4
|
"description": "Centrali MCP Server - AI assistant integration for Centrali workspaces",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"author": "Blueinit",
|
|
26
26
|
"license": "ISC",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@centrali-io/centrali-sdk": "^6.
|
|
28
|
+
"@centrali-io/centrali-sdk": "^6.17.0",
|
|
29
29
|
"@modelcontextprotocol/sdk": "^1.28.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
package/src/index.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { registerRecordTools } from "./tools/records.js";
|
|
|
8
8
|
import { registerSearchTools } from "./tools/search.js";
|
|
9
9
|
import { registerComputeTools } from "./tools/compute.js";
|
|
10
10
|
import { registerSavedQueryTools } from "./tools/saved-queries.js";
|
|
11
|
+
import { registerAlertTools } from "./tools/alerts.js";
|
|
11
12
|
import { registerOrchestrationTools } from "./tools/orchestrations.js";
|
|
12
13
|
import { registerInsightTools } from "./tools/insights.js";
|
|
13
14
|
import { registerValidationTools } from "./tools/validation.js";
|
|
@@ -72,6 +73,7 @@ async function main() {
|
|
|
72
73
|
registerSearchTools(server, sdk);
|
|
73
74
|
registerComputeTools(server, sdk, baseUrl, workspaceId);
|
|
74
75
|
registerSavedQueryTools(server, sdk);
|
|
76
|
+
registerAlertTools(server, sdk);
|
|
75
77
|
registerOrchestrationTools(server, sdk);
|
|
76
78
|
registerInsightTools(server, sdk);
|
|
77
79
|
registerValidationTools(server, sdk);
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { CentraliSDK } from "@centrali-io/centrali-sdk";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { registerTool, formatError } from "./_register.js";
|
|
5
|
+
|
|
6
|
+
// Saved-query alerts (CEN-1123). An alert runs a saved query on a cron,
|
|
7
|
+
// checks the row count against a condition, and notifies explicit
|
|
8
|
+
// recipients by email + in-app inbox when it matches.
|
|
9
|
+
|
|
10
|
+
const CONDITION_HINT = `The 'condition' decides when the alert fires. Two kinds ship today:
|
|
11
|
+
|
|
12
|
+
{ "kind": "rowCount", "op": "gt", "value": 10 } // op: eq | neq | gt | gte | lt | lte
|
|
13
|
+
{ "kind": "rowsChanged" }
|
|
14
|
+
|
|
15
|
+
'rowCount' compares the execution's row count against 'value'. 'rowsChanged' fires whenever the row count differs from the previous evaluation — its FIRST run only records a baseline and never fires, so don't propose it when the user wants an immediate one-off check.
|
|
16
|
+
|
|
17
|
+
There is no 'aggregate' kind yet: an alert can only reason about how many rows came back, not about a sum or average of their contents. If the user wants "alert when total revenue drops below X", author the saved query so that the rows it returns ARE the exception set (e.g. filter to the offending rows) and alert on 'rowCount', rather than promising an aggregate comparison that doesn't exist.`;
|
|
18
|
+
|
|
19
|
+
const SCHEDULE_HINT = `'cronExpression' is a standard 5-field cron expression ("minute hour day-of-month month day-of-week"), interpreted in 'timezone' (an IANA name like "Europe/London"; defaults to "UTC"). Examples: "0 9 * * 1-5" = 9am every weekday, "*/15 * * * *" = every 15 minutes, "0 0 1 * *" = midnight on the 1st.
|
|
20
|
+
|
|
21
|
+
Each evaluation runs the saved query in full, so prefer the least frequent schedule that satisfies the user's need. Notifications are additionally throttled to 1 per recipient per 15 minutes per alert, so a sub-15-minute cron will evaluate more often than it can notify.`;
|
|
22
|
+
|
|
23
|
+
const VARIABLES_HINT = `If the saved query declares parameters, bind them via 'variables' — a map of variable name to concrete value, validated against the query's declarations by JS typeof (no coercion, so 123 not "123" for a number).
|
|
24
|
+
|
|
25
|
+
Call get_saved_query first and read its 'variables' declarations. Bind EVERY declaration that the query body references and that has no 'default'. This is stricter than executing the query by hand, and the server enforces it: an unbound reference is legal at execute time and gets left in the body verbatim, so the alert would filter on the literal "\${name}", match nothing, and never fire — with no error anywhere, because nobody watches a cron. Declarations the body never references may be omitted.
|
|
26
|
+
|
|
27
|
+
An incomplete map is rejected with a 400 naming each offending variable.`;
|
|
28
|
+
|
|
29
|
+
const RECIPIENTS_HINT = `'recipients' is an explicit list of users — [{ "type": "user", "id": "<userId>" }] — not a subscription list. At least one is required, and only the people listed here are notified.
|
|
30
|
+
|
|
31
|
+
There is no MCP tool that enumerates workspace users, so do NOT guess or construct user IDs. Ask the user for the IDs (they can copy them from the console's workspace members page), or have them create the alert in the console UI where the recipient picker searches members by name.`;
|
|
32
|
+
|
|
33
|
+
export function registerAlertTools(server: McpServer, sdk: CentraliSDK) {
|
|
34
|
+
registerTool<any>(server,
|
|
35
|
+
"list_alerts",
|
|
36
|
+
"List saved-query alerts in the workspace. Each row includes the alert's schedule, condition, recipients, whether it is enabled, and its evaluation history ('lastEvaluatedAt', 'lastTriggeredAt', 'lastRowCount'). Alerts on saved queries the caller can't read are omitted rather than failing the call. Optionally filter to one saved query.",
|
|
37
|
+
{
|
|
38
|
+
savedQueryId: z
|
|
39
|
+
.string()
|
|
40
|
+
.optional()
|
|
41
|
+
.describe("Only return alerts attached to this saved query (UUID). If omitted, lists every readable alert in the workspace."),
|
|
42
|
+
},
|
|
43
|
+
async ({ savedQueryId }) => {
|
|
44
|
+
try {
|
|
45
|
+
const result = await sdk.alerts.list(savedQueryId ? { savedQueryId } : undefined);
|
|
46
|
+
return {
|
|
47
|
+
content: [
|
|
48
|
+
{ type: "text", text: JSON.stringify(result.data, null, 2) },
|
|
49
|
+
],
|
|
50
|
+
};
|
|
51
|
+
} catch (error: unknown) {
|
|
52
|
+
return {
|
|
53
|
+
content: [
|
|
54
|
+
{ type: "text", text: formatError(error, "listing alerts") },
|
|
55
|
+
],
|
|
56
|
+
isError: true,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
registerTool<any>(server,
|
|
63
|
+
"get_alert",
|
|
64
|
+
`Get a saved-query alert by ID, including its bound 'variables', schedule, condition, recipients, and evaluation history.
|
|
65
|
+
|
|
66
|
+
Diagnosing an alert that "never fires": check 'lastEvaluatedAt' first. If it is null or stale, the alert is disabled or its evaluations are failing (a query error is logged and skipped, leaving the row untouched). If it is current but 'lastTriggeredAt' stays null, the query is running fine and the condition simply isn't matching — compare the alert's 'variables' against the saved query's declarations via get_saved_query, since a placeholder the alert leaves unbound filters on a literal that matches nothing.`,
|
|
67
|
+
{
|
|
68
|
+
alertId: z.string().describe("The alert ID (UUID)"),
|
|
69
|
+
},
|
|
70
|
+
async ({ alertId }) => {
|
|
71
|
+
try {
|
|
72
|
+
const result = await sdk.alerts.get(alertId);
|
|
73
|
+
return {
|
|
74
|
+
content: [
|
|
75
|
+
{ type: "text", text: JSON.stringify(result.data, null, 2) },
|
|
76
|
+
],
|
|
77
|
+
};
|
|
78
|
+
} catch (error: unknown) {
|
|
79
|
+
return {
|
|
80
|
+
content: [
|
|
81
|
+
{ type: "text", text: formatError(error, `getting alert '${alertId}'`) },
|
|
82
|
+
],
|
|
83
|
+
isError: true,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
registerTool<any>(server,
|
|
90
|
+
"create_alert",
|
|
91
|
+
`Create a scheduled alert on a saved query. Unless 'enabled' is false, it is scheduled immediately and will start notifying people.
|
|
92
|
+
|
|
93
|
+
Authorization: creating an alert requires permission to manage alerts AND 'execute' on the saved query itself — scheduling recurring runs of a query you can't run yourself is refused with a 403.
|
|
94
|
+
|
|
95
|
+
${CONDITION_HINT}
|
|
96
|
+
|
|
97
|
+
${SCHEDULE_HINT}
|
|
98
|
+
|
|
99
|
+
${VARIABLES_HINT}
|
|
100
|
+
|
|
101
|
+
${RECIPIENTS_HINT}`,
|
|
102
|
+
{
|
|
103
|
+
savedQueryId: z.string().describe("The saved query (UUID) to evaluate on the schedule. Must be in this workspace."),
|
|
104
|
+
name: z.string().describe("Display name, max 255 characters. Used as the notification subject, so make it read as the situation being reported (e.g. 'No open orders') rather than as a job name."),
|
|
105
|
+
description: z.string().optional().describe("Optional context for the alert, max 2000 characters"),
|
|
106
|
+
cronExpression: z.string().describe("5-field cron expression driving evaluation, e.g. '0 9 * * 1-5'"),
|
|
107
|
+
timezone: z.string().optional().describe("IANA timezone the cron is interpreted in, e.g. 'Europe/London'. Defaults to 'UTC' — set it explicitly whenever the user states a wall-clock time."),
|
|
108
|
+
condition: z
|
|
109
|
+
.record(z.string(), z.any())
|
|
110
|
+
.describe("The trigger condition: { kind: 'rowCount', op, value } or { kind: 'rowsChanged' }"),
|
|
111
|
+
recipients: z
|
|
112
|
+
.array(z.record(z.string(), z.any()))
|
|
113
|
+
.describe("Users to notify: [{ type: 'user', id: '<userId>' }]. At least one required."),
|
|
114
|
+
variables: z
|
|
115
|
+
.record(z.string(), z.any())
|
|
116
|
+
.optional()
|
|
117
|
+
.describe("Values bound to the saved query's '${varName}' placeholders on every evaluation. Required for any referenced declaration without a default — see the tool description."),
|
|
118
|
+
enabled: z
|
|
119
|
+
.boolean()
|
|
120
|
+
.optional()
|
|
121
|
+
.describe("Defaults to true. Pass false to author the alert without scheduling it yet."),
|
|
122
|
+
},
|
|
123
|
+
async ({ savedQueryId, name, description, cronExpression, timezone, condition, recipients, variables, enabled }) => {
|
|
124
|
+
try {
|
|
125
|
+
const input: Record<string, any> = {
|
|
126
|
+
savedQueryId,
|
|
127
|
+
name,
|
|
128
|
+
cronExpression,
|
|
129
|
+
condition,
|
|
130
|
+
recipients,
|
|
131
|
+
};
|
|
132
|
+
if (description !== undefined) input.description = description;
|
|
133
|
+
if (timezone !== undefined) input.timezone = timezone;
|
|
134
|
+
if (variables !== undefined) input.variables = variables;
|
|
135
|
+
if (enabled !== undefined) input.enabled = enabled;
|
|
136
|
+
|
|
137
|
+
const result = await sdk.alerts.create(input as any);
|
|
138
|
+
return {
|
|
139
|
+
content: [
|
|
140
|
+
{ type: "text", text: JSON.stringify(result.data, null, 2) },
|
|
141
|
+
],
|
|
142
|
+
};
|
|
143
|
+
} catch (error: unknown) {
|
|
144
|
+
return {
|
|
145
|
+
content: [
|
|
146
|
+
{ type: "text", text: formatError(error, `creating alert '${name}'`) },
|
|
147
|
+
],
|
|
148
|
+
isError: true,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
registerTool<any>(server,
|
|
155
|
+
"update_alert",
|
|
156
|
+
`Update an alert. Only include the fields you want to change.
|
|
157
|
+
|
|
158
|
+
'savedQueryId' is immutable — to point an alert at a different query, delete it and create a new one.
|
|
159
|
+
|
|
160
|
+
Toggling 'enabled' or changing 'cronExpression'/'timezone' reschedules the underlying job. If another request changes the same alert concurrently, this fails with 409; refetch with get_alert and reapply rather than retrying the same body.
|
|
161
|
+
|
|
162
|
+
Passing 'variables' REPLACES the stored bindings wholesale (it is not merged), and the replacement is validated under the same rule as create — see below. Omit it to leave the existing bindings untouched.
|
|
163
|
+
|
|
164
|
+
${CONDITION_HINT}
|
|
165
|
+
|
|
166
|
+
${SCHEDULE_HINT}
|
|
167
|
+
|
|
168
|
+
${VARIABLES_HINT}
|
|
169
|
+
|
|
170
|
+
${RECIPIENTS_HINT}`,
|
|
171
|
+
{
|
|
172
|
+
alertId: z.string().describe("The alert ID (UUID) to update"),
|
|
173
|
+
name: z.string().optional().describe("Updated display name"),
|
|
174
|
+
description: z
|
|
175
|
+
.union([z.string(), z.null()])
|
|
176
|
+
.optional()
|
|
177
|
+
.describe("Updated description. Pass null to clear it; omit to leave it unchanged."),
|
|
178
|
+
cronExpression: z.string().optional().describe("Updated cron expression — reschedules the job"),
|
|
179
|
+
timezone: z.string().optional().describe("Updated IANA timezone — reschedules the job"),
|
|
180
|
+
condition: z
|
|
181
|
+
.record(z.string(), z.any())
|
|
182
|
+
.optional()
|
|
183
|
+
.describe("Updated trigger condition"),
|
|
184
|
+
recipients: z
|
|
185
|
+
.array(z.record(z.string(), z.any()))
|
|
186
|
+
.optional()
|
|
187
|
+
.describe("Replacement recipient list: [{ type: 'user', id: '<userId>' }]. Replaces the existing list wholesale."),
|
|
188
|
+
variables: z
|
|
189
|
+
.record(z.string(), z.any())
|
|
190
|
+
.optional()
|
|
191
|
+
.describe("Replacement variable bindings. Replaces the stored map wholesale; omit to leave it unchanged."),
|
|
192
|
+
enabled: z
|
|
193
|
+
.boolean()
|
|
194
|
+
.optional()
|
|
195
|
+
.describe("Pause (false) or resume (true) the alert. Pausing keeps the definition and its evaluation history."),
|
|
196
|
+
},
|
|
197
|
+
async ({ alertId, name, description, cronExpression, timezone, condition, recipients, variables, enabled }) => {
|
|
198
|
+
try {
|
|
199
|
+
const input: Record<string, any> = {};
|
|
200
|
+
if (name !== undefined) input.name = name;
|
|
201
|
+
if (description !== undefined) input.description = description;
|
|
202
|
+
if (cronExpression !== undefined) input.cronExpression = cronExpression;
|
|
203
|
+
if (timezone !== undefined) input.timezone = timezone;
|
|
204
|
+
if (condition !== undefined) input.condition = condition;
|
|
205
|
+
if (recipients !== undefined) input.recipients = recipients;
|
|
206
|
+
if (variables !== undefined) input.variables = variables;
|
|
207
|
+
if (enabled !== undefined) input.enabled = enabled;
|
|
208
|
+
|
|
209
|
+
if (Object.keys(input).length === 0) {
|
|
210
|
+
return {
|
|
211
|
+
content: [
|
|
212
|
+
{
|
|
213
|
+
type: "text",
|
|
214
|
+
text: `Error updating alert '${alertId}': no fields to change — pass at least one of name, description, cronExpression, timezone, condition, recipients, variables, enabled.`,
|
|
215
|
+
},
|
|
216
|
+
],
|
|
217
|
+
isError: true,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const result = await sdk.alerts.update(alertId, input as any);
|
|
222
|
+
return {
|
|
223
|
+
content: [
|
|
224
|
+
{ type: "text", text: JSON.stringify(result.data, null, 2) },
|
|
225
|
+
],
|
|
226
|
+
};
|
|
227
|
+
} catch (error: unknown) {
|
|
228
|
+
return {
|
|
229
|
+
content: [
|
|
230
|
+
{ type: "text", text: formatError(error, `updating alert '${alertId}'`) },
|
|
231
|
+
],
|
|
232
|
+
isError: true,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
);
|
|
237
|
+
|
|
238
|
+
registerTool<any>(server,
|
|
239
|
+
"delete_alert",
|
|
240
|
+
"Delete an alert and unschedule its job. This is permanent and drops the alert's evaluation history — to stop notifications while keeping the definition, call update_alert with enabled: false instead.",
|
|
241
|
+
{
|
|
242
|
+
alertId: z.string().describe("The alert ID (UUID) to delete"),
|
|
243
|
+
},
|
|
244
|
+
async ({ alertId }) => {
|
|
245
|
+
try {
|
|
246
|
+
await sdk.alerts.delete(alertId);
|
|
247
|
+
return {
|
|
248
|
+
content: [
|
|
249
|
+
{ type: "text", text: `Alert '${alertId}' deleted.` },
|
|
250
|
+
],
|
|
251
|
+
};
|
|
252
|
+
} catch (error: unknown) {
|
|
253
|
+
return {
|
|
254
|
+
content: [
|
|
255
|
+
{ type: "text", text: formatError(error, `deleting alert '${alertId}'`) },
|
|
256
|
+
],
|
|
257
|
+
isError: true,
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
);
|
|
262
|
+
}
|
package/src/tools/describe.ts
CHANGED
|
@@ -103,6 +103,18 @@ export function registerDescribeTools(server: McpServer) {
|
|
|
103
103
|
"test_saved_query",
|
|
104
104
|
],
|
|
105
105
|
},
|
|
106
|
+
alerts: {
|
|
107
|
+
summary:
|
|
108
|
+
"Scheduled alerts on saved queries. Run a saved query on a cron, compare its row count against a condition, and notify named recipients by email + inbox when it matches — no compute function required.",
|
|
109
|
+
describeWith: "describe_saved_queries",
|
|
110
|
+
tools: [
|
|
111
|
+
"list_alerts",
|
|
112
|
+
"get_alert",
|
|
113
|
+
"create_alert",
|
|
114
|
+
"update_alert",
|
|
115
|
+
"delete_alert",
|
|
116
|
+
],
|
|
117
|
+
},
|
|
106
118
|
orchestrations: {
|
|
107
119
|
summary:
|
|
108
120
|
"Multi-step workflows that chain compute functions. Support sequential execution with input/output passing between steps.",
|
|
@@ -1260,6 +1272,48 @@ export function registerDescribeTools(server: McpServer) {
|
|
|
1260
1272
|
required_params: ["recordSlug", "queryDefinition"],
|
|
1261
1273
|
optional_params: ["variables"],
|
|
1262
1274
|
},
|
|
1275
|
+
list_alerts: {
|
|
1276
|
+
description: "List scheduled alerts on saved queries. Alerts on queries the caller can't read are omitted rather than failing the call.",
|
|
1277
|
+
optional_params: ["savedQueryId"],
|
|
1278
|
+
},
|
|
1279
|
+
get_alert: {
|
|
1280
|
+
description: "Get an alert by ID, including its bound 'variables' and evaluation history ('lastEvaluatedAt', 'lastTriggeredAt', 'lastRowCount').",
|
|
1281
|
+
required_params: ["alertId"],
|
|
1282
|
+
},
|
|
1283
|
+
create_alert: {
|
|
1284
|
+
description: "Create a scheduled alert on a saved query. Requires 'execute' on that saved query, not just alert permissions.",
|
|
1285
|
+
required_params: ["savedQueryId", "name", "cronExpression", "condition", "recipients"],
|
|
1286
|
+
optional_params: ["description", "timezone", "variables", "enabled"],
|
|
1287
|
+
},
|
|
1288
|
+
update_alert: {
|
|
1289
|
+
description: "Update an alert. 'savedQueryId' is immutable. Toggling 'enabled' or changing the cron/timezone reschedules the job; a concurrent change to those fields fails with 409.",
|
|
1290
|
+
required_params: ["alertId"],
|
|
1291
|
+
optional_params: ["name", "description", "cronExpression", "timezone", "condition", "recipients", "variables", "enabled"],
|
|
1292
|
+
},
|
|
1293
|
+
delete_alert: {
|
|
1294
|
+
description: "Delete an alert and unschedule its job. To stop notifications while keeping the definition, use update_alert with enabled: false.",
|
|
1295
|
+
required_params: ["alertId"],
|
|
1296
|
+
},
|
|
1297
|
+
},
|
|
1298
|
+
alerts: {
|
|
1299
|
+
summary:
|
|
1300
|
+
"An alert runs a saved query on a cron, checks the row count against a condition, and notifies explicit recipients by email + inbox. Evaluation is server-side; nothing needs to poll.",
|
|
1301
|
+
condition_kinds: {
|
|
1302
|
+
rowCount:
|
|
1303
|
+
"{ kind: 'rowCount', op, value } — compares the execution's row count against 'value'. 'op' is one of eq, neq, gt, gte, lt, lte.",
|
|
1304
|
+
rowsChanged:
|
|
1305
|
+
"{ kind: 'rowsChanged' } — fires when the row count differs from the previous evaluation. The FIRST run only records a baseline and never fires.",
|
|
1306
|
+
},
|
|
1307
|
+
no_aggregate_kind:
|
|
1308
|
+
"There is no 'aggregate' condition — an alert reasons about how many rows came back, not about a sum or average of their contents. For 'alert when total revenue drops below X', author the saved query so the rows it returns ARE the exception set, then alert on rowCount.",
|
|
1309
|
+
schedule:
|
|
1310
|
+
"'cronExpression' is a 5-field cron expression interpreted in 'timezone' (IANA name, default 'UTC'). Notifications are throttled to 1 per recipient per 15 minutes per alert, so a sub-15-minute cron evaluates more often than it can notify.",
|
|
1311
|
+
recipients:
|
|
1312
|
+
"'recipients' is an explicit list — [{ type: 'user', id: '<userId>' }] — not a subscription list. No MCP tool enumerates workspace users, so ask the user for IDs instead of constructing them.",
|
|
1313
|
+
variable_binding:
|
|
1314
|
+
"Bind the saved query's parameters via 'variables'. The server requires EVERY declaration the query body references that has no 'default', regardless of 'required' — stricter than execute_saved_query. An unbound reference is accepted at execute time and left in the body verbatim, so the alert would filter on the literal '${name}', match nothing, and never fire, with no error anywhere. Authoring is the last point where that's noticeable, so it fails there with a 400 naming each offending variable.",
|
|
1315
|
+
diagnosing:
|
|
1316
|
+
"For 'it never fired': a null/stale 'lastEvaluatedAt' means the alert is disabled or its evaluations are erroring (failures are logged and skipped, leaving the row untouched). A current 'lastEvaluatedAt' with null 'lastTriggeredAt' means the query runs fine and the condition isn't matching — compare the alert's 'variables' against the saved query's declarations.",
|
|
1263
1317
|
},
|
|
1264
1318
|
tips: [
|
|
1265
1319
|
"Use list_saved_queries to discover available queries (optionally filter by collection slug); each row's 'variables' field tells you what to pass",
|
|
@@ -1270,6 +1324,7 @@ export function registerDescribeTools(server: McpServer) {
|
|
|
1270
1324
|
"DO NOT author new saved queries with legacy '$'-prefixed operators ('$eq', '$gte', …) or '{{var}}' placeholders. Both still translate during the deprecation window, but new saved queries must use canonical operators ('eq', 'gte', …) and '${var}' placeholders.",
|
|
1271
1325
|
"For multi-collection reporting, use 'joins[]' (see top-level 'joins' field) — up to 4 joined collections; joinType is 'inner' | 'left' | 'right' | 'full' (RIGHT/FULL gated server-side by 'DATA_QUERY_OUTER_JOINS_ENABLED' — coordinate with ops if you need them). Joined rows arrive under '_joined[alias]' on each primary row. Identifiers ('foreignSlug', 'localField', 'foreignField', 'alias', 'joinType') are literal-only — no '${var}' placeholders. 'text' and 'joins' cannot be combined; 'include' and 'joins' cannot be combined either.",
|
|
1272
1326
|
"Before authoring a join, confirm the user has 'records:list' on every joined collection — saved queries run under SECURITY DEFINER and the data service enforces author-time auth on the primary + every join.",
|
|
1327
|
+
"To notify people when a saved query's result changes, use create_alert rather than a scheduled compute function — see the 'alerts' section above. Read the query's 'variables' first and bind every referenced declaration without a default, or the alert will run clean and never fire.",
|
|
1273
1328
|
],
|
|
1274
1329
|
},
|
|
1275
1330
|
null,
|