@notifkit/mcp 0.1.0 → 0.1.2
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 +45 -30
- package/dist/client.d.ts +2 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +6 -0
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -6
- package/dist/index.js.map +1 -1
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +607 -35
- package/dist/tools.js.map +1 -1
- package/package.json +2 -1
- package/src/client.ts +109 -0
- package/src/index.ts +84 -0
- package/src/tools.ts +1481 -0
package/dist/tools.js
CHANGED
|
@@ -1,7 +1,26 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { NotifkitApiError } from "./client.js";
|
|
3
|
-
const CHANNELS = [
|
|
4
|
-
|
|
3
|
+
const CHANNELS = [
|
|
4
|
+
"email",
|
|
5
|
+
"sms",
|
|
6
|
+
"push",
|
|
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
|
+
];
|
|
5
24
|
const PRIORITIES = ["low", "normal", "high", "critical"];
|
|
6
25
|
/** Render any handler return value as the text payload MCP clients expect. */
|
|
7
26
|
function ok(value) {
|
|
@@ -31,6 +50,72 @@ function handler(fn) {
|
|
|
31
50
|
}
|
|
32
51
|
};
|
|
33
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
|
+
}
|
|
34
119
|
export function registerTools(server, api) {
|
|
35
120
|
// ─── Sending ────────────────────────────────────────────────────────────────
|
|
36
121
|
server.registerTool("send_notification", {
|
|
@@ -100,14 +185,15 @@ export function registerTools(server, api) {
|
|
|
100
185
|
}));
|
|
101
186
|
server.registerTool("send_campaign", {
|
|
102
187
|
title: "Send a campaign to a list of addresses",
|
|
103
|
-
description: "Send one template to a list of
|
|
104
|
-
"
|
|
105
|
-
"
|
|
106
|
-
"
|
|
107
|
-
"
|
|
108
|
-
"
|
|
109
|
-
"
|
|
110
|
-
"count is normally lower than
|
|
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.",
|
|
111
197
|
inputSchema: {
|
|
112
198
|
campaign: z
|
|
113
199
|
.string()
|
|
@@ -116,11 +202,23 @@ export function registerTools(server, api) {
|
|
|
116
202
|
.describe("Label for this send, e.g. 'spring-sale-2026-08-13'. Must be unique per send — reusing a " +
|
|
117
203
|
"label merges the two into one set of statistics."),
|
|
118
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."),
|
|
119
216
|
emails: z
|
|
120
217
|
.array(z.string().email())
|
|
121
218
|
.min(1)
|
|
122
219
|
.max(10000)
|
|
123
|
-
.
|
|
220
|
+
.optional()
|
|
221
|
+
.describe("Recipient email addresses (alias for recipients when sending on email channel)."),
|
|
124
222
|
data: z
|
|
125
223
|
.record(z.unknown())
|
|
126
224
|
.optional()
|
|
@@ -137,30 +235,58 @@ export function registerTools(server, api) {
|
|
|
137
235
|
},
|
|
138
236
|
annotations: { title: "Send a campaign", readOnlyHint: false, idempotentHint: false },
|
|
139
237
|
}, handler(async (args) => {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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
|
+
}
|
|
143
243
|
const seen = new Set();
|
|
144
244
|
const recipients = [];
|
|
145
|
-
for (const raw of
|
|
146
|
-
const
|
|
147
|
-
if (seen.has(
|
|
245
|
+
for (const raw of rawList) {
|
|
246
|
+
const target = channel === "email" ? raw.trim().toLowerCase() : raw.trim();
|
|
247
|
+
if (seen.has(target))
|
|
148
248
|
continue;
|
|
149
|
-
seen.add(
|
|
150
|
-
|
|
249
|
+
seen.add(target);
|
|
250
|
+
let userRecord;
|
|
251
|
+
if (channel === "email") {
|
|
252
|
+
userRecord = { id: `email:${target}`, email: target };
|
|
253
|
+
}
|
|
254
|
+
else if (channel === "sms") {
|
|
255
|
+
userRecord = { id: `phone:${target}`, phone: target };
|
|
256
|
+
}
|
|
257
|
+
else if (channel === "push") {
|
|
258
|
+
userRecord = { id: `push:${target}`, pushToken: target };
|
|
259
|
+
}
|
|
260
|
+
else if (channel === "telegram") {
|
|
261
|
+
userRecord = { id: `telegram:${target}` };
|
|
262
|
+
}
|
|
263
|
+
else if (channel === "discord") {
|
|
264
|
+
userRecord = { id: `discord:${target}` };
|
|
265
|
+
}
|
|
266
|
+
else if (channel === "whatsapp") {
|
|
267
|
+
userRecord = { id: `whatsapp:${target}`, phone: target };
|
|
268
|
+
}
|
|
269
|
+
else if (channel === "slack") {
|
|
270
|
+
userRecord = { id: `slack:${target}` };
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
userRecord = { id: `webhook:${target}` };
|
|
274
|
+
}
|
|
275
|
+
recipients.push(userRecord);
|
|
151
276
|
}
|
|
152
277
|
const result = await api.post("/v1/notify", {
|
|
153
278
|
user: recipients,
|
|
154
279
|
template: args.template,
|
|
155
280
|
campaign: args.campaign,
|
|
156
|
-
channels: [
|
|
281
|
+
channels: [channel],
|
|
157
282
|
...(args.data ? { data: args.data } : {}),
|
|
158
283
|
...(args.priority ? { priority: args.priority } : {}),
|
|
159
284
|
...(args.sendAt ? { sendAt: args.sendAt } : {}),
|
|
160
285
|
});
|
|
161
|
-
const duplicates =
|
|
286
|
+
const duplicates = rawList.length - recipients.length;
|
|
162
287
|
return {
|
|
163
288
|
campaign: args.campaign,
|
|
289
|
+
channel,
|
|
164
290
|
queued: recipients.length,
|
|
165
291
|
...(duplicates > 0 ? { duplicatesRemoved: duplicates } : {}),
|
|
166
292
|
note: "Queued, not yet delivered. Preferences, quiet hours, and suppressions are applied during " +
|
|
@@ -172,7 +298,8 @@ export function registerTools(server, api) {
|
|
|
172
298
|
title: "List campaigns",
|
|
173
299
|
description: "List recent campaign labels with their size and when they last saw activity, newest first. Call " +
|
|
174
300
|
"this when the user refers to a past send without naming its exact label ('the one I sent " +
|
|
175
|
-
"yesterday') to find the label to pass to get_campaign_stats."
|
|
301
|
+
"yesterday') to find the label to pass to get_campaign_stats. Supports filtering by search query, " +
|
|
302
|
+
"channel, date range, or minimum message count.",
|
|
176
303
|
inputSchema: {
|
|
177
304
|
limit: z
|
|
178
305
|
.number()
|
|
@@ -180,7 +307,31 @@ export function registerTools(server, api) {
|
|
|
180
307
|
.min(1)
|
|
181
308
|
.max(100)
|
|
182
309
|
.optional()
|
|
183
|
-
.describe("How many campaigns to return."),
|
|
310
|
+
.describe("How many campaigns to return. Defaults to 20."),
|
|
311
|
+
search: z
|
|
312
|
+
.string()
|
|
313
|
+
.optional()
|
|
314
|
+
.describe("Filter campaigns whose label contains this string (case-insensitive)."),
|
|
315
|
+
channel: z
|
|
316
|
+
.enum(CHANNELS)
|
|
317
|
+
.optional()
|
|
318
|
+
.describe("Only list campaigns that sent messages on this channel."),
|
|
319
|
+
since: z
|
|
320
|
+
.string()
|
|
321
|
+
.datetime()
|
|
322
|
+
.optional()
|
|
323
|
+
.describe("ISO 8601 timestamp; only return campaigns with activity on or after this date."),
|
|
324
|
+
until: z
|
|
325
|
+
.string()
|
|
326
|
+
.datetime()
|
|
327
|
+
.optional()
|
|
328
|
+
.describe("ISO 8601 timestamp; only return campaigns with activity on or before this date."),
|
|
329
|
+
minMessages: z
|
|
330
|
+
.number()
|
|
331
|
+
.int()
|
|
332
|
+
.min(1)
|
|
333
|
+
.optional()
|
|
334
|
+
.describe("Minimum number of distinct messages/recipients for a campaign."),
|
|
184
335
|
},
|
|
185
336
|
annotations: { title: "List campaigns", readOnlyHint: true },
|
|
186
337
|
}, handler(async (args) => api.get("/v1/campaigns", args)));
|
|
@@ -209,6 +360,10 @@ export function registerTools(server, api) {
|
|
|
209
360
|
.enum(["unsubscribed", "complained", "bounced", "manual"])
|
|
210
361
|
.optional()
|
|
211
362
|
.describe("Only suppressions with this reason."),
|
|
363
|
+
target: z
|
|
364
|
+
.string()
|
|
365
|
+
.optional()
|
|
366
|
+
.describe("Filter suppressions matching this email, phone, or push token."),
|
|
212
367
|
},
|
|
213
368
|
annotations: { title: "List suppressed addresses", readOnlyHint: true },
|
|
214
369
|
}, handler(async (args) => api.get("/v1/suppressions", args)));
|
|
@@ -256,15 +411,31 @@ export function registerTools(server, api) {
|
|
|
256
411
|
server.registerTool("list_scheduled", {
|
|
257
412
|
title: "List scheduled sends",
|
|
258
413
|
description: "List notifications queued for future delivery — those given a `sendAt`, plus any deferred by a " +
|
|
259
|
-
"recipient's quiet hours.
|
|
260
|
-
|
|
414
|
+
"recipient's quiet hours. Supports filtering by channel and pagination.",
|
|
415
|
+
inputSchema: {
|
|
416
|
+
limit: z
|
|
417
|
+
.number()
|
|
418
|
+
.int()
|
|
419
|
+
.min(1)
|
|
420
|
+
.max(100)
|
|
421
|
+
.optional()
|
|
422
|
+
.describe("How many rows to return. Defaults to 50."),
|
|
423
|
+
cursor: z
|
|
424
|
+
.string()
|
|
425
|
+
.optional()
|
|
426
|
+
.describe("Pagination cursor (taskId) from a previous call's `nextCursor`."),
|
|
427
|
+
channel: z
|
|
428
|
+
.enum(CHANNELS)
|
|
429
|
+
.optional()
|
|
430
|
+
.describe("Only list scheduled messages intended for this channel."),
|
|
431
|
+
},
|
|
261
432
|
annotations: { title: "List scheduled sends", readOnlyHint: true },
|
|
262
|
-
}, handler(async () => api.get("/v1/notifications/scheduled")));
|
|
433
|
+
}, handler(async (args) => api.get("/v1/notifications/scheduled", args)));
|
|
263
434
|
server.registerTool("get_delivery_logs", {
|
|
264
435
|
title: "Get delivery logs",
|
|
265
436
|
description: "Query the durable delivery log: what was sent, on which channel, and whether it succeeded. Call " +
|
|
266
437
|
"this to answer 'did it go out?' after a send, or to investigate failures. Filter by template, " +
|
|
267
|
-
"channel, status, or
|
|
438
|
+
"channel, status, campaign, or task ID. Results are paginated — pass the returned `nextCursor` " +
|
|
268
439
|
"back as `cursor` for the next page.",
|
|
269
440
|
inputSchema: {
|
|
270
441
|
limit: z
|
|
@@ -287,17 +458,72 @@ export function registerTools(server, api) {
|
|
|
287
458
|
status: z
|
|
288
459
|
.string()
|
|
289
460
|
.optional()
|
|
290
|
-
.describe("Delivery status to filter on, e.g. 'sent'
|
|
461
|
+
.describe("Delivery status to filter on, e.g. 'sent', 'delivered', 'failed', 'opened'."),
|
|
462
|
+
campaign: z
|
|
463
|
+
.string()
|
|
464
|
+
.optional()
|
|
465
|
+
.describe("Only log entries tagged with this campaign label."),
|
|
466
|
+
taskId: z
|
|
467
|
+
.string()
|
|
468
|
+
.optional()
|
|
469
|
+
.describe("Only log entries for this specific notification task ID."),
|
|
470
|
+
search: z
|
|
471
|
+
.string()
|
|
472
|
+
.optional()
|
|
473
|
+
.describe("Search keyword across task IDs, template IDs, provider message IDs, or campaign labels."),
|
|
291
474
|
},
|
|
292
475
|
annotations: { title: "Get delivery logs", readOnlyHint: true },
|
|
293
476
|
}, handler(async (args) => api.get("/v1/notifications/logs", args)));
|
|
477
|
+
server.registerTool("get_notification", {
|
|
478
|
+
title: "Get notification status",
|
|
479
|
+
description: "Fetch the delivery history and latest state of a specific notification by its task ID. " +
|
|
480
|
+
"Shows each attempt, provider status, timestamps, and error messages.",
|
|
481
|
+
inputSchema: {
|
|
482
|
+
taskId: z
|
|
483
|
+
.string()
|
|
484
|
+
.min(1)
|
|
485
|
+
.describe("Task ID returned from send_notification or send_campaign."),
|
|
486
|
+
},
|
|
487
|
+
annotations: { title: "Get notification status", readOnlyHint: true },
|
|
488
|
+
}, handler(async (args) => api.get(`/v1/notifications/${encodeURIComponent(args.taskId)}`)));
|
|
489
|
+
server.registerTool("cancel_notification", {
|
|
490
|
+
title: "Cancel a scheduled notification",
|
|
491
|
+
description: "Cancel a pending or quiet-hours deferred notification before it is dispatched to the provider. " +
|
|
492
|
+
"Takes the taskId from send_notification or list_scheduled.",
|
|
493
|
+
inputSchema: {
|
|
494
|
+
taskId: z.string().min(1).describe("Task ID of the scheduled notification to cancel."),
|
|
495
|
+
},
|
|
496
|
+
annotations: {
|
|
497
|
+
title: "Cancel a scheduled notification",
|
|
498
|
+
readOnlyHint: false,
|
|
499
|
+
destructiveHint: true,
|
|
500
|
+
idempotentHint: true,
|
|
501
|
+
},
|
|
502
|
+
}, handler(async (args) => {
|
|
503
|
+
await api.request("DELETE", `/v1/notifications/${encodeURIComponent(args.taskId)}`);
|
|
504
|
+
return `Cancelled scheduled notification ${args.taskId}.`;
|
|
505
|
+
}));
|
|
294
506
|
// ─── Templates ──────────────────────────────────────────────────────────────
|
|
295
507
|
server.registerTool("list_templates", {
|
|
296
508
|
title: "List templates",
|
|
297
|
-
description: "List
|
|
298
|
-
"
|
|
509
|
+
description: "List registered templates with their channel and content. Supports filtering by channel, " +
|
|
510
|
+
"topic opt-out category, or limiting result count.",
|
|
511
|
+
inputSchema: {
|
|
512
|
+
limit: z
|
|
513
|
+
.number()
|
|
514
|
+
.int()
|
|
515
|
+
.min(1)
|
|
516
|
+
.max(100)
|
|
517
|
+
.optional()
|
|
518
|
+
.describe("Maximum number of templates to return."),
|
|
519
|
+
channel: z
|
|
520
|
+
.enum(CHANNELS)
|
|
521
|
+
.optional()
|
|
522
|
+
.describe("Only list templates that render for this channel."),
|
|
523
|
+
topic: z.string().optional().describe("Only list templates tagged with this topic."),
|
|
524
|
+
},
|
|
299
525
|
annotations: { title: "List templates", readOnlyHint: true },
|
|
300
|
-
}, handler(async () => api.get("/v1/templates")));
|
|
526
|
+
}, handler(async (args) => api.get("/v1/templates", args)));
|
|
301
527
|
server.registerTool("get_template", {
|
|
302
528
|
title: "Get a template",
|
|
303
529
|
description: "Fetch one template by id, including its full per-channel content and any AI prompts.",
|
|
@@ -331,17 +557,126 @@ export function registerTools(server, api) {
|
|
|
331
557
|
idempotentHint: true,
|
|
332
558
|
},
|
|
333
559
|
}, handler(async (args) => api.put("/v1/templates", { templates: [args] })));
|
|
560
|
+
server.registerTool("delete_template", {
|
|
561
|
+
title: "Delete a template",
|
|
562
|
+
description: "Permanently delete a registered template by its ID.",
|
|
563
|
+
inputSchema: {
|
|
564
|
+
id: z.string().min(1).describe("Template id to delete."),
|
|
565
|
+
},
|
|
566
|
+
annotations: {
|
|
567
|
+
title: "Delete a template",
|
|
568
|
+
readOnlyHint: false,
|
|
569
|
+
destructiveHint: true,
|
|
570
|
+
idempotentHint: true,
|
|
571
|
+
},
|
|
572
|
+
}, handler(async (args) => {
|
|
573
|
+
await api.delete(`/v1/templates/${encodeURIComponent(args.id)}`);
|
|
574
|
+
return `Deleted template ${args.id}.`;
|
|
575
|
+
}));
|
|
576
|
+
const previewTemplateHandler = async (args) => {
|
|
577
|
+
if (!args.id && !args.content) {
|
|
578
|
+
throw new Error("Provide either a template `id` or raw `content` to preview.");
|
|
579
|
+
}
|
|
580
|
+
let rawContent = args.content;
|
|
581
|
+
let templateChannel = args.channel;
|
|
582
|
+
if (args.id) {
|
|
583
|
+
const tmpl = await api.get(`/v1/templates/${encodeURIComponent(args.id)}`);
|
|
584
|
+
if (!rawContent) {
|
|
585
|
+
rawContent = tmpl.content;
|
|
586
|
+
}
|
|
587
|
+
if (!templateChannel && tmpl.channel) {
|
|
588
|
+
templateChannel = tmpl.channel;
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
const vars = args.data ?? {};
|
|
592
|
+
const rendered = renderContentNode(rawContent ?? {}, vars, "text");
|
|
593
|
+
const jsonStr = JSON.stringify(rawContent ?? {});
|
|
594
|
+
const placeholderMatches = Array.from(jsonStr.matchAll(/\{\{\{?(\w+)\}?\}\}/g)).map((m) => m[1]);
|
|
595
|
+
const placeholders = Array.from(new Set(placeholderMatches));
|
|
596
|
+
const resolvedVariables = placeholders.filter((p) => p in vars);
|
|
597
|
+
const unresolvedVariables = placeholders.filter((p) => !(p in vars));
|
|
598
|
+
return {
|
|
599
|
+
...(args.id ? { templateId: args.id } : {}),
|
|
600
|
+
channel: templateChannel ?? "email",
|
|
601
|
+
rendered,
|
|
602
|
+
resolvedVariables,
|
|
603
|
+
unresolvedVariables: unresolvedVariables.length > 0 ? unresolvedVariables : undefined,
|
|
604
|
+
};
|
|
605
|
+
};
|
|
606
|
+
server.registerTool("preview_template", {
|
|
607
|
+
title: "Preview a template",
|
|
608
|
+
description: "Dry-run render a template with sample variable data before sending. Pass an existing template " +
|
|
609
|
+
"`id` or supply raw `content` directly. Interpolates {{variable}} placeholders and returns the " +
|
|
610
|
+
"rendered output alongside resolved/unresolved variable names.",
|
|
611
|
+
inputSchema: {
|
|
612
|
+
id: z.string().optional().describe("Template id to fetch and preview."),
|
|
613
|
+
content: z
|
|
614
|
+
.record(z.unknown())
|
|
615
|
+
.optional()
|
|
616
|
+
.describe("Raw template content object (e.g. { subject, body }) to render without saving."),
|
|
617
|
+
data: z
|
|
618
|
+
.record(z.unknown())
|
|
619
|
+
.optional()
|
|
620
|
+
.describe("Sample variable data to interpolate into the template's placeholders."),
|
|
621
|
+
channel: z
|
|
622
|
+
.enum(CHANNELS)
|
|
623
|
+
.optional()
|
|
624
|
+
.describe("Target channel (e.g. 'email', 'sms', 'push'). Defaults to the template's channel."),
|
|
625
|
+
},
|
|
626
|
+
annotations: { title: "Preview a template", readOnlyHint: true },
|
|
627
|
+
}, handler(previewTemplateHandler));
|
|
628
|
+
server.registerTool("render_template", {
|
|
629
|
+
title: "Render template content",
|
|
630
|
+
description: "Render template content with variable data without dispatching any notifications. " +
|
|
631
|
+
"Accepts either an existing template `id` or raw `content` object.",
|
|
632
|
+
inputSchema: {
|
|
633
|
+
id: z.string().optional().describe("Template id to fetch and render."),
|
|
634
|
+
content: z
|
|
635
|
+
.record(z.unknown())
|
|
636
|
+
.optional()
|
|
637
|
+
.describe("Raw template content object to render."),
|
|
638
|
+
data: z
|
|
639
|
+
.record(z.unknown())
|
|
640
|
+
.optional()
|
|
641
|
+
.describe("Variables to interpolate into placeholders."),
|
|
642
|
+
channel: z
|
|
643
|
+
.enum(CHANNELS)
|
|
644
|
+
.optional()
|
|
645
|
+
.describe("Target channel. Defaults to template channel."),
|
|
646
|
+
},
|
|
647
|
+
annotations: { title: "Render template content", readOnlyHint: true },
|
|
648
|
+
}, handler(previewTemplateHandler));
|
|
334
649
|
// ─── Users ──────────────────────────────────────────────────────────────────
|
|
335
650
|
server.registerTool("list_users", {
|
|
336
651
|
title: "List users",
|
|
337
|
-
description: "Page through the project's users
|
|
338
|
-
"
|
|
652
|
+
description: "Page through the project's users with comprehensive filtering. Supports filtering by search " +
|
|
653
|
+
"keyword (external ID or email), segment tag, language, timezone, or channel contact. " +
|
|
654
|
+
"Results are paginated — pass the returned `nextCursor` back as `cursor`. For one known user " +
|
|
655
|
+
"prefer get_user, which also returns contacts and preferences.",
|
|
339
656
|
inputSchema: {
|
|
340
657
|
limit: z.number().int().min(1).max(200).optional().describe("Users per page."),
|
|
341
658
|
cursor: z
|
|
342
659
|
.string()
|
|
343
660
|
.optional()
|
|
344
661
|
.describe("Pagination cursor from a previous call's `nextCursor`."),
|
|
662
|
+
search: z
|
|
663
|
+
.string()
|
|
664
|
+
.optional()
|
|
665
|
+
.describe("Filter users whose external ID or email contains this search keyword."),
|
|
666
|
+
segment: z.string().optional().describe("Only list users assigned to this segment tag."),
|
|
667
|
+
language: z
|
|
668
|
+
.string()
|
|
669
|
+
.optional()
|
|
670
|
+
.describe("Filter users by language tag, e.g. 'en', 'es', 'fr'."),
|
|
671
|
+
timezone: z
|
|
672
|
+
.string()
|
|
673
|
+
.optional()
|
|
674
|
+
.describe("Filter users by IANA timezone, e.g. 'Europe/London', 'America/New_York'."),
|
|
675
|
+
channel: z
|
|
676
|
+
.enum(CONTACT_CHANNELS)
|
|
677
|
+
.optional()
|
|
678
|
+
.describe("Only list users who have a registered contact for this channel " +
|
|
679
|
+
"(email, sms, push, webhook, telegram, discord, whatsapp, slack)."),
|
|
345
680
|
},
|
|
346
681
|
annotations: { title: "List users", readOnlyHint: true },
|
|
347
682
|
}, handler(async (args) => api.get("/v1/users", args)));
|
|
@@ -403,6 +738,79 @@ export function registerTools(server, api) {
|
|
|
403
738
|
},
|
|
404
739
|
annotations: { title: "Create or update a user", readOnlyHint: false, idempotentHint: true },
|
|
405
740
|
}, handler(async (args) => api.post("/v1/users", args)));
|
|
741
|
+
server.registerTool("update_user", {
|
|
742
|
+
title: "Update a user",
|
|
743
|
+
description: "Partially update an existing user profile (e.g. language, timezone, segment tags, preferences, or append new contacts) without replacing unspecified fields.",
|
|
744
|
+
inputSchema: {
|
|
745
|
+
id: z.string().min(1).describe("User id."),
|
|
746
|
+
email: z
|
|
747
|
+
.union([z.string().min(1), z.array(z.string().min(1))])
|
|
748
|
+
.optional()
|
|
749
|
+
.describe("One email address or several."),
|
|
750
|
+
phone: z
|
|
751
|
+
.union([z.string().min(1), z.array(z.string().min(1))])
|
|
752
|
+
.optional()
|
|
753
|
+
.describe("One phone number or several, in E.164 form."),
|
|
754
|
+
pushToken: z
|
|
755
|
+
.union([z.string().min(1), z.array(z.string().min(1))])
|
|
756
|
+
.optional()
|
|
757
|
+
.describe("One device push token or several."),
|
|
758
|
+
segments: z
|
|
759
|
+
.array(z.string().min(1))
|
|
760
|
+
.optional()
|
|
761
|
+
.describe("Segment tags to assign to this user."),
|
|
762
|
+
language: z
|
|
763
|
+
.string()
|
|
764
|
+
.optional()
|
|
765
|
+
.describe("BCP 47 language tag used to pick localised content."),
|
|
766
|
+
timezone: z
|
|
767
|
+
.string()
|
|
768
|
+
.optional()
|
|
769
|
+
.describe("IANA timezone, e.g. 'Europe/London'. Drives quiet hours."),
|
|
770
|
+
preferences: z
|
|
771
|
+
.object({
|
|
772
|
+
channels: z
|
|
773
|
+
.record(z.boolean())
|
|
774
|
+
.optional()
|
|
775
|
+
.describe("Per-channel opt-in map, e.g. { email: true, sms: false }."),
|
|
776
|
+
topics: z.record(z.boolean()).optional().describe("Per-topic opt-in map."),
|
|
777
|
+
quietHours: z
|
|
778
|
+
.array(z.object({
|
|
779
|
+
start: z.string().describe("HH:MM, 24h, UTC."),
|
|
780
|
+
end: z.string().describe("HH:MM, 24h, UTC."),
|
|
781
|
+
}))
|
|
782
|
+
.optional()
|
|
783
|
+
.describe("Windows during which non-critical sends are deferred."),
|
|
784
|
+
})
|
|
785
|
+
.optional()
|
|
786
|
+
.describe("Consent and quiet-hours settings."),
|
|
787
|
+
},
|
|
788
|
+
annotations: { title: "Update a user", readOnlyHint: false, idempotentHint: true },
|
|
789
|
+
}, handler(async ({ id, ...body }) => api.patch(`/v1/users/${encodeURIComponent(id)}`, body)));
|
|
790
|
+
server.registerTool("delete_user", {
|
|
791
|
+
title: "Delete a user",
|
|
792
|
+
description: "Permanently delete a user profile and all associated contacts and preferences by user id.",
|
|
793
|
+
inputSchema: {
|
|
794
|
+
id: z.string().min(1).describe("User id to delete."),
|
|
795
|
+
},
|
|
796
|
+
annotations: {
|
|
797
|
+
title: "Delete a user",
|
|
798
|
+
readOnlyHint: false,
|
|
799
|
+
destructiveHint: true,
|
|
800
|
+
idempotentHint: true,
|
|
801
|
+
},
|
|
802
|
+
}, handler(async (args) => {
|
|
803
|
+
await api.delete(`/v1/users/${encodeURIComponent(args.id)}`);
|
|
804
|
+
return `Deleted user ${args.id}.`;
|
|
805
|
+
}));
|
|
806
|
+
server.registerTool("get_user_contacts", {
|
|
807
|
+
title: "Get user contacts",
|
|
808
|
+
description: "Fetch all registered contact addresses and tokens for a specific user.",
|
|
809
|
+
inputSchema: {
|
|
810
|
+
userId: z.string().min(1).describe("User id."),
|
|
811
|
+
},
|
|
812
|
+
annotations: { title: "Get user contacts", readOnlyHint: true },
|
|
813
|
+
}, handler(async (args) => api.get(`/v1/users/${encodeURIComponent(args.userId)}/contacts`)));
|
|
406
814
|
server.registerTool("add_user_contact", {
|
|
407
815
|
title: "Add a contact to a user",
|
|
408
816
|
description: "Add one addressable target (email address, phone number, push token, or webhook URL) to an " +
|
|
@@ -415,6 +823,52 @@ export function registerTools(server, api) {
|
|
|
415
823
|
},
|
|
416
824
|
annotations: { title: "Add a contact to a user", readOnlyHint: false },
|
|
417
825
|
}, handler(async ({ userId, ...body }) => api.post(`/v1/users/${encodeURIComponent(userId)}/contacts`, body)));
|
|
826
|
+
server.registerTool("delete_user_contact", {
|
|
827
|
+
title: "Delete a user contact",
|
|
828
|
+
description: "Remove one contact destination (email, phone, push token, or webhook URL) from a user profile.",
|
|
829
|
+
inputSchema: {
|
|
830
|
+
userId: z.string().min(1).describe("User id."),
|
|
831
|
+
channel: z.enum(CONTACT_CHANNELS).describe("Channel of the contact to delete."),
|
|
832
|
+
target: z.string().min(1).describe("The address/number/token/URL to remove."),
|
|
833
|
+
},
|
|
834
|
+
annotations: {
|
|
835
|
+
title: "Delete a user contact",
|
|
836
|
+
readOnlyHint: false,
|
|
837
|
+
destructiveHint: true,
|
|
838
|
+
idempotentHint: true,
|
|
839
|
+
},
|
|
840
|
+
}, handler(async (args) => {
|
|
841
|
+
await api.delete(`/v1/users/${encodeURIComponent(args.userId)}/contacts/${encodeURIComponent(args.channel)}/${encodeURIComponent(args.target)}`);
|
|
842
|
+
return `Deleted ${args.channel} contact '${args.target}' for user ${args.userId}.`;
|
|
843
|
+
}));
|
|
844
|
+
server.registerTool("get_user_preferences", {
|
|
845
|
+
title: "Get user preferences",
|
|
846
|
+
description: "Fetch notification channel/topic opt-in preferences and quiet hours for a user.",
|
|
847
|
+
inputSchema: {
|
|
848
|
+
userId: z.string().min(1).describe("User id."),
|
|
849
|
+
},
|
|
850
|
+
annotations: { title: "Get user preferences", readOnlyHint: true },
|
|
851
|
+
}, handler(async (args) => api.get(`/v1/users/${encodeURIComponent(args.userId)}/preferences`)));
|
|
852
|
+
server.registerTool("update_user_preferences", {
|
|
853
|
+
title: "Update user preferences",
|
|
854
|
+
description: "Update notification channel/topic opt-ins and quiet hours settings for a user.",
|
|
855
|
+
inputSchema: {
|
|
856
|
+
userId: z.string().min(1).describe("User id."),
|
|
857
|
+
channels: z
|
|
858
|
+
.record(z.boolean())
|
|
859
|
+
.optional()
|
|
860
|
+
.describe("Per-channel opt-in map, e.g. { email: true, sms: false }."),
|
|
861
|
+
topics: z.record(z.boolean()).optional().describe("Per-topic opt-in map."),
|
|
862
|
+
quietHours: z
|
|
863
|
+
.array(z.object({
|
|
864
|
+
start: z.string().describe("HH:MM, 24h, UTC."),
|
|
865
|
+
end: z.string().describe("HH:MM, 24h, UTC."),
|
|
866
|
+
}))
|
|
867
|
+
.optional()
|
|
868
|
+
.describe("Windows during which non-critical sends are deferred."),
|
|
869
|
+
},
|
|
870
|
+
annotations: { title: "Update user preferences", readOnlyHint: false, idempotentHint: true },
|
|
871
|
+
}, handler(async ({ userId, ...preferences }) => api.patch(`/v1/users/${encodeURIComponent(userId)}/preferences`, preferences)));
|
|
418
872
|
// ─── Workflows ──────────────────────────────────────────────────────────────
|
|
419
873
|
server.registerTool("create_workflow", {
|
|
420
874
|
title: "Create a workflow",
|
|
@@ -455,9 +909,22 @@ export function registerTools(server, api) {
|
|
|
455
909
|
server.registerTool("list_workflows", {
|
|
456
910
|
title: "List workflows",
|
|
457
911
|
description: "List registered workflow definitions and their steps. Call this to find the name to pass to " +
|
|
458
|
-
"trigger_workflow, or to check a sequence before triggering it.",
|
|
912
|
+
"trigger_workflow, or to check a sequence before triggering it. Supports filtering by search keyword.",
|
|
913
|
+
inputSchema: {
|
|
914
|
+
limit: z
|
|
915
|
+
.number()
|
|
916
|
+
.int()
|
|
917
|
+
.min(1)
|
|
918
|
+
.max(100)
|
|
919
|
+
.optional()
|
|
920
|
+
.describe("Maximum number of workflow definitions to return."),
|
|
921
|
+
search: z
|
|
922
|
+
.string()
|
|
923
|
+
.optional()
|
|
924
|
+
.describe("Filter workflow definitions whose name contains this search keyword."),
|
|
925
|
+
},
|
|
459
926
|
annotations: { title: "List workflows", readOnlyHint: true },
|
|
460
|
-
}, handler(async () => api.get("/v1/workflows")));
|
|
927
|
+
}, handler(async (args) => api.get("/v1/workflows", args)));
|
|
461
928
|
server.registerTool("trigger_workflow", {
|
|
462
929
|
title: "Trigger a workflow",
|
|
463
930
|
description: "Start one run of a registered workflow, optionally for a specific user, and return the instance " +
|
|
@@ -539,5 +1006,110 @@ export function registerTools(server, api) {
|
|
|
539
1006
|
idempotentHint: false,
|
|
540
1007
|
},
|
|
541
1008
|
}, handler(async (args) => api.post("/v1/dlq/replay", { id: args.id })));
|
|
1009
|
+
server.registerTool("delete_dead_letter", {
|
|
1010
|
+
title: "Delete a dead-lettered message",
|
|
1011
|
+
description: "Permanently delete/dismiss a dead-letter message from the DLQ by its entry ID.",
|
|
1012
|
+
inputSchema: {
|
|
1013
|
+
id: z.string().min(1).describe("Dead-letter entry id from get_dead_letters."),
|
|
1014
|
+
},
|
|
1015
|
+
annotations: {
|
|
1016
|
+
title: "Delete a dead-letter message",
|
|
1017
|
+
readOnlyHint: false,
|
|
1018
|
+
destructiveHint: true,
|
|
1019
|
+
idempotentHint: true,
|
|
1020
|
+
},
|
|
1021
|
+
}, handler(async (args) => {
|
|
1022
|
+
await api.delete(`/v1/dlq/${encodeURIComponent(args.id)}`);
|
|
1023
|
+
return `Deleted dead letter message ${args.id}.`;
|
|
1024
|
+
}));
|
|
1025
|
+
server.registerTool("get_system_metrics", {
|
|
1026
|
+
title: "Get system stream metrics",
|
|
1027
|
+
description: "Report queue depths across all Redis streams and delivery stats for the project.",
|
|
1028
|
+
annotations: { title: "Get system stream metrics", readOnlyHint: true },
|
|
1029
|
+
}, handler(async () => api.get("/v1/system/metrics")));
|
|
1030
|
+
// ─── Projects ───────────────────────────────────────────────────────────────
|
|
1031
|
+
server.registerTool("list_projects", {
|
|
1032
|
+
title: "List projects",
|
|
1033
|
+
description: "List all projects configured in this Notifkit deployment.",
|
|
1034
|
+
annotations: { title: "List projects", readOnlyHint: true },
|
|
1035
|
+
}, handler(async () => api.get("/v1/projects")));
|
|
1036
|
+
server.registerTool("create_project", {
|
|
1037
|
+
title: "Create a project",
|
|
1038
|
+
description: "Create a new tenant project with a name and generate its initial admin API key.",
|
|
1039
|
+
inputSchema: {
|
|
1040
|
+
name: z.string().min(1).describe("Project name."),
|
|
1041
|
+
},
|
|
1042
|
+
annotations: { title: "Create a project", readOnlyHint: false },
|
|
1043
|
+
}, handler(async (args) => api.post("/v1/projects", { name: args.name })));
|
|
1044
|
+
server.registerTool("update_project", {
|
|
1045
|
+
title: "Update a project",
|
|
1046
|
+
description: "Update project settings including rate limits and throttle limits.",
|
|
1047
|
+
inputSchema: {
|
|
1048
|
+
id: z.string().min(1).describe("Project id."),
|
|
1049
|
+
rateLimitRpm: z.number().nullable().optional().describe("Requests per minute limit."),
|
|
1050
|
+
throttleLimit: z
|
|
1051
|
+
.number()
|
|
1052
|
+
.nullable()
|
|
1053
|
+
.optional()
|
|
1054
|
+
.describe("Max notifications per throttle window."),
|
|
1055
|
+
throttleWindowHours: z.number().nullable().optional().describe("Throttle window in hours."),
|
|
1056
|
+
},
|
|
1057
|
+
annotations: { title: "Update a project", readOnlyHint: false, idempotentHint: true },
|
|
1058
|
+
}, handler(async ({ id, ...settings }) => api.patch(`/v1/projects/${encodeURIComponent(id)}`, settings)));
|
|
1059
|
+
server.registerTool("delete_project", {
|
|
1060
|
+
title: "Delete a project",
|
|
1061
|
+
description: "Permanently delete a project and its associated resources.",
|
|
1062
|
+
inputSchema: {
|
|
1063
|
+
id: z.string().min(1).describe("Project id to delete."),
|
|
1064
|
+
},
|
|
1065
|
+
annotations: {
|
|
1066
|
+
title: "Delete a project",
|
|
1067
|
+
readOnlyHint: false,
|
|
1068
|
+
destructiveHint: true,
|
|
1069
|
+
idempotentHint: true,
|
|
1070
|
+
},
|
|
1071
|
+
}, handler(async (args) => {
|
|
1072
|
+
await api.delete(`/v1/projects/${encodeURIComponent(args.id)}`);
|
|
1073
|
+
return `Deleted project ${args.id}.`;
|
|
1074
|
+
}));
|
|
1075
|
+
server.registerTool("list_project_keys", {
|
|
1076
|
+
title: "List project API keys",
|
|
1077
|
+
description: "List all API keys created for a specific project.",
|
|
1078
|
+
inputSchema: {
|
|
1079
|
+
projectId: z.string().min(1).describe("Project id."),
|
|
1080
|
+
},
|
|
1081
|
+
annotations: { title: "List project API keys", readOnlyHint: true },
|
|
1082
|
+
}, handler(async (args) => api.get(`/v1/projects/${encodeURIComponent(args.projectId)}/keys`)));
|
|
1083
|
+
server.registerTool("create_project_key", {
|
|
1084
|
+
title: "Create a project API key",
|
|
1085
|
+
description: "Generate a new API key with 'admin' or 'read_only' role for a project.",
|
|
1086
|
+
inputSchema: {
|
|
1087
|
+
projectId: z.string().min(1).describe("Project id."),
|
|
1088
|
+
role: z
|
|
1089
|
+
.enum(["admin", "read_only"])
|
|
1090
|
+
.optional()
|
|
1091
|
+
.describe("Role for this API key. Defaults to 'admin'."),
|
|
1092
|
+
},
|
|
1093
|
+
annotations: { title: "Create a project API key", readOnlyHint: false },
|
|
1094
|
+
}, handler(async (args) => api.post(`/v1/projects/${encodeURIComponent(args.projectId)}/keys`, {
|
|
1095
|
+
role: args.role ?? "admin",
|
|
1096
|
+
})));
|
|
1097
|
+
server.registerTool("delete_project_key", {
|
|
1098
|
+
title: "Delete a project API key",
|
|
1099
|
+
description: "Revoke and delete an API key for a project.",
|
|
1100
|
+
inputSchema: {
|
|
1101
|
+
projectId: z.string().min(1).describe("Project id."),
|
|
1102
|
+
keyId: z.string().min(1).describe("Key id to revoke."),
|
|
1103
|
+
},
|
|
1104
|
+
annotations: {
|
|
1105
|
+
title: "Delete a project API key",
|
|
1106
|
+
readOnlyHint: false,
|
|
1107
|
+
destructiveHint: true,
|
|
1108
|
+
idempotentHint: true,
|
|
1109
|
+
},
|
|
1110
|
+
}, handler(async (args) => {
|
|
1111
|
+
await api.delete(`/v1/projects/${encodeURIComponent(args.projectId)}/keys/${encodeURIComponent(args.keyId)}`);
|
|
1112
|
+
return `Deleted API key ${args.keyId} for project ${args.projectId}.`;
|
|
1113
|
+
}));
|
|
542
1114
|
}
|
|
543
1115
|
//# sourceMappingURL=tools.js.map
|