@notifkit/mcp 0.1.4 → 0.1.6
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 +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/tools/operations.d.ts +4 -0
- package/dist/tools/operations.d.ts.map +1 -0
- package/dist/tools/operations.js +54 -0
- package/dist/tools/operations.js.map +1 -0
- package/dist/tools/projects.d.ts +4 -0
- package/dist/tools/projects.d.ts.map +1 -0
- package/dist/tools/projects.js +88 -0
- package/dist/tools/projects.js.map +1 -0
- package/dist/tools/sending.d.ts +4 -0
- package/dist/tools/sending.d.ts.map +1 -0
- package/dist/tools/sending.js +375 -0
- package/dist/tools/sending.js.map +1 -0
- package/dist/tools/shared.d.ts +17 -0
- package/dist/tools/shared.d.ts.map +1 -0
- package/dist/tools/shared.js +110 -0
- package/dist/tools/shared.js.map +1 -0
- package/dist/tools/templates.d.ts +4 -0
- package/dist/tools/templates.d.ts.map +1 -0
- package/dist/tools/templates.js +149 -0
- package/dist/tools/templates.js.map +1 -0
- package/dist/tools/users.d.ts +4 -0
- package/dist/tools/users.d.ts.map +1 -0
- package/dist/tools/users.js +251 -0
- package/dist/tools/users.js.map +1 -0
- package/dist/tools/workflows.d.ts +4 -0
- package/dist/tools/workflows.d.ts.map +1 -0
- package/dist/tools/workflows.js +115 -0
- package/dist/tools/workflows.js.map +1 -0
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +12 -1124
- package/dist/tools.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +7 -1
- package/src/tools/operations.ts +84 -0
- package/src/tools/projects.ts +131 -0
- package/src/tools/sending.ts +484 -0
- package/src/tools/shared.ts +129 -0
- package/src/tools/templates.ts +206 -0
- package/src/tools/users.ts +330 -0
- package/src/tools/workflows.ts +158 -0
- package/src/tools.ts +12 -1502
package/dist/tools.js
CHANGED
|
@@ -1,1127 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
"webhook",
|
|
8
|
-
"in-app",
|
|
9
|
-
"telegram",
|
|
10
|
-
"discord",
|
|
11
|
-
"whatsapp",
|
|
12
|
-
"slack",
|
|
13
|
-
];
|
|
14
|
-
const CONTACT_CHANNELS = [
|
|
15
|
-
"email",
|
|
16
|
-
"sms",
|
|
17
|
-
"push",
|
|
18
|
-
"webhook",
|
|
19
|
-
"telegram",
|
|
20
|
-
"discord",
|
|
21
|
-
"whatsapp",
|
|
22
|
-
"slack",
|
|
23
|
-
];
|
|
24
|
-
const PRIORITIES = ["low", "normal", "high", "critical"];
|
|
25
|
-
/** Render any handler return value as the text payload MCP clients expect. */
|
|
26
|
-
function ok(value) {
|
|
27
|
-
const text = value === undefined
|
|
28
|
-
? "Done."
|
|
29
|
-
: typeof value === "string"
|
|
30
|
-
? value
|
|
31
|
-
: JSON.stringify(value, null, 2);
|
|
32
|
-
return { content: [{ type: "text", text }] };
|
|
33
|
-
}
|
|
34
|
-
function fail(error) {
|
|
35
|
-
const text = error instanceof NotifkitApiError
|
|
36
|
-
? `notifkit API error (HTTP ${error.status}): ${error.message}`
|
|
37
|
-
: error instanceof Error
|
|
38
|
-
? error.message
|
|
39
|
-
: String(error);
|
|
40
|
-
return { content: [{ type: "text", text }], isError: true };
|
|
41
|
-
}
|
|
42
|
-
/** Wrap a handler so a failed request is reported to the model instead of killing the server. */
|
|
43
|
-
function handler(fn) {
|
|
44
|
-
return async (args) => {
|
|
45
|
-
try {
|
|
46
|
-
return ok(await fn(args));
|
|
47
|
-
}
|
|
48
|
-
catch (error) {
|
|
49
|
-
return fail(error);
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
function escapeHtml(unsafe) {
|
|
54
|
-
return String(unsafe)
|
|
55
|
-
.replace(/&/g, "&")
|
|
56
|
-
.replace(/</g, "<")
|
|
57
|
-
.replace(/>/g, ">")
|
|
58
|
-
.replace(/"/g, """)
|
|
59
|
-
.replace(/'/g, "'");
|
|
60
|
-
}
|
|
61
|
-
function escapeHeader(unsafe) {
|
|
62
|
-
return String(unsafe)
|
|
63
|
-
.replace(/[\r\n]+/g, " ")
|
|
64
|
-
.trim();
|
|
65
|
-
}
|
|
66
|
-
const HTML_FIELDS = new Set(["html", "htmlbody", "bodyhtml", "htmlcontent"]);
|
|
67
|
-
const HEADER_FIELDS = new Set([
|
|
68
|
-
"subject",
|
|
69
|
-
"title",
|
|
70
|
-
"from",
|
|
71
|
-
"replyto",
|
|
72
|
-
"cc",
|
|
73
|
-
"bcc",
|
|
74
|
-
"preheader",
|
|
75
|
-
"preview",
|
|
76
|
-
]);
|
|
77
|
-
function escapeModeFor(key, inherited) {
|
|
78
|
-
const k = key.toLowerCase().replace(/[-_]/g, "");
|
|
79
|
-
if (HTML_FIELDS.has(k))
|
|
80
|
-
return "html";
|
|
81
|
-
if (HEADER_FIELDS.has(k))
|
|
82
|
-
return "header";
|
|
83
|
-
return inherited;
|
|
84
|
-
}
|
|
85
|
-
function interpolateValue(tmpl, variables, mode) {
|
|
86
|
-
return tmpl
|
|
87
|
-
.replace(/\{\{\{(\w+)\}\}\}/g, (_, k) => {
|
|
88
|
-
const raw = variables[k];
|
|
89
|
-
if (raw === undefined || raw === null)
|
|
90
|
-
return "";
|
|
91
|
-
return typeof raw === "string" ? raw : JSON.stringify(raw);
|
|
92
|
-
})
|
|
93
|
-
.replace(/\{\{(\w+)\}\}/g, (_, k) => {
|
|
94
|
-
const raw = variables[k];
|
|
95
|
-
if (raw === undefined || raw === null)
|
|
96
|
-
return "";
|
|
97
|
-
const val = typeof raw === "string" ? raw : JSON.stringify(raw);
|
|
98
|
-
if (mode === "html")
|
|
99
|
-
return escapeHtml(val);
|
|
100
|
-
if (mode === "header")
|
|
101
|
-
return escapeHeader(val);
|
|
102
|
-
return val;
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
function renderContentNode(node, variables, mode) {
|
|
106
|
-
if (typeof node === "string")
|
|
107
|
-
return interpolateValue(node, variables, mode);
|
|
108
|
-
if (Array.isArray(node))
|
|
109
|
-
return node.map((item) => renderContentNode(item, variables, mode));
|
|
110
|
-
if (node && typeof node === "object") {
|
|
111
|
-
const out = {};
|
|
112
|
-
for (const [key, value] of Object.entries(node)) {
|
|
113
|
-
out[key] = renderContentNode(value, variables, escapeModeFor(key, mode));
|
|
114
|
-
}
|
|
115
|
-
return out;
|
|
116
|
-
}
|
|
117
|
-
return node;
|
|
118
|
-
}
|
|
1
|
+
import { registerSendingTools } from "./tools/sending.js";
|
|
2
|
+
import { registerTemplatesTools } from "./tools/templates.js";
|
|
3
|
+
import { registerUsersTools } from "./tools/users.js";
|
|
4
|
+
import { registerWorkflowsTools } from "./tools/workflows.js";
|
|
5
|
+
import { registerOperationsTools } from "./tools/operations.js";
|
|
6
|
+
import { registerProjectsTools } from "./tools/projects.js";
|
|
119
7
|
export function registerTools(server, api) {
|
|
120
|
-
|
|
121
|
-
server
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
"`segment`, or `topic` must be given. Set `sendAt` to schedule a future send, which can then be " +
|
|
127
|
-
"inspected with list_scheduled. Delivery is filtered by each recipient's preferences, consent, and " +
|
|
128
|
-
"quiet hours, so the number of messages actually delivered is usually lower than the audience size. " +
|
|
129
|
-
"Call list_segments first when the user names an audience you have not confirmed exists, and " +
|
|
130
|
-
"list_templates when you are unsure of the template id.",
|
|
131
|
-
inputSchema: {
|
|
132
|
-
template: z.string().min(1).describe("Template id to render, e.g. 'order-shipped'."),
|
|
133
|
-
user: z
|
|
134
|
-
.union([z.string().min(1), z.array(z.string().min(1)).nonempty()])
|
|
135
|
-
.optional()
|
|
136
|
-
.describe("A single user id or a list of user ids. Mutually exclusive with segment and topic."),
|
|
137
|
-
segment: z
|
|
138
|
-
.string()
|
|
139
|
-
.min(1)
|
|
140
|
-
.optional()
|
|
141
|
-
.describe("Send to every user tagged with this segment. Mutually exclusive with user and topic."),
|
|
142
|
-
topic: z
|
|
143
|
-
.string()
|
|
144
|
-
.min(1)
|
|
145
|
-
.optional()
|
|
146
|
-
.describe("Send to every user opted in to this topic. Mutually exclusive with user and segment."),
|
|
147
|
-
data: z
|
|
148
|
-
.record(z.string(), z.unknown())
|
|
149
|
-
.optional()
|
|
150
|
-
.describe("Variables interpolated into the template's {{placeholders}}."),
|
|
151
|
-
channels: z
|
|
152
|
-
.array(z.enum(CHANNELS))
|
|
153
|
-
.nonempty()
|
|
154
|
-
.optional()
|
|
155
|
-
.describe("Channels to use. Defaults to whatever the template defines."),
|
|
156
|
-
fallback: z
|
|
157
|
-
.boolean()
|
|
158
|
-
.optional()
|
|
159
|
-
.describe("When true, channels are tried in order and only the first success counts. When false or " +
|
|
160
|
-
"omitted, every listed channel is delivered to."),
|
|
161
|
-
priority: z
|
|
162
|
-
.enum(PRIORITIES)
|
|
163
|
-
.optional()
|
|
164
|
-
.describe("Queue lane. 'critical' bypasses quiet hours and per-user rate limits."),
|
|
165
|
-
sendAt: z
|
|
166
|
-
.string()
|
|
167
|
-
.datetime()
|
|
168
|
-
.optional()
|
|
169
|
-
.describe("ISO 8601 timestamp to send at. Omit to send now."),
|
|
170
|
-
campaign: z
|
|
171
|
-
.string()
|
|
172
|
-
.min(1)
|
|
173
|
-
.max(128)
|
|
174
|
-
.optional()
|
|
175
|
-
.describe("Label grouping this send for later reporting via get_campaign_stats. Set it on any send " +
|
|
176
|
-
"whose results someone may ask about; without it the messages cannot be attributed."),
|
|
177
|
-
},
|
|
178
|
-
annotations: { title: "Send a notification", readOnlyHint: false, idempotentHint: false },
|
|
179
|
-
}, handler(async (args) => {
|
|
180
|
-
const targets = [args.user, args.segment, args.topic].filter((t) => t !== undefined);
|
|
181
|
-
if (targets.length !== 1) {
|
|
182
|
-
throw new Error("Provide exactly one of `user`, `segment`, or `topic`.");
|
|
183
|
-
}
|
|
184
|
-
return api.post("/v1/notify", args);
|
|
185
|
-
}));
|
|
186
|
-
server.registerTool("send_campaign", {
|
|
187
|
-
title: "Send a campaign to a list of addresses",
|
|
188
|
-
description: "Send one template to a list of recipient destinations (email, SMS/phone, push tokens, webhook URLs, " +
|
|
189
|
-
"Telegram chat ids, Discord webhook URLs, WhatsApp phone numbers, or Slack channel/user IDs/webhook URLs) given directly — the tool creates or updates a user " +
|
|
190
|
-
"record for each address, then sends, and tags every message with a campaign label so the results " +
|
|
191
|
-
"can be read back later with get_campaign_stats. Supports 'email', 'sms', 'push', 'webhook', " +
|
|
192
|
-
"'telegram', 'discord', 'whatsapp', and 'slack' channels. Use this when the person supplies the recipients themselves " +
|
|
193
|
-
"(a pasted list, a spreadsheet column). Always report the returned campaign label back to the user " +
|
|
194
|
-
"— it is how they ask about results later. Suppressed addresses (previous unsubscribes, complaints, " +
|
|
195
|
-
"hard bounces) are dropped automatically at send time, so the delivered count is normally lower than " +
|
|
196
|
-
"the list size.",
|
|
197
|
-
inputSchema: {
|
|
198
|
-
campaign: z
|
|
199
|
-
.string()
|
|
200
|
-
.min(1)
|
|
201
|
-
.max(128)
|
|
202
|
-
.describe("Label for this send, e.g. 'spring-sale-2026-08-13'. Must be unique per send — reusing a " +
|
|
203
|
-
"label merges the two into one set of statistics."),
|
|
204
|
-
template: z.string().min(1).describe("Template id to render."),
|
|
205
|
-
channel: z
|
|
206
|
-
.enum(CONTACT_CHANNELS)
|
|
207
|
-
.optional()
|
|
208
|
-
.describe("Channel to send on ('email', 'sms', 'push', 'webhook', 'telegram', 'discord', 'whatsapp', or 'slack'). Defaults to 'email'."),
|
|
209
|
-
recipients: z
|
|
210
|
-
.array(z.string().min(1))
|
|
211
|
-
.min(1)
|
|
212
|
-
.max(10000)
|
|
213
|
-
.optional()
|
|
214
|
-
.describe("Recipient destination addresses: email addresses for email, E.164 phone numbers for sms/whatsapp, " +
|
|
215
|
-
"device tokens for push, URLs for webhook, chat ids for telegram, webhook URLs for discord, or channel/user IDs for slack."),
|
|
216
|
-
emails: z
|
|
217
|
-
.array(z.string().email())
|
|
218
|
-
.min(1)
|
|
219
|
-
.max(10000)
|
|
220
|
-
.optional()
|
|
221
|
-
.describe("Recipient email addresses (alias for recipients when sending on email channel)."),
|
|
222
|
-
data: z
|
|
223
|
-
.record(z.string(), z.unknown())
|
|
224
|
-
.optional()
|
|
225
|
-
.describe("Variables interpolated into the template, shared by every recipient."),
|
|
226
|
-
priority: z
|
|
227
|
-
.enum(PRIORITIES)
|
|
228
|
-
.optional()
|
|
229
|
-
.describe("Queue lane. Leave unset for 'normal'; do not use 'critical' for marketing sends."),
|
|
230
|
-
sendAt: z
|
|
231
|
-
.string()
|
|
232
|
-
.datetime()
|
|
233
|
-
.optional()
|
|
234
|
-
.describe("ISO 8601 timestamp to send at. Omit to send now."),
|
|
235
|
-
},
|
|
236
|
-
annotations: { title: "Send a campaign", readOnlyHint: false, idempotentHint: false },
|
|
237
|
-
}, handler(async (args) => {
|
|
238
|
-
const channel = args.channel ?? "email";
|
|
239
|
-
const rawList = args.recipients ?? args.emails;
|
|
240
|
-
if (!rawList || rawList.length === 0) {
|
|
241
|
-
throw new Error("Provide a list of `recipients` (or `emails`) to send to.");
|
|
242
|
-
}
|
|
243
|
-
const seen = new Set();
|
|
244
|
-
const recipients = [];
|
|
245
|
-
for (const raw of rawList) {
|
|
246
|
-
const target = channel === "email" ? raw.trim().toLowerCase() : raw.trim();
|
|
247
|
-
if (seen.has(target))
|
|
248
|
-
continue;
|
|
249
|
-
seen.add(target);
|
|
250
|
-
// Every channel needs a contact on that channel to be reached. Chat
|
|
251
|
-
// channels used to get a bare user record, and WhatsApp a phone
|
|
252
|
-
// number filed as an SMS contact, so those campaigns sent nothing.
|
|
253
|
-
const userRecord = channel === "email"
|
|
254
|
-
? { id: `email:${target}`, email: target }
|
|
255
|
-
: channel === "sms"
|
|
256
|
-
? { id: `phone:${target}`, phone: target }
|
|
257
|
-
: channel === "push"
|
|
258
|
-
? { id: `push:${target}`, pushToken: target }
|
|
259
|
-
: { id: `${channel}:${target}`, contacts: [{ channel, target }] };
|
|
260
|
-
recipients.push(userRecord);
|
|
261
|
-
}
|
|
262
|
-
const result = await api.post("/v1/notify", {
|
|
263
|
-
user: recipients,
|
|
264
|
-
template: args.template,
|
|
265
|
-
campaign: args.campaign,
|
|
266
|
-
channels: [channel],
|
|
267
|
-
...(args.data ? { data: args.data } : {}),
|
|
268
|
-
...(args.priority ? { priority: args.priority } : {}),
|
|
269
|
-
...(args.sendAt ? { sendAt: args.sendAt } : {}),
|
|
270
|
-
});
|
|
271
|
-
const duplicates = rawList.length - recipients.length;
|
|
272
|
-
return {
|
|
273
|
-
campaign: args.campaign,
|
|
274
|
-
channel,
|
|
275
|
-
queued: recipients.length,
|
|
276
|
-
...(duplicates > 0 ? { duplicatesRemoved: duplicates } : {}),
|
|
277
|
-
note: "Queued, not yet delivered. Preferences, quiet hours, and suppressions are applied during " +
|
|
278
|
-
"delivery — call get_campaign_stats for what actually landed.",
|
|
279
|
-
result,
|
|
280
|
-
};
|
|
281
|
-
}));
|
|
282
|
-
server.registerTool("list_campaigns", {
|
|
283
|
-
title: "List campaigns",
|
|
284
|
-
description: "List recent campaign labels with their size and when they last saw activity, newest first. Call " +
|
|
285
|
-
"this when the user refers to a past send without naming its exact label ('the one I sent " +
|
|
286
|
-
"yesterday') to find the label to pass to get_campaign_stats. Supports filtering by search query, " +
|
|
287
|
-
"channel, date range, or minimum message count.",
|
|
288
|
-
inputSchema: {
|
|
289
|
-
limit: z
|
|
290
|
-
.number()
|
|
291
|
-
.int()
|
|
292
|
-
.min(1)
|
|
293
|
-
.max(100)
|
|
294
|
-
.optional()
|
|
295
|
-
.describe("How many campaigns to return. Defaults to 20."),
|
|
296
|
-
search: z
|
|
297
|
-
.string()
|
|
298
|
-
.optional()
|
|
299
|
-
.describe("Filter campaigns whose label contains this string (case-insensitive)."),
|
|
300
|
-
channel: z
|
|
301
|
-
.enum(CHANNELS)
|
|
302
|
-
.optional()
|
|
303
|
-
.describe("Only list campaigns that sent messages on this channel."),
|
|
304
|
-
since: z
|
|
305
|
-
.string()
|
|
306
|
-
.datetime()
|
|
307
|
-
.optional()
|
|
308
|
-
.describe("ISO 8601 timestamp; only return campaigns with activity on or after this date."),
|
|
309
|
-
until: z
|
|
310
|
-
.string()
|
|
311
|
-
.datetime()
|
|
312
|
-
.optional()
|
|
313
|
-
.describe("ISO 8601 timestamp; only return campaigns with activity on or before this date."),
|
|
314
|
-
minMessages: z
|
|
315
|
-
.number()
|
|
316
|
-
.int()
|
|
317
|
-
.min(1)
|
|
318
|
-
.optional()
|
|
319
|
-
.describe("Minimum number of distinct messages/recipients for a campaign."),
|
|
320
|
-
},
|
|
321
|
-
annotations: { title: "List campaigns", readOnlyHint: true },
|
|
322
|
-
}, handler(async (args) => api.get("/v1/campaigns", args)));
|
|
323
|
-
server.registerTool("get_campaign_stats", {
|
|
324
|
-
title: "Get campaign performance",
|
|
325
|
-
description: "The delivery and engagement funnel for one campaign: sent, delivered, failed, opened, clicked, " +
|
|
326
|
-
"bounced, complained, unsubscribed, with rates and a per-channel breakdown. This is the tool for " +
|
|
327
|
-
"'how did that send perform?'. Every count is people, not events — opening an email twice counts " +
|
|
328
|
-
"once. Always surface the `warnings` field to the user: it says when opens and clicks are not " +
|
|
329
|
-
"tracked on a channel, which is different from them being zero. A high complaint rate (above " +
|
|
330
|
-
"~0.3%) is worth flagging unprompted, as it damages deliverability for all future sends.",
|
|
331
|
-
inputSchema: {
|
|
332
|
-
campaign: z.string().min(1).describe("Campaign label, as returned by list_campaigns."),
|
|
333
|
-
},
|
|
334
|
-
annotations: { title: "Get campaign performance", readOnlyHint: true },
|
|
335
|
-
}, handler(async (args) => api.get(`/v1/campaigns/${encodeURIComponent(args.campaign)}/stats`)));
|
|
336
|
-
server.registerTool("list_suppressions", {
|
|
337
|
-
title: "List suppressed addresses",
|
|
338
|
-
description: "List destinations that will not be contacted again, with the reason each was suppressed " +
|
|
339
|
-
"(unsubscribed, complained, bounced, or manual). Call this to explain why someone did not receive " +
|
|
340
|
-
"a message, or to review unsubscribes after a campaign.",
|
|
341
|
-
inputSchema: {
|
|
342
|
-
limit: z.number().int().min(1).max(500).optional().describe("How many rows to return."),
|
|
343
|
-
channel: z.enum(CONTACT_CHANNELS).optional().describe("Only this channel."),
|
|
344
|
-
reason: z
|
|
345
|
-
.enum(["unsubscribed", "complained", "bounced", "manual"])
|
|
346
|
-
.optional()
|
|
347
|
-
.describe("Only suppressions with this reason."),
|
|
348
|
-
target: z
|
|
349
|
-
.string()
|
|
350
|
-
.optional()
|
|
351
|
-
.describe("Filter suppressions matching this email, phone, or push token."),
|
|
352
|
-
},
|
|
353
|
-
annotations: { title: "List suppressed addresses", readOnlyHint: true },
|
|
354
|
-
}, handler(async (args) => api.get("/v1/suppressions", args)));
|
|
355
|
-
server.registerTool("suppress_address", {
|
|
356
|
-
title: "Suppress an address",
|
|
357
|
-
description: "Stop sending to a destination on a channel — use when someone asks to be removed by replying, " +
|
|
358
|
-
"over the phone, or any route the provider does not report automatically. Takes effect on the " +
|
|
359
|
-
"next send and outranks every other setting, including 'critical' priority.",
|
|
360
|
-
inputSchema: {
|
|
361
|
-
channel: z.enum(CONTACT_CHANNELS).describe("Channel to suppress on."),
|
|
362
|
-
target: z.string().min(1).describe("The address: email, phone number, or push token."),
|
|
363
|
-
reason: z
|
|
364
|
-
.enum(["unsubscribed", "complained", "bounced", "manual"])
|
|
365
|
-
.optional()
|
|
366
|
-
.describe("Why. Defaults to 'manual'."),
|
|
367
|
-
},
|
|
368
|
-
annotations: { title: "Suppress an address", readOnlyHint: false, idempotentHint: true },
|
|
369
|
-
}, handler(async (args) => api.post("/v1/suppressions", args)));
|
|
370
|
-
server.registerTool("unsuppress_address", {
|
|
371
|
-
title: "Remove a suppression",
|
|
372
|
-
description: "Re-enable sending to a previously suppressed destination. Only do this on an explicit request " +
|
|
373
|
-
"from the user — a suppression usually records that the person asked not to be contacted, and " +
|
|
374
|
-
"removing it to fix a low delivery count is how a sending domain gets blocked. Confirm before " +
|
|
375
|
-
"calling.",
|
|
376
|
-
inputSchema: {
|
|
377
|
-
channel: z.enum(CONTACT_CHANNELS).describe("Channel the suppression is on."),
|
|
378
|
-
target: z.string().min(1).describe("The suppressed address."),
|
|
379
|
-
},
|
|
380
|
-
annotations: {
|
|
381
|
-
title: "Remove a suppression",
|
|
382
|
-
readOnlyHint: false,
|
|
383
|
-
destructiveHint: true,
|
|
384
|
-
idempotentHint: true,
|
|
385
|
-
},
|
|
386
|
-
}, handler(async (args) => {
|
|
387
|
-
await api.request("DELETE", `/v1/suppressions/${encodeURIComponent(args.channel)}/${encodeURIComponent(args.target)}`);
|
|
388
|
-
return `Removed the suppression on ${args.target} for ${args.channel}.`;
|
|
389
|
-
}));
|
|
390
|
-
server.registerTool("list_segments", {
|
|
391
|
-
title: "List segments",
|
|
392
|
-
description: "List every segment tag currently in use across the project's users. Call this to discover the " +
|
|
393
|
-
"valid audiences for send_notification's `segment` argument before broadcasting.",
|
|
394
|
-
annotations: { title: "List segments", readOnlyHint: true },
|
|
395
|
-
}, handler(async () => api.get("/v1/segments")));
|
|
396
|
-
server.registerTool("list_scheduled", {
|
|
397
|
-
title: "List scheduled sends",
|
|
398
|
-
description: "List notifications queued for future delivery — those given a `sendAt`, plus any deferred by a " +
|
|
399
|
-
"recipient's quiet hours. Supports filtering by channel and pagination.",
|
|
400
|
-
inputSchema: {
|
|
401
|
-
limit: z
|
|
402
|
-
.number()
|
|
403
|
-
.int()
|
|
404
|
-
.min(1)
|
|
405
|
-
.max(100)
|
|
406
|
-
.optional()
|
|
407
|
-
.describe("How many rows to return. Defaults to 50."),
|
|
408
|
-
cursor: z
|
|
409
|
-
.string()
|
|
410
|
-
.optional()
|
|
411
|
-
.describe("Pagination cursor (taskId) from a previous call's `nextCursor`."),
|
|
412
|
-
channel: z
|
|
413
|
-
.enum(CHANNELS)
|
|
414
|
-
.optional()
|
|
415
|
-
.describe("Only list scheduled messages intended for this channel."),
|
|
416
|
-
},
|
|
417
|
-
annotations: { title: "List scheduled sends", readOnlyHint: true },
|
|
418
|
-
}, handler(async (args) => api.get("/v1/notifications/scheduled", args)));
|
|
419
|
-
server.registerTool("get_delivery_logs", {
|
|
420
|
-
title: "Get delivery logs",
|
|
421
|
-
description: "Query the durable delivery log: what was sent, on which channel, and whether it succeeded. Call " +
|
|
422
|
-
"this to answer 'did it go out?' after a send, or to investigate failures. Filter by template, " +
|
|
423
|
-
"channel, status, campaign, or task ID. Results are paginated — pass the returned `nextCursor` " +
|
|
424
|
-
"back as `cursor` for the next page.",
|
|
425
|
-
inputSchema: {
|
|
426
|
-
limit: z
|
|
427
|
-
.number()
|
|
428
|
-
.int()
|
|
429
|
-
.min(1)
|
|
430
|
-
.max(200)
|
|
431
|
-
.optional()
|
|
432
|
-
.describe("Rows per page. Defaults to the server's page size."),
|
|
433
|
-
cursor: z
|
|
434
|
-
.string()
|
|
435
|
-
.optional()
|
|
436
|
-
.describe("Pagination cursor from a previous call's `nextCursor`."),
|
|
437
|
-
templateId: z.string().optional().describe("Only log entries rendered from this template."),
|
|
438
|
-
workflowInstanceId: z
|
|
439
|
-
.string()
|
|
440
|
-
.optional()
|
|
441
|
-
.describe("Only entries emitted by this workflow instance."),
|
|
442
|
-
channel: z.enum(CHANNELS).optional().describe("Only entries delivered on this channel."),
|
|
443
|
-
status: z
|
|
444
|
-
.string()
|
|
445
|
-
.optional()
|
|
446
|
-
.describe("Delivery status to filter on, e.g. 'sent', 'delivered', 'failed', 'opened'."),
|
|
447
|
-
campaign: z
|
|
448
|
-
.string()
|
|
449
|
-
.optional()
|
|
450
|
-
.describe("Only log entries tagged with this campaign label."),
|
|
451
|
-
taskId: z
|
|
452
|
-
.string()
|
|
453
|
-
.optional()
|
|
454
|
-
.describe("Only log entries for this specific notification task ID."),
|
|
455
|
-
search: z
|
|
456
|
-
.string()
|
|
457
|
-
.optional()
|
|
458
|
-
.describe("Search keyword across task IDs, template IDs, provider message IDs, or campaign labels."),
|
|
459
|
-
},
|
|
460
|
-
annotations: { title: "Get delivery logs", readOnlyHint: true },
|
|
461
|
-
}, handler(async (args) => api.get("/v1/notifications/logs", args)));
|
|
462
|
-
server.registerTool("get_notification", {
|
|
463
|
-
title: "Get notification status",
|
|
464
|
-
description: "Fetch the delivery history and latest state of a specific notification by its task ID. " +
|
|
465
|
-
"Shows each attempt, provider status, timestamps, and error messages.",
|
|
466
|
-
inputSchema: {
|
|
467
|
-
taskId: z
|
|
468
|
-
.string()
|
|
469
|
-
.min(1)
|
|
470
|
-
.describe("Task ID returned from send_notification or send_campaign."),
|
|
471
|
-
},
|
|
472
|
-
annotations: { title: "Get notification status", readOnlyHint: true },
|
|
473
|
-
}, handler(async (args) => api.get(`/v1/notifications/${encodeURIComponent(args.taskId)}`)));
|
|
474
|
-
server.registerTool("cancel_notification", {
|
|
475
|
-
title: "Cancel a scheduled notification",
|
|
476
|
-
description: "Cancel a pending or quiet-hours deferred notification before it is dispatched to the provider. " +
|
|
477
|
-
"Takes the taskId from send_notification or list_scheduled.",
|
|
478
|
-
inputSchema: {
|
|
479
|
-
taskId: z.string().min(1).describe("Task ID of the scheduled notification to cancel."),
|
|
480
|
-
},
|
|
481
|
-
annotations: {
|
|
482
|
-
title: "Cancel a scheduled notification",
|
|
483
|
-
readOnlyHint: false,
|
|
484
|
-
destructiveHint: true,
|
|
485
|
-
idempotentHint: true,
|
|
486
|
-
},
|
|
487
|
-
}, handler(async (args) => {
|
|
488
|
-
await api.request("DELETE", `/v1/notifications/${encodeURIComponent(args.taskId)}`);
|
|
489
|
-
return `Cancelled scheduled notification ${args.taskId}.`;
|
|
490
|
-
}));
|
|
491
|
-
// ─── Templates ──────────────────────────────────────────────────────────────
|
|
492
|
-
server.registerTool("list_templates", {
|
|
493
|
-
title: "List templates",
|
|
494
|
-
description: "List registered templates with their channel and content. Supports filtering by channel, " +
|
|
495
|
-
"topic opt-out category, or limiting result count.",
|
|
496
|
-
inputSchema: {
|
|
497
|
-
limit: z
|
|
498
|
-
.number()
|
|
499
|
-
.int()
|
|
500
|
-
.min(1)
|
|
501
|
-
.max(100)
|
|
502
|
-
.optional()
|
|
503
|
-
.describe("Maximum number of templates to return."),
|
|
504
|
-
channel: z
|
|
505
|
-
.enum(CHANNELS)
|
|
506
|
-
.optional()
|
|
507
|
-
.describe("Only list templates that render for this channel."),
|
|
508
|
-
topic: z.string().optional().describe("Only list templates tagged with this topic."),
|
|
509
|
-
},
|
|
510
|
-
annotations: { title: "List templates", readOnlyHint: true },
|
|
511
|
-
}, handler(async (args) => api.get("/v1/templates", args)));
|
|
512
|
-
server.registerTool("get_template", {
|
|
513
|
-
title: "Get a template",
|
|
514
|
-
description: "Fetch one template by id, including its full per-channel content and any AI prompts.",
|
|
515
|
-
inputSchema: { id: z.string().min(1).describe("Template id.") },
|
|
516
|
-
annotations: { title: "Get a template", readOnlyHint: true },
|
|
517
|
-
}, handler(async (args) => api.get(`/v1/templates/${encodeURIComponent(args.id)}`)));
|
|
518
|
-
server.registerTool("upsert_template", {
|
|
519
|
-
title: "Create or update a template",
|
|
520
|
-
description: "Create a template, or overwrite an existing one with the same id. Content is a per-channel object " +
|
|
521
|
-
"whose values may contain {{variable}} placeholders filled by send_notification's `data`; escaping " +
|
|
522
|
-
"is decided by the destination field. Because this overwrites, call get_template first when " +
|
|
523
|
-
"editing one that already exists.",
|
|
524
|
-
inputSchema: {
|
|
525
|
-
id: z.string().min(1).describe("Template id, e.g. 'order-shipped'."),
|
|
526
|
-
channel: z.enum(CHANNELS).describe("Channel this template renders for."),
|
|
527
|
-
topic: z
|
|
528
|
-
.union([z.string().min(1), z.array(z.string().min(1))])
|
|
529
|
-
.optional()
|
|
530
|
-
.describe("Topic(s) this template belongs to, used for per-user topic opt-outs."),
|
|
531
|
-
content: z
|
|
532
|
-
.record(z.string(), z.unknown())
|
|
533
|
-
.describe("Channel-specific fields, e.g. { subject, body } for email."),
|
|
534
|
-
aiPrompts: z
|
|
535
|
-
.record(z.string(), z.string())
|
|
536
|
-
.optional()
|
|
537
|
-
.describe("Optional per-field LLM prompts applied before rendering."),
|
|
538
|
-
},
|
|
539
|
-
annotations: {
|
|
540
|
-
title: "Create or update a template",
|
|
541
|
-
readOnlyHint: false,
|
|
542
|
-
idempotentHint: true,
|
|
543
|
-
},
|
|
544
|
-
}, handler(async (args) => api.put("/v1/templates", { templates: [args] })));
|
|
545
|
-
server.registerTool("delete_template", {
|
|
546
|
-
title: "Delete a template",
|
|
547
|
-
description: "Permanently delete a registered template by its ID.",
|
|
548
|
-
inputSchema: {
|
|
549
|
-
id: z.string().min(1).describe("Template id to delete."),
|
|
550
|
-
},
|
|
551
|
-
annotations: {
|
|
552
|
-
title: "Delete a template",
|
|
553
|
-
readOnlyHint: false,
|
|
554
|
-
destructiveHint: true,
|
|
555
|
-
idempotentHint: true,
|
|
556
|
-
},
|
|
557
|
-
}, handler(async (args) => {
|
|
558
|
-
await api.delete(`/v1/templates/${encodeURIComponent(args.id)}`);
|
|
559
|
-
return `Deleted template ${args.id}.`;
|
|
560
|
-
}));
|
|
561
|
-
const previewTemplateHandler = async (args) => {
|
|
562
|
-
if (!args.id && !args.content) {
|
|
563
|
-
throw new Error("Provide either a template `id` or raw `content` to preview.");
|
|
564
|
-
}
|
|
565
|
-
let rawContent = args.content;
|
|
566
|
-
let templateChannel = args.channel;
|
|
567
|
-
if (args.id) {
|
|
568
|
-
const tmpl = await api.get(`/v1/templates/${encodeURIComponent(args.id)}`);
|
|
569
|
-
if (!rawContent) {
|
|
570
|
-
rawContent = tmpl.content;
|
|
571
|
-
}
|
|
572
|
-
if (!templateChannel && tmpl.channel) {
|
|
573
|
-
templateChannel = tmpl.channel;
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
const vars = args.data ?? {};
|
|
577
|
-
const rendered = renderContentNode(rawContent ?? {}, vars, "text");
|
|
578
|
-
const jsonStr = JSON.stringify(rawContent ?? {});
|
|
579
|
-
const placeholderMatches = Array.from(jsonStr.matchAll(/\{\{\{?(\w+)\}?\}\}/g)).map((m) => m[1]);
|
|
580
|
-
const placeholders = Array.from(new Set(placeholderMatches));
|
|
581
|
-
const resolvedVariables = placeholders.filter((p) => p in vars);
|
|
582
|
-
const unresolvedVariables = placeholders.filter((p) => !(p in vars));
|
|
583
|
-
return {
|
|
584
|
-
...(args.id ? { templateId: args.id } : {}),
|
|
585
|
-
channel: templateChannel ?? "email",
|
|
586
|
-
rendered,
|
|
587
|
-
resolvedVariables,
|
|
588
|
-
unresolvedVariables: unresolvedVariables.length > 0 ? unresolvedVariables : undefined,
|
|
589
|
-
};
|
|
590
|
-
};
|
|
591
|
-
server.registerTool("preview_template", {
|
|
592
|
-
title: "Preview a template",
|
|
593
|
-
description: "Dry-run render a template with sample variable data before sending. Pass an existing template " +
|
|
594
|
-
"`id` or supply raw `content` directly. Interpolates {{variable}} placeholders and returns the " +
|
|
595
|
-
"rendered output alongside resolved/unresolved variable names.",
|
|
596
|
-
inputSchema: {
|
|
597
|
-
id: z.string().optional().describe("Template id to fetch and preview."),
|
|
598
|
-
content: z
|
|
599
|
-
.record(z.string(), z.unknown())
|
|
600
|
-
.optional()
|
|
601
|
-
.describe("Raw template content object (e.g. { subject, body }) to render without saving."),
|
|
602
|
-
data: z
|
|
603
|
-
.record(z.string(), z.unknown())
|
|
604
|
-
.optional()
|
|
605
|
-
.describe("Sample variable data to interpolate into the template's placeholders."),
|
|
606
|
-
channel: z
|
|
607
|
-
.enum(CHANNELS)
|
|
608
|
-
.optional()
|
|
609
|
-
.describe("Target channel (e.g. 'email', 'sms', 'push'). Defaults to the template's channel."),
|
|
610
|
-
},
|
|
611
|
-
annotations: { title: "Preview a template", readOnlyHint: true },
|
|
612
|
-
}, handler(previewTemplateHandler));
|
|
613
|
-
server.registerTool("render_template", {
|
|
614
|
-
title: "Render template content",
|
|
615
|
-
description: "Render template content with variable data without dispatching any notifications. " +
|
|
616
|
-
"Accepts either an existing template `id` or raw `content` object.",
|
|
617
|
-
inputSchema: {
|
|
618
|
-
id: z.string().optional().describe("Template id to fetch and render."),
|
|
619
|
-
content: z
|
|
620
|
-
.record(z.string(), z.unknown())
|
|
621
|
-
.optional()
|
|
622
|
-
.describe("Raw template content object to render."),
|
|
623
|
-
data: z
|
|
624
|
-
.record(z.string(), z.unknown())
|
|
625
|
-
.optional()
|
|
626
|
-
.describe("Variables to interpolate into placeholders."),
|
|
627
|
-
channel: z
|
|
628
|
-
.enum(CHANNELS)
|
|
629
|
-
.optional()
|
|
630
|
-
.describe("Target channel. Defaults to template channel."),
|
|
631
|
-
},
|
|
632
|
-
annotations: { title: "Render template content", readOnlyHint: true },
|
|
633
|
-
}, handler(previewTemplateHandler));
|
|
634
|
-
// ─── Users ──────────────────────────────────────────────────────────────────
|
|
635
|
-
server.registerTool("list_users", {
|
|
636
|
-
title: "List users",
|
|
637
|
-
description: "Page through the project's users with comprehensive filtering. Supports filtering by search " +
|
|
638
|
-
"keyword (external ID or email), segment tag, language, timezone, or channel contact. " +
|
|
639
|
-
"Results are paginated — pass the returned `nextCursor` back as `cursor`. For one known user " +
|
|
640
|
-
"prefer get_user, which also returns contacts and preferences.",
|
|
641
|
-
inputSchema: {
|
|
642
|
-
limit: z.number().int().min(1).max(200).optional().describe("Users per page."),
|
|
643
|
-
cursor: z
|
|
644
|
-
.string()
|
|
645
|
-
.optional()
|
|
646
|
-
.describe("Pagination cursor from a previous call's `nextCursor`."),
|
|
647
|
-
search: z
|
|
648
|
-
.string()
|
|
649
|
-
.optional()
|
|
650
|
-
.describe("Filter users whose external ID or email contains this search keyword."),
|
|
651
|
-
segment: z.string().optional().describe("Only list users assigned to this segment tag."),
|
|
652
|
-
language: z
|
|
653
|
-
.string()
|
|
654
|
-
.optional()
|
|
655
|
-
.describe("Filter users by language tag, e.g. 'en', 'es', 'fr'."),
|
|
656
|
-
timezone: z
|
|
657
|
-
.string()
|
|
658
|
-
.optional()
|
|
659
|
-
.describe("Filter users by IANA timezone, e.g. 'Europe/London', 'America/New_York'."),
|
|
660
|
-
channel: z
|
|
661
|
-
.enum(CONTACT_CHANNELS)
|
|
662
|
-
.optional()
|
|
663
|
-
.describe("Only list users who have a registered contact for this channel " +
|
|
664
|
-
"(email, sms, push, webhook, telegram, discord, whatsapp, slack)."),
|
|
665
|
-
},
|
|
666
|
-
annotations: { title: "List users", readOnlyHint: true },
|
|
667
|
-
}, handler(async (args) => api.get("/v1/users", args)));
|
|
668
|
-
server.registerTool("get_user", {
|
|
669
|
-
title: "Get a user",
|
|
670
|
-
description: "Fetch one user with their contacts, segments, and notification preferences. Call this before " +
|
|
671
|
-
"sending to a single user when you need to know which channels they can actually be reached on.",
|
|
672
|
-
inputSchema: { id: z.string().min(1).describe("User id.") },
|
|
673
|
-
annotations: { title: "Get a user", readOnlyHint: true },
|
|
674
|
-
}, handler(async (args) => api.get(`/v1/users/${encodeURIComponent(args.id)}/details`)));
|
|
675
|
-
server.registerTool("upsert_user", {
|
|
676
|
-
title: "Create or update a user",
|
|
677
|
-
description: "Create a user profile, or update an existing one with the same id. Sets contact targets, segment " +
|
|
678
|
-
"tags, timezone, and preferences in one call. Segments assigned here are what send_notification's " +
|
|
679
|
-
"`segment` targeting matches on. Timezone drives quiet-hours maths, so set it when known.",
|
|
680
|
-
inputSchema: {
|
|
681
|
-
id: z.string().min(1).describe("Your own stable user id, e.g. 'usr_123'."),
|
|
682
|
-
contacts: z
|
|
683
|
-
.array(z.object({
|
|
684
|
-
channel: z.enum(CHANNELS).describe("Contact delivery channel."),
|
|
685
|
-
target: z.string().min(1).describe("Destination address, phone, token, or URL."),
|
|
686
|
-
label: z.string().optional().describe("Friendly label for this contact."),
|
|
687
|
-
isPrimary: z
|
|
688
|
-
.boolean()
|
|
689
|
-
.optional()
|
|
690
|
-
.describe("Whether this is the primary contact for this channel."),
|
|
691
|
-
}))
|
|
692
|
-
.optional()
|
|
693
|
-
.describe("Array of user contacts across any supported channels (preferred over legacy email/phone/pushToken)."),
|
|
694
|
-
email: z
|
|
695
|
-
.union([z.string().min(1), z.array(z.string().min(1))])
|
|
696
|
-
.optional()
|
|
697
|
-
.describe("One email address or several."),
|
|
698
|
-
phone: z
|
|
699
|
-
.union([z.string().min(1), z.array(z.string().min(1))])
|
|
700
|
-
.optional()
|
|
701
|
-
.describe("One phone number or several, in E.164 form."),
|
|
702
|
-
pushToken: z
|
|
703
|
-
.union([z.string().min(1), z.array(z.string().min(1))])
|
|
704
|
-
.optional()
|
|
705
|
-
.describe("One device push token or several."),
|
|
706
|
-
segments: z
|
|
707
|
-
.array(z.string().min(1))
|
|
708
|
-
.optional()
|
|
709
|
-
.describe("Segment tags to assign to this user."),
|
|
710
|
-
language: z
|
|
711
|
-
.string()
|
|
712
|
-
.optional()
|
|
713
|
-
.describe("BCP 47 language tag used to pick localised content."),
|
|
714
|
-
timezone: z
|
|
715
|
-
.string()
|
|
716
|
-
.optional()
|
|
717
|
-
.describe("IANA timezone, e.g. 'Europe/London'. Drives quiet hours."),
|
|
718
|
-
preferences: z
|
|
719
|
-
.object({
|
|
720
|
-
channels: z
|
|
721
|
-
.record(z.string(), z.boolean())
|
|
722
|
-
.optional()
|
|
723
|
-
.describe("Per-channel opt-in map, e.g. { email: true, sms: false }."),
|
|
724
|
-
topics: z.record(z.string(), z.boolean()).optional().describe("Per-topic opt-in map."),
|
|
725
|
-
quietHours: z
|
|
726
|
-
.array(z.object({
|
|
727
|
-
start: z.string().describe("HH:MM, 24h, UTC."),
|
|
728
|
-
end: z.string().describe("HH:MM, 24h, UTC."),
|
|
729
|
-
}))
|
|
730
|
-
.optional()
|
|
731
|
-
.describe("Windows during which non-critical sends are deferred."),
|
|
732
|
-
})
|
|
733
|
-
.optional()
|
|
734
|
-
.describe("Consent and quiet-hours settings."),
|
|
735
|
-
},
|
|
736
|
-
annotations: { title: "Create or update a user", readOnlyHint: false, idempotentHint: true },
|
|
737
|
-
}, handler(async (args) => api.post("/v1/users", args)));
|
|
738
|
-
server.registerTool("update_user", {
|
|
739
|
-
title: "Update a user",
|
|
740
|
-
description: "Partially update an existing user profile (e.g. language, timezone, segment tags, preferences, or append new contacts) without replacing unspecified fields.",
|
|
741
|
-
inputSchema: {
|
|
742
|
-
id: z.string().min(1).describe("User id."),
|
|
743
|
-
contacts: z
|
|
744
|
-
.array(z.object({
|
|
745
|
-
channel: z.enum(CHANNELS).describe("Contact delivery channel."),
|
|
746
|
-
target: z.string().min(1).describe("Destination address, phone, token, or URL."),
|
|
747
|
-
label: z.string().optional().describe("Friendly label for this contact."),
|
|
748
|
-
isPrimary: z
|
|
749
|
-
.boolean()
|
|
750
|
-
.optional()
|
|
751
|
-
.describe("Whether this is the primary contact for this channel."),
|
|
752
|
-
}))
|
|
753
|
-
.optional()
|
|
754
|
-
.describe("Array of user contacts across any supported channels to append or update."),
|
|
755
|
-
email: z
|
|
756
|
-
.union([z.string().min(1), z.array(z.string().min(1))])
|
|
757
|
-
.optional()
|
|
758
|
-
.describe("One email address or several."),
|
|
759
|
-
phone: z
|
|
760
|
-
.union([z.string().min(1), z.array(z.string().min(1))])
|
|
761
|
-
.optional()
|
|
762
|
-
.describe("One phone number or several, in E.164 form."),
|
|
763
|
-
pushToken: z
|
|
764
|
-
.union([z.string().min(1), z.array(z.string().min(1))])
|
|
765
|
-
.optional()
|
|
766
|
-
.describe("One device push token or several."),
|
|
767
|
-
segments: z
|
|
768
|
-
.array(z.string().min(1))
|
|
769
|
-
.optional()
|
|
770
|
-
.describe("Segment tags to assign to this user."),
|
|
771
|
-
language: z
|
|
772
|
-
.string()
|
|
773
|
-
.optional()
|
|
774
|
-
.describe("BCP 47 language tag used to pick localised content."),
|
|
775
|
-
timezone: z
|
|
776
|
-
.string()
|
|
777
|
-
.optional()
|
|
778
|
-
.describe("IANA timezone, e.g. 'Europe/London'. Drives quiet hours."),
|
|
779
|
-
preferences: z
|
|
780
|
-
.object({
|
|
781
|
-
channels: z
|
|
782
|
-
.record(z.string(), z.boolean())
|
|
783
|
-
.optional()
|
|
784
|
-
.describe("Per-channel opt-in map, e.g. { email: true, sms: false }."),
|
|
785
|
-
topics: z.record(z.string(), z.boolean()).optional().describe("Per-topic opt-in map."),
|
|
786
|
-
quietHours: z
|
|
787
|
-
.array(z.object({
|
|
788
|
-
start: z.string().describe("HH:MM, 24h, UTC."),
|
|
789
|
-
end: z.string().describe("HH:MM, 24h, UTC."),
|
|
790
|
-
}))
|
|
791
|
-
.optional()
|
|
792
|
-
.describe("Windows during which non-critical sends are deferred."),
|
|
793
|
-
})
|
|
794
|
-
.optional()
|
|
795
|
-
.describe("Consent and quiet-hours settings."),
|
|
796
|
-
},
|
|
797
|
-
annotations: { title: "Update a user", readOnlyHint: false, idempotentHint: true },
|
|
798
|
-
}, handler(async ({ id, ...body }) => api.patch(`/v1/users/${encodeURIComponent(id)}`, body)));
|
|
799
|
-
server.registerTool("delete_user", {
|
|
800
|
-
title: "Delete a user",
|
|
801
|
-
description: "Permanently delete a user profile and all associated contacts and preferences by user id.",
|
|
802
|
-
inputSchema: {
|
|
803
|
-
id: z.string().min(1).describe("User id to delete."),
|
|
804
|
-
},
|
|
805
|
-
annotations: {
|
|
806
|
-
title: "Delete a user",
|
|
807
|
-
readOnlyHint: false,
|
|
808
|
-
destructiveHint: true,
|
|
809
|
-
idempotentHint: true,
|
|
810
|
-
},
|
|
811
|
-
}, handler(async (args) => {
|
|
812
|
-
await api.delete(`/v1/users/${encodeURIComponent(args.id)}`);
|
|
813
|
-
return `Deleted user ${args.id}.`;
|
|
814
|
-
}));
|
|
815
|
-
server.registerTool("get_user_contacts", {
|
|
816
|
-
title: "Get user contacts",
|
|
817
|
-
description: "Fetch all registered contact addresses and tokens for a specific user.",
|
|
818
|
-
inputSchema: {
|
|
819
|
-
userId: z.string().min(1).describe("User id."),
|
|
820
|
-
},
|
|
821
|
-
annotations: { title: "Get user contacts", readOnlyHint: true },
|
|
822
|
-
}, handler(async (args) => api.get(`/v1/users/${encodeURIComponent(args.userId)}/contacts`)));
|
|
823
|
-
server.registerTool("add_user_contact", {
|
|
824
|
-
title: "Add a contact to a user",
|
|
825
|
-
description: "Add one addressable target (email address, phone number, push token, or webhook URL) to an " +
|
|
826
|
-
"existing user without replacing their other contacts. Prefer this over upsert_user when adding a " +
|
|
827
|
-
"second device or address to someone who already exists.",
|
|
828
|
-
inputSchema: {
|
|
829
|
-
userId: z.string().min(1).describe("Id of the user to add the contact to."),
|
|
830
|
-
channel: z.enum(CONTACT_CHANNELS).describe("Channel this target belongs to."),
|
|
831
|
-
target: z.string().min(1).describe("The address itself: email, phone, push token, or URL."),
|
|
832
|
-
},
|
|
833
|
-
annotations: { title: "Add a contact to a user", readOnlyHint: false },
|
|
834
|
-
}, handler(async ({ userId, ...body }) => api.post(`/v1/users/${encodeURIComponent(userId)}/contacts`, body)));
|
|
835
|
-
server.registerTool("delete_user_contact", {
|
|
836
|
-
title: "Delete a user contact",
|
|
837
|
-
description: "Remove one contact destination (email, phone, push token, or webhook URL) from a user profile.",
|
|
838
|
-
inputSchema: {
|
|
839
|
-
userId: z.string().min(1).describe("User id."),
|
|
840
|
-
channel: z.enum(CONTACT_CHANNELS).describe("Channel of the contact to delete."),
|
|
841
|
-
target: z.string().min(1).describe("The address/number/token/URL to remove."),
|
|
842
|
-
},
|
|
843
|
-
annotations: {
|
|
844
|
-
title: "Delete a user contact",
|
|
845
|
-
readOnlyHint: false,
|
|
846
|
-
destructiveHint: true,
|
|
847
|
-
idempotentHint: true,
|
|
848
|
-
},
|
|
849
|
-
}, handler(async (args) => {
|
|
850
|
-
await api.delete(`/v1/users/${encodeURIComponent(args.userId)}/contacts/${encodeURIComponent(args.channel)}/${encodeURIComponent(args.target)}`);
|
|
851
|
-
return `Deleted ${args.channel} contact '${args.target}' for user ${args.userId}.`;
|
|
852
|
-
}));
|
|
853
|
-
server.registerTool("get_user_preferences", {
|
|
854
|
-
title: "Get user preferences",
|
|
855
|
-
description: "Fetch notification channel/topic opt-in preferences and quiet hours for a user.",
|
|
856
|
-
inputSchema: {
|
|
857
|
-
userId: z.string().min(1).describe("User id."),
|
|
858
|
-
},
|
|
859
|
-
annotations: { title: "Get user preferences", readOnlyHint: true },
|
|
860
|
-
}, handler(async (args) => api.get(`/v1/users/${encodeURIComponent(args.userId)}/preferences`)));
|
|
861
|
-
server.registerTool("update_user_preferences", {
|
|
862
|
-
title: "Update user preferences",
|
|
863
|
-
description: "Update notification channel/topic opt-ins and quiet hours settings for a user.",
|
|
864
|
-
inputSchema: {
|
|
865
|
-
userId: z.string().min(1).describe("User id."),
|
|
866
|
-
channels: z
|
|
867
|
-
.record(z.string(), z.boolean())
|
|
868
|
-
.optional()
|
|
869
|
-
.describe("Per-channel opt-in map, e.g. { email: true, sms: false }."),
|
|
870
|
-
topics: z.record(z.string(), z.boolean()).optional().describe("Per-topic opt-in map."),
|
|
871
|
-
quietHours: z
|
|
872
|
-
.array(z.object({
|
|
873
|
-
start: z.string().describe("HH:MM, 24h, UTC."),
|
|
874
|
-
end: z.string().describe("HH:MM, 24h, UTC."),
|
|
875
|
-
}))
|
|
876
|
-
.optional()
|
|
877
|
-
.describe("Windows during which non-critical sends are deferred."),
|
|
878
|
-
},
|
|
879
|
-
annotations: { title: "Update user preferences", readOnlyHint: false, idempotentHint: true },
|
|
880
|
-
}, handler(async ({ userId, ...preferences }) => api.patch(`/v1/users/${encodeURIComponent(userId)}/preferences`, preferences)));
|
|
881
|
-
// ─── Workflows ──────────────────────────────────────────────────────────────
|
|
882
|
-
server.registerTool("create_workflow", {
|
|
883
|
-
title: "Create a workflow",
|
|
884
|
-
description: "Define a named multi-step sequence — the way to build a drip, an onboarding series, or a reminder " +
|
|
885
|
-
"chain rather than a single send. Steps run in order and are one of: `notify` (send, using the " +
|
|
886
|
-
"same fields as send_notification), `wait` (pause for a duration like '1h' or '3d'), or " +
|
|
887
|
-
"`waitForEvent` (block until ingest_event reports a named event, with an optional timeout). A " +
|
|
888
|
-
"notify step with no target inherits the user the instance was triggered for. Creating a workflow " +
|
|
889
|
-
"does not run it — call trigger_workflow per user.",
|
|
890
|
-
inputSchema: {
|
|
891
|
-
name: z.string().min(1).describe("Workflow name, used later by trigger_workflow."),
|
|
892
|
-
steps: z
|
|
893
|
-
.array(z.union([
|
|
894
|
-
z.object({
|
|
895
|
-
action: z.literal("notify"),
|
|
896
|
-
payload: z
|
|
897
|
-
.record(z.string(), z.unknown())
|
|
898
|
-
.describe("Same shape as send_notification's arguments. Omit the target to use the instance's own user."),
|
|
899
|
-
}),
|
|
900
|
-
z.object({
|
|
901
|
-
action: z.literal("wait"),
|
|
902
|
-
duration: z.string().describe("Duration string, e.g. '5m', '1h', '3d'."),
|
|
903
|
-
}),
|
|
904
|
-
z.object({
|
|
905
|
-
action: z.literal("waitForEvent"),
|
|
906
|
-
event: z.string().describe("Event name to wait for, as passed to ingest_event."),
|
|
907
|
-
options: z
|
|
908
|
-
.object({ timeout: z.string().optional().describe("e.g. '24h'.") })
|
|
909
|
-
.optional()
|
|
910
|
-
.describe("Give a timeout so the instance cannot wait forever."),
|
|
911
|
-
}),
|
|
912
|
-
]))
|
|
913
|
-
.min(1)
|
|
914
|
-
.describe("Ordered steps."),
|
|
915
|
-
},
|
|
916
|
-
annotations: { title: "Create a workflow", readOnlyHint: false, idempotentHint: true },
|
|
917
|
-
}, handler(async (args) => api.post("/v1/workflows", args)));
|
|
918
|
-
server.registerTool("list_workflows", {
|
|
919
|
-
title: "List workflows",
|
|
920
|
-
description: "List registered workflow definitions and their steps. Call this to find the name to pass to " +
|
|
921
|
-
"trigger_workflow, or to check a sequence before triggering it. Supports filtering by search keyword.",
|
|
922
|
-
inputSchema: {
|
|
923
|
-
limit: z
|
|
924
|
-
.number()
|
|
925
|
-
.int()
|
|
926
|
-
.min(1)
|
|
927
|
-
.max(100)
|
|
928
|
-
.optional()
|
|
929
|
-
.describe("Maximum number of workflow definitions to return."),
|
|
930
|
-
search: z
|
|
931
|
-
.string()
|
|
932
|
-
.optional()
|
|
933
|
-
.describe("Filter workflow definitions whose name contains this search keyword."),
|
|
934
|
-
},
|
|
935
|
-
annotations: { title: "List workflows", readOnlyHint: true },
|
|
936
|
-
}, handler(async (args) => api.get("/v1/workflows", args)));
|
|
937
|
-
server.registerTool("trigger_workflow", {
|
|
938
|
-
title: "Trigger a workflow",
|
|
939
|
-
description: "Start one run of a registered workflow, optionally for a specific user, and return the instance " +
|
|
940
|
-
"id. Each call starts an independent instance, so triggering the same workflow twice for one user " +
|
|
941
|
-
"enrols them twice. Track the returned instance with get_workflow_run.",
|
|
942
|
-
inputSchema: {
|
|
943
|
-
name: z.string().min(1).describe("Name of the workflow to run."),
|
|
944
|
-
user: z
|
|
945
|
-
.string()
|
|
946
|
-
.min(1)
|
|
947
|
-
.optional()
|
|
948
|
-
.describe("User id this run is for. Notify steps default to them."),
|
|
949
|
-
input: z
|
|
950
|
-
.record(z.string(), z.unknown())
|
|
951
|
-
.optional()
|
|
952
|
-
.describe("Data made available to the run's steps."),
|
|
953
|
-
},
|
|
954
|
-
annotations: { title: "Trigger a workflow", readOnlyHint: false, idempotentHint: false },
|
|
955
|
-
}, handler(async (args) => api.post("/v1/workflows/trigger", args)));
|
|
956
|
-
server.registerTool("get_workflow_run", {
|
|
957
|
-
title: "Get a workflow run",
|
|
958
|
-
description: "Fetch one workflow instance by id: which step it is on, its status, and what it is waiting for. " +
|
|
959
|
-
"Use this to check on a run started by trigger_workflow.",
|
|
960
|
-
inputSchema: { instanceId: z.string().min(1).describe("Workflow instance id.") },
|
|
961
|
-
annotations: { title: "Get a workflow run", readOnlyHint: true },
|
|
962
|
-
}, handler(async (args) => api.get(`/v1/workflows/instances/${encodeURIComponent(args.instanceId)}`)));
|
|
963
|
-
server.registerTool("cancel_workflow_run", {
|
|
964
|
-
title: "Cancel a workflow run",
|
|
965
|
-
description: "Stop a running or suspended workflow instance so its remaining steps never fire. This does not " +
|
|
966
|
-
"recall notifications already sent, and it cannot be undone — confirm with the user before " +
|
|
967
|
-
"cancelling a run you did not start in this session.",
|
|
968
|
-
inputSchema: { instanceId: z.string().min(1).describe("Workflow instance id to cancel.") },
|
|
969
|
-
annotations: {
|
|
970
|
-
title: "Cancel a workflow run",
|
|
971
|
-
readOnlyHint: false,
|
|
972
|
-
destructiveHint: true,
|
|
973
|
-
idempotentHint: true,
|
|
974
|
-
},
|
|
975
|
-
}, handler(async (args) => {
|
|
976
|
-
await api.request("DELETE", `/v1/workflows/instances/${encodeURIComponent(args.instanceId)}`);
|
|
977
|
-
return `Cancelled workflow instance ${args.instanceId}.`;
|
|
978
|
-
}));
|
|
979
|
-
server.registerTool("ingest_event", {
|
|
980
|
-
title: "Ingest an event",
|
|
981
|
-
description: "Report that something happened in your product. Workflow instances parked on a matching " +
|
|
982
|
-
"`waitForEvent` step resume. Call this to unblock a waiting sequence, e.g. emitting 'order.paid' " +
|
|
983
|
-
"so an abandoned-cart workflow stops before its reminder fires.",
|
|
984
|
-
inputSchema: {
|
|
985
|
-
name: z.string().min(1).describe("Event name, matching a workflow's waitForEvent step."),
|
|
986
|
-
properties: z
|
|
987
|
-
.record(z.string(), z.unknown())
|
|
988
|
-
.describe("Event payload. Include the user id the event is about."),
|
|
989
|
-
},
|
|
990
|
-
annotations: { title: "Ingest an event", readOnlyHint: false, idempotentHint: false },
|
|
991
|
-
}, handler(async (args) => api.post("/v1/events", args)));
|
|
992
|
-
// ─── Operations ─────────────────────────────────────────────────────────────
|
|
993
|
-
server.registerTool("get_system_health", {
|
|
994
|
-
title: "Get system health",
|
|
995
|
-
description: "Report the health of the notifkit deployment: queue depth, worker state, and dependency status. " +
|
|
996
|
-
"Call this first when sends appear queued but never delivered, to tell an outage apart from a " +
|
|
997
|
-
"preference or quiet-hours filter.",
|
|
998
|
-
annotations: { title: "Get system health", readOnlyHint: true },
|
|
999
|
-
}, handler(async () => api.get("/v1/system/health")));
|
|
1000
|
-
server.registerTool("get_dead_letters", {
|
|
1001
|
-
title: "Get dead-lettered messages",
|
|
1002
|
-
description: "List messages that exhausted their retries and landed in the dead-letter queue, with the error " +
|
|
1003
|
-
"that put them there. Use this to investigate deliveries that failed permanently; " +
|
|
1004
|
-
"replay_dead_letter puts one back on the queue.",
|
|
1005
|
-
annotations: { title: "Get dead-lettered messages", readOnlyHint: true },
|
|
1006
|
-
}, handler(async () => api.get("/v1/dlq")));
|
|
1007
|
-
server.registerTool("replay_dead_letter", {
|
|
1008
|
-
title: "Replay a dead-lettered message",
|
|
1009
|
-
description: "Re-queue one dead-lettered message for delivery. Only replay after the cause of the original " +
|
|
1010
|
-
"failure is fixed, or it will simply fail again — check get_dead_letters for the recorded error " +
|
|
1011
|
-
"first. Replaying sends a real notification to a real person.",
|
|
1012
|
-
inputSchema: {
|
|
1013
|
-
id: z.string().min(1).describe("Dead-letter entry id from get_dead_letters."),
|
|
1014
|
-
},
|
|
1015
|
-
annotations: {
|
|
1016
|
-
title: "Replay a dead-lettered message",
|
|
1017
|
-
readOnlyHint: false,
|
|
1018
|
-
idempotentHint: false,
|
|
1019
|
-
},
|
|
1020
|
-
}, handler(async (args) => api.post("/v1/dlq/replay", { id: args.id })));
|
|
1021
|
-
server.registerTool("delete_dead_letter", {
|
|
1022
|
-
title: "Delete a dead-lettered message",
|
|
1023
|
-
description: "Permanently delete/dismiss a dead-letter message from the DLQ by its entry ID.",
|
|
1024
|
-
inputSchema: {
|
|
1025
|
-
id: z.string().min(1).describe("Dead-letter entry id from get_dead_letters."),
|
|
1026
|
-
},
|
|
1027
|
-
annotations: {
|
|
1028
|
-
title: "Delete a dead-letter message",
|
|
1029
|
-
readOnlyHint: false,
|
|
1030
|
-
destructiveHint: true,
|
|
1031
|
-
idempotentHint: true,
|
|
1032
|
-
},
|
|
1033
|
-
}, handler(async (args) => {
|
|
1034
|
-
await api.delete(`/v1/dlq/${encodeURIComponent(args.id)}`);
|
|
1035
|
-
return `Deleted dead letter message ${args.id}.`;
|
|
1036
|
-
}));
|
|
1037
|
-
server.registerTool("get_system_metrics", {
|
|
1038
|
-
title: "Get system stream metrics",
|
|
1039
|
-
description: "Report queue depths across all Redis streams and delivery stats for the project.",
|
|
1040
|
-
annotations: { title: "Get system stream metrics", readOnlyHint: true },
|
|
1041
|
-
}, handler(async () => api.get("/v1/system/metrics")));
|
|
1042
|
-
// ─── Projects ───────────────────────────────────────────────────────────────
|
|
1043
|
-
server.registerTool("list_projects", {
|
|
1044
|
-
title: "List projects",
|
|
1045
|
-
description: "List all projects configured in this Notifkit deployment.",
|
|
1046
|
-
annotations: { title: "List projects", readOnlyHint: true },
|
|
1047
|
-
}, handler(async () => api.get("/v1/projects")));
|
|
1048
|
-
server.registerTool("create_project", {
|
|
1049
|
-
title: "Create a project",
|
|
1050
|
-
description: "Create a new tenant project with a name and generate its initial admin API key.",
|
|
1051
|
-
inputSchema: {
|
|
1052
|
-
name: z.string().min(1).describe("Project name."),
|
|
1053
|
-
},
|
|
1054
|
-
annotations: { title: "Create a project", readOnlyHint: false },
|
|
1055
|
-
}, handler(async (args) => api.post("/v1/projects", { name: args.name })));
|
|
1056
|
-
server.registerTool("update_project", {
|
|
1057
|
-
title: "Update a project",
|
|
1058
|
-
description: "Update project settings including rate limits and throttle limits.",
|
|
1059
|
-
inputSchema: {
|
|
1060
|
-
id: z.string().min(1).describe("Project id."),
|
|
1061
|
-
rateLimitRpm: z.number().nullable().optional().describe("Requests per minute limit."),
|
|
1062
|
-
throttleLimit: z
|
|
1063
|
-
.number()
|
|
1064
|
-
.nullable()
|
|
1065
|
-
.optional()
|
|
1066
|
-
.describe("Max notifications per throttle window."),
|
|
1067
|
-
throttleWindowHours: z.number().nullable().optional().describe("Throttle window in hours."),
|
|
1068
|
-
},
|
|
1069
|
-
annotations: { title: "Update a project", readOnlyHint: false, idempotentHint: true },
|
|
1070
|
-
}, handler(async ({ id, ...settings }) => api.patch(`/v1/projects/${encodeURIComponent(id)}`, settings)));
|
|
1071
|
-
server.registerTool("delete_project", {
|
|
1072
|
-
title: "Delete a project",
|
|
1073
|
-
description: "Permanently delete a project and its associated resources.",
|
|
1074
|
-
inputSchema: {
|
|
1075
|
-
id: z.string().min(1).describe("Project id to delete."),
|
|
1076
|
-
},
|
|
1077
|
-
annotations: {
|
|
1078
|
-
title: "Delete a project",
|
|
1079
|
-
readOnlyHint: false,
|
|
1080
|
-
destructiveHint: true,
|
|
1081
|
-
idempotentHint: true,
|
|
1082
|
-
},
|
|
1083
|
-
}, handler(async (args) => {
|
|
1084
|
-
await api.delete(`/v1/projects/${encodeURIComponent(args.id)}`);
|
|
1085
|
-
return `Deleted project ${args.id}.`;
|
|
1086
|
-
}));
|
|
1087
|
-
server.registerTool("list_project_keys", {
|
|
1088
|
-
title: "List project API keys",
|
|
1089
|
-
description: "List all API keys created for a specific project.",
|
|
1090
|
-
inputSchema: {
|
|
1091
|
-
projectId: z.string().min(1).describe("Project id."),
|
|
1092
|
-
},
|
|
1093
|
-
annotations: { title: "List project API keys", readOnlyHint: true },
|
|
1094
|
-
}, handler(async (args) => api.get(`/v1/projects/${encodeURIComponent(args.projectId)}/keys`)));
|
|
1095
|
-
server.registerTool("create_project_key", {
|
|
1096
|
-
title: "Create a project API key",
|
|
1097
|
-
description: "Generate a new API key with 'admin' or 'read_only' role for a project.",
|
|
1098
|
-
inputSchema: {
|
|
1099
|
-
projectId: z.string().min(1).describe("Project id."),
|
|
1100
|
-
role: z
|
|
1101
|
-
.enum(["admin", "read_only"])
|
|
1102
|
-
.optional()
|
|
1103
|
-
.describe("Role for this API key. Defaults to 'admin'."),
|
|
1104
|
-
},
|
|
1105
|
-
annotations: { title: "Create a project API key", readOnlyHint: false },
|
|
1106
|
-
}, handler(async (args) => api.post(`/v1/projects/${encodeURIComponent(args.projectId)}/keys`, {
|
|
1107
|
-
role: args.role ?? "admin",
|
|
1108
|
-
})));
|
|
1109
|
-
server.registerTool("delete_project_key", {
|
|
1110
|
-
title: "Delete a project API key",
|
|
1111
|
-
description: "Revoke and delete an API key for a project.",
|
|
1112
|
-
inputSchema: {
|
|
1113
|
-
projectId: z.string().min(1).describe("Project id."),
|
|
1114
|
-
keyId: z.string().min(1).describe("Key id to revoke."),
|
|
1115
|
-
},
|
|
1116
|
-
annotations: {
|
|
1117
|
-
title: "Delete a project API key",
|
|
1118
|
-
readOnlyHint: false,
|
|
1119
|
-
destructiveHint: true,
|
|
1120
|
-
idempotentHint: true,
|
|
1121
|
-
},
|
|
1122
|
-
}, handler(async (args) => {
|
|
1123
|
-
await api.delete(`/v1/projects/${encodeURIComponent(args.projectId)}/keys/${encodeURIComponent(args.keyId)}`);
|
|
1124
|
-
return `Deleted API key ${args.keyId} for project ${args.projectId}.`;
|
|
1125
|
-
}));
|
|
8
|
+
registerSendingTools(server, api);
|
|
9
|
+
registerTemplatesTools(server, api);
|
|
10
|
+
registerUsersTools(server, api);
|
|
11
|
+
registerWorkflowsTools(server, api);
|
|
12
|
+
registerOperationsTools(server, api);
|
|
13
|
+
registerProjectsTools(server, api);
|
|
1126
14
|
}
|
|
1127
15
|
//# sourceMappingURL=tools.js.map
|