@notifkit/mcp 0.1.8 → 0.1.9
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 +11 -11
- package/dist/tools/sending.js +4 -4
- package/dist/tools/sending.js.map +1 -1
- package/dist/tools/shared.d.ts +2 -2
- package/dist/tools/shared.d.ts.map +1 -1
- package/dist/tools/shared.js +1 -0
- package/dist/tools/shared.js.map +1 -1
- package/dist/tools/users.js +1 -1
- package/dist/tools/users.js.map +1 -1
- package/package.json +1 -1
- package/src/tools/sending.ts +4 -4
- package/src/tools/shared.ts +1 -0
- package/src/tools/users.ts +1 -1
package/README.md
CHANGED
|
@@ -90,17 +90,17 @@ Because triple braces `{{{body}}}` preserve unescaped HTML, your agent in Claude
|
|
|
90
90
|
|
|
91
91
|
**Campaigns & Sending**
|
|
92
92
|
|
|
93
|
-
| Tool | What it does
|
|
94
|
-
| --------------------- |
|
|
95
|
-
| `send_campaign` | Send a template to a list of recipients across `email`, `sms`, `push`, `webhook`, `telegram`, `discord`, `whatsapp`, or `
|
|
96
|
-
| `send_notification` | Send to existing users, a segment, or a topic with `sendAt` scheduling and priority lanes
|
|
97
|
-
| `list_campaigns` | Recent campaign labels with size and last activity (supports `search`, `channel`, date range)
|
|
98
|
-
| `get_campaign_stats` | Sent, delivered, failed, opened, clicked, bounced, complained, unsubscribed, with rates
|
|
99
|
-
| `list_segments` | Every segment tag in use — the valid audiences to broadcast to
|
|
100
|
-
| `list_scheduled` | Sends queued for the future, including quiet-hours deferrals
|
|
101
|
-
| `get_delivery_logs` | Per-message detail with filters for template, channel, status, campaign, or user search
|
|
102
|
-
| `get_notification` | Status and delivery attempts for a specific task
|
|
103
|
-
| `cancel_notification` | Cancel a pending scheduled or quiet-hours deferred notification
|
|
93
|
+
| Tool | What it does |
|
|
94
|
+
| --------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
95
|
+
| `send_campaign` | Send a template to a list of recipients across `email`, `sms`, `push`, `webhook`, `telegram`, `discord`, `whatsapp`, `slack`, or `teams` with campaign tagging |
|
|
96
|
+
| `send_notification` | Send to existing users, a segment, or a topic with `sendAt` scheduling and priority lanes |
|
|
97
|
+
| `list_campaigns` | Recent campaign labels with size and last activity (supports `search`, `channel`, date range) |
|
|
98
|
+
| `get_campaign_stats` | Sent, delivered, failed, opened, clicked, bounced, complained, unsubscribed, with rates |
|
|
99
|
+
| `list_segments` | Every segment tag in use — the valid audiences to broadcast to |
|
|
100
|
+
| `list_scheduled` | Sends queued for the future, including quiet-hours deferrals |
|
|
101
|
+
| `get_delivery_logs` | Per-message detail with filters for template, channel, status, campaign, or user search |
|
|
102
|
+
| `get_notification` | Status and delivery attempts for a specific task |
|
|
103
|
+
| `cancel_notification` | Cancel a pending scheduled or quiet-hours deferred notification |
|
|
104
104
|
|
|
105
105
|
**Templates** — `list_templates`, `get_template`, `upsert_template`, `delete_template`, `preview_template`, `render_template` (deprecated: same as `preview_template`)
|
|
106
106
|
|
package/dist/tools/sending.js
CHANGED
|
@@ -69,10 +69,10 @@ export function registerSendingTools(server, api) {
|
|
|
69
69
|
server.registerTool("send_campaign", {
|
|
70
70
|
title: "Send a campaign to a list of addresses",
|
|
71
71
|
description: "Send one template to a list of recipient destinations (email, SMS/phone, push tokens, webhook URLs, " +
|
|
72
|
-
"Telegram chat ids, Discord webhook URLs, WhatsApp phone numbers,
|
|
72
|
+
"Telegram chat ids, Discord webhook URLs, WhatsApp phone numbers, Slack channel/user IDs/webhook URLs, or Teams Workflows webhook URLs) given directly — the tool creates or updates a user " +
|
|
73
73
|
"record for each address, then sends, and tags every message with a campaign label so the results " +
|
|
74
74
|
"can be read back later with get_campaign_stats. Supports 'email', 'sms', 'push', 'webhook', " +
|
|
75
|
-
"'telegram', 'discord', 'whatsapp', and '
|
|
75
|
+
"'telegram', 'discord', 'whatsapp', 'slack', and 'teams' channels. Use this when the person supplies the recipients themselves " +
|
|
76
76
|
"(a pasted list, a spreadsheet column). Always report the returned campaign label back to the user " +
|
|
77
77
|
"— it is how they ask about results later. Suppressed addresses (previous unsubscribes, complaints, " +
|
|
78
78
|
"hard bounces) are dropped automatically at send time, so the delivered count is normally lower than " +
|
|
@@ -88,14 +88,14 @@ export function registerSendingTools(server, api) {
|
|
|
88
88
|
channel: z
|
|
89
89
|
.enum(CONTACT_CHANNELS)
|
|
90
90
|
.optional()
|
|
91
|
-
.describe("Channel to send on ('email', 'sms', 'push', 'webhook', 'telegram', 'discord', 'whatsapp', or '
|
|
91
|
+
.describe("Channel to send on ('email', 'sms', 'push', 'webhook', 'telegram', 'discord', 'whatsapp', 'slack', or 'teams'). Defaults to 'email'."),
|
|
92
92
|
recipients: z
|
|
93
93
|
.array(z.string().min(1))
|
|
94
94
|
.min(1)
|
|
95
95
|
.max(10000)
|
|
96
96
|
.optional()
|
|
97
97
|
.describe("Recipient destination addresses: email addresses for email, E.164 phone numbers for sms/whatsapp, " +
|
|
98
|
-
"device tokens for push, URLs for webhook, chat ids for telegram, webhook URLs for discord,
|
|
98
|
+
"device tokens for push, URLs for webhook, chat ids for telegram, webhook URLs for discord, channel/user IDs for slack, or Workflows webhook URLs for teams."),
|
|
99
99
|
emails: z
|
|
100
100
|
.array(z.string().email())
|
|
101
101
|
.min(1)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sending.js","sourceRoot":"","sources":["../../src/tools/sending.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAE9E,MAAM,UAAU,oBAAoB,CAAC,MAAiB,EAAE,GAAgB;IACtE,MAAM,CAAC,YAAY,CACjB,mBAAmB,EACnB;QACE,KAAK,EAAE,qBAAqB;QAC5B,WAAW,EACT,gGAAgG;YAChG,iGAAiG;YACjG,gGAAgG;YAChG,iGAAiG;YACjG,oGAAoG;YACpG,q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KAAK,EAAE,yBAAyB;QAChC,WAAW,EACT,yFAAyF;YACzF,sEAAsE;QACxE,WAAW,EAAE;YACX,MAAM,EAAE,CAAC;iBACN,MAAM,EAAE;iBACR,GAAG,CAAC,CAAC,CAAC;iBACN,QAAQ,CAAC,2DAA2D,CAAC;SACzE;QACD,WAAW,EAAE,EAAE,KAAK,EAAE,yBAAyB,EAAE,YAAY,EAAE,IAAI,EAAE;KACtE,EACD,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,qBAAqB,kBAAkB,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CACzF,CAAC;IAEF,MAAM,CAAC,YAAY,CACjB,qBAAqB,EACrB;QACE,KAAK,EAAE,iCAAiC;QACxC,WAAW,EACT,iGAAiG;YACjG,4DAA4D;QAC9D,WAAW,EAAE;YACX,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,kDAAkD,CAAC;SACvF;QACD,WAAW,EAAE;YACX,KAAK,EAAE,iCAAiC;YACxC,YAAY,EAAE,KAAK;YACnB,eAAe,EAAE,IAAI;YACrB,cAAc,EAAE,IAAI;SACrB;KACF,EACD,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;QACrB,MAAM,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,qBAAqB,kBAAkB,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACpF,OAAO,oCAAoC,IAAI,CAAC,MAAM,GAAG,CAAC;IAC5D,CAAC,CAAC,CACH,CAAC;AACJ,CAAC","sourcesContent":["import { z } from \"zod\";\nimport type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport type { NotifkitApi } from \"../client.js\";\nimport { CHANNELS, CONTACT_CHANNELS, PRIORITIES, handler } from \"./shared.js\";\n\nexport function registerSendingTools(server: McpServer, api: NotifkitApi): void {\n server.registerTool(\n \"send_notification\",\n {\n title: \"Send a notification\",\n description:\n \"Queue a notification and return immediately with its message id. This is the primitive behind \" +\n \"both one-off sends and broadcasts: target a single user by id, a list of user ids, a `segment` \" +\n \"(every user tagged with it), or a `topic` (every user opted in to it). Exactly one of `user`, \" +\n \"`segment`, or `topic` must be given. Set `sendAt` to schedule a future send, which can then be \" +\n \"inspected with list_scheduled. Delivery is filtered by each recipient's preferences, consent, and \" +\n \"quiet hours, so the number of messages actually delivered is usually lower than the audience size. \" +\n \"Call list_segments first when the user names an audience you have not confirmed exists, and \" +\n \"list_templates when you are unsure of the template id.\",\n inputSchema: {\n template: z.string().min(1).describe(\"Template id to render, e.g. 'order-shipped'.\"),\n user: z\n .union([z.string().min(1), z.array(z.string().min(1)).nonempty()])\n .optional()\n .describe(\n \"A single user id or a list of user ids. Mutually exclusive with segment and topic.\",\n ),\n segment: z\n .string()\n .min(1)\n .optional()\n .describe(\n \"Send to every user tagged with this segment. Mutually exclusive with user and topic.\",\n ),\n topic: z\n .string()\n .min(1)\n .optional()\n .describe(\n \"Send to every user opted in to this topic. Mutually exclusive with user and segment.\",\n ),\n data: z\n .record(z.string(), z.unknown())\n .optional()\n .describe(\"Variables interpolated into the template's {{placeholders}}.\"),\n channels: z\n .array(z.enum(CHANNELS))\n .nonempty()\n .optional()\n .describe(\"Channels to use. Defaults to ['email'].\"),\n fallback: z\n .boolean()\n .optional()\n .describe(\n \"When true, channels are tried in order and only the first success counts. When false or \" +\n \"omitted, every listed channel is delivered to.\",\n ),\n priority: z\n .enum(PRIORITIES)\n .optional()\n .describe(\"Queue lane. 'critical' bypasses quiet hours and per-user rate limits.\"),\n sendAt: z\n .string()\n .datetime()\n .optional()\n .describe(\"ISO 8601 timestamp to send at. Omit to send now.\"),\n campaign: z\n .string()\n .min(1)\n .max(128)\n .optional()\n .describe(\n \"Label grouping this send for later reporting via get_campaign_stats. Set it on any send \" +\n \"whose results someone may ask about; without it the messages cannot be attributed.\",\n ),\n },\n annotations: { title: \"Send a notification\", readOnlyHint: false, idempotentHint: false },\n },\n handler(async (args) => {\n const targets = [args.user, args.segment, args.topic].filter((t) => t !== undefined);\n if (targets.length !== 1) {\n throw new Error(\"Provide exactly one of `user`, `segment`, or `topic`.\");\n }\n return api.post(\"/v1/notify\", args);\n }),\n );\n\n server.registerTool(\n \"send_campaign\",\n {\n title: \"Send a campaign to a list of addresses\",\n description:\n \"Send one template to a list of recipient destinations (email, SMS/phone, push tokens, webhook URLs, \" +\n \"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 \" +\n \"record for each address, then sends, and tags every message with a campaign label so the results \" +\n \"can be read back later with get_campaign_stats. Supports 'email', 'sms', 'push', 'webhook', \" +\n \"'telegram', 'discord', 'whatsapp', and 'slack' channels. Use this when the person supplies the recipients themselves \" +\n \"(a pasted list, a spreadsheet column). Always report the returned campaign label back to the user \" +\n \"— it is how they ask about results later. Suppressed addresses (previous unsubscribes, complaints, \" +\n \"hard bounces) are dropped automatically at send time, so the delivered count is normally lower than \" +\n \"the list size.\",\n inputSchema: {\n campaign: z\n .string()\n .min(1)\n .max(128)\n .describe(\n \"Label for this send, e.g. 'spring-sale-2026-08-13'. Must be unique per send — reusing a \" +\n \"label merges the two into one set of statistics.\",\n ),\n template: z.string().min(1).describe(\"Template id to render.\"),\n channel: z\n .enum(CONTACT_CHANNELS)\n .optional()\n .describe(\n \"Channel to send on ('email', 'sms', 'push', 'webhook', 'telegram', 'discord', 'whatsapp', or 'slack'). Defaults to 'email'.\",\n ),\n recipients: z\n .array(z.string().min(1))\n .min(1)\n .max(10000)\n .optional()\n .describe(\n \"Recipient destination addresses: email addresses for email, E.164 phone numbers for sms/whatsapp, \" +\n \"device tokens for push, URLs for webhook, chat ids for telegram, webhook URLs for discord, or channel/user IDs for slack.\",\n ),\n emails: z\n .array(z.string().email())\n .min(1)\n .max(10000)\n .optional()\n .describe(\n \"Recipient email addresses (alias for recipients when sending on email channel).\",\n ),\n data: z\n .record(z.string(), z.unknown())\n .optional()\n .describe(\"Variables interpolated into the template, shared by every recipient.\"),\n priority: z\n .enum(PRIORITIES)\n .optional()\n .describe(\n \"Queue lane. Leave unset for 'normal'; do not use 'critical' for marketing sends.\",\n ),\n sendAt: z\n .string()\n .datetime()\n .optional()\n .describe(\"ISO 8601 timestamp to send at. Omit to send now.\"),\n },\n annotations: { title: \"Send a campaign\", readOnlyHint: false, idempotentHint: false },\n },\n handler(async (args) => {\n const channel = args.channel ?? \"email\";\n const rawList = args.recipients ?? args.emails;\n if (!rawList || rawList.length === 0) {\n throw new Error(\"Provide a list of `recipients` (or `emails`) to send to.\");\n }\n\n const seen = new Set<string>();\n const recipients = [];\n for (const raw of rawList) {\n const target = channel === \"email\" ? raw.trim().toLowerCase() : raw.trim();\n if (seen.has(target)) continue;\n seen.add(target);\n\n // Every channel needs a contact on that channel to be reached. Chat\n // channels used to get a bare user record, and WhatsApp a phone\n // number filed as an SMS contact, so those campaigns sent nothing.\n const userRecord: Record<string, unknown> =\n channel === \"email\"\n ? { id: `email:${target}`, email: target }\n : channel === \"sms\"\n ? { id: `phone:${target}`, phone: target }\n : channel === \"push\"\n ? { id: `push:${target}`, pushToken: target }\n : { id: `${channel}:${target}`, contacts: [{ channel, target }] };\n recipients.push(userRecord);\n }\n\n const result = await api.post<Record<string, unknown>>(\"/v1/notify\", {\n user: recipients,\n template: args.template,\n campaign: args.campaign,\n channels: [channel],\n ...(args.data ? { data: args.data } : {}),\n ...(args.priority ? { priority: args.priority } : {}),\n ...(args.sendAt ? { sendAt: args.sendAt } : {}),\n });\n\n const duplicates = rawList.length - recipients.length;\n return {\n campaign: args.campaign,\n channel,\n queued: recipients.length,\n ...(duplicates > 0 ? { duplicatesRemoved: duplicates } : {}),\n note:\n \"Queued, not yet delivered. Preferences, quiet hours, and suppressions are applied during \" +\n \"delivery — call get_campaign_stats for what actually landed.\",\n result,\n };\n }),\n );\n\n server.registerTool(\n \"list_campaigns\",\n {\n title: \"List campaigns\",\n description:\n \"List recent campaign labels with their size and when they last saw activity, newest first. Call \" +\n \"this when the user refers to a past send without naming its exact label ('the one I sent \" +\n \"yesterday') to find the label to pass to get_campaign_stats. Supports filtering by search query, \" +\n \"channel, date range, or minimum message count.\",\n inputSchema: {\n limit: z\n .number()\n .int()\n .min(1)\n .max(100)\n .optional()\n .describe(\"How many campaigns to return. Defaults to 20.\"),\n search: z\n .string()\n .optional()\n .describe(\"Filter campaigns whose label contains this string (case-insensitive).\"),\n channel: z\n .enum(CHANNELS)\n .optional()\n .describe(\"Only list campaigns that sent messages on this channel.\"),\n since: z\n .string()\n .datetime()\n .optional()\n .describe(\n \"ISO 8601 timestamp; only return campaigns with activity on or after this date.\",\n ),\n until: z\n .string()\n .datetime()\n .optional()\n .describe(\n \"ISO 8601 timestamp; only return campaigns with activity on or before this date.\",\n ),\n minMessages: z\n .number()\n .int()\n .min(1)\n .optional()\n .describe(\"Minimum number of distinct messages/recipients for a campaign.\"),\n },\n annotations: { title: \"List campaigns\", readOnlyHint: true },\n },\n handler(async (args) => api.get(\"/v1/campaigns\", args)),\n );\n\n server.registerTool(\n \"get_campaign_stats\",\n {\n title: \"Get campaign performance\",\n description:\n \"The delivery and engagement funnel for one campaign: sent, delivered, failed, opened, clicked, \" +\n \"bounced, complained, unsubscribed, with rates and a per-channel breakdown. This is the tool for \" +\n \"'how did that send perform?'. Every count is people, not events — opening an email twice counts \" +\n \"once. Always surface the `warnings` field to the user: it says when opens and clicks are not \" +\n \"tracked on a channel, which is different from them being zero. A high complaint rate (above \" +\n \"~0.3%) is worth flagging unprompted, as it damages deliverability for all future sends.\",\n inputSchema: {\n campaign: z.string().min(1).describe(\"Campaign label, as returned by list_campaigns.\"),\n },\n annotations: { title: \"Get campaign performance\", readOnlyHint: true },\n },\n handler(async (args) => api.get(`/v1/campaigns/${encodeURIComponent(args.campaign)}/stats`)),\n );\n\n server.registerTool(\n \"list_suppressions\",\n {\n title: \"List suppressed addresses\",\n description:\n \"List destinations that will not be contacted again, with the reason each was suppressed \" +\n \"(unsubscribed, complained, bounced, or manual). Call this to explain why someone did not receive \" +\n \"a message, or to review unsubscribes after a campaign.\",\n inputSchema: {\n limit: z.number().int().min(1).max(500).optional().describe(\"How many rows to return.\"),\n channel: z.enum(CONTACT_CHANNELS).optional().describe(\"Only this channel.\"),\n reason: z\n .enum([\"unsubscribed\", \"complained\", \"bounced\", \"manual\"])\n .optional()\n .describe(\"Only suppressions with this reason.\"),\n target: z\n .string()\n .optional()\n .describe(\"Filter suppressions matching this email, phone, or push token.\"),\n },\n annotations: { title: \"List suppressed addresses\", readOnlyHint: true },\n },\n handler(async (args) => api.get(\"/v1/suppressions\", args)),\n );\n\n server.registerTool(\n \"suppress_address\",\n {\n title: \"Suppress an address\",\n description:\n \"Stop sending to a destination on a channel — use when someone asks to be removed by replying, \" +\n \"over the phone, or any route the provider does not report automatically. Takes effect on the \" +\n \"next send and outranks every other setting, including 'critical' priority.\",\n inputSchema: {\n channel: z.enum(CONTACT_CHANNELS).describe(\"Channel to suppress on.\"),\n target: z.string().min(1).describe(\"The address: email, phone number, or push token.\"),\n reason: z\n .enum([\"unsubscribed\", \"complained\", \"bounced\", \"manual\"])\n .optional()\n .describe(\"Why. Defaults to 'manual'.\"),\n },\n annotations: { title: \"Suppress an address\", readOnlyHint: false, idempotentHint: true },\n },\n handler(async (args) => api.post(\"/v1/suppressions\", args)),\n );\n\n server.registerTool(\n \"unsuppress_address\",\n {\n title: \"Remove a suppression\",\n description:\n \"Re-enable sending to a previously suppressed destination. Only do this on an explicit request \" +\n \"from the user — a suppression usually records that the person asked not to be contacted, and \" +\n \"removing it to fix a low delivery count is how a sending domain gets blocked. Confirm before \" +\n \"calling.\",\n inputSchema: {\n channel: z.enum(CONTACT_CHANNELS).describe(\"Channel the suppression is on.\"),\n target: z.string().min(1).describe(\"The suppressed address.\"),\n },\n annotations: {\n title: \"Remove a suppression\",\n readOnlyHint: false,\n destructiveHint: true,\n idempotentHint: true,\n },\n },\n handler(async (args) => {\n await api.request(\n \"DELETE\",\n `/v1/suppressions/${encodeURIComponent(args.channel)}/${encodeURIComponent(args.target)}`,\n );\n return `Removed the suppression on ${args.target} for ${args.channel}.`;\n }),\n );\n\n server.registerTool(\n \"list_segments\",\n {\n title: \"List segments\",\n description:\n \"List every segment tag currently in use across the project's users. Call this to discover the \" +\n \"valid audiences for send_notification's `segment` argument before broadcasting.\",\n annotations: { title: \"List segments\", readOnlyHint: true },\n },\n handler(async () => api.get(\"/v1/segments\")),\n );\n\n server.registerTool(\n \"list_scheduled\",\n {\n title: \"List scheduled sends\",\n description:\n \"List notifications queued for future delivery — those given a `sendAt`, plus any deferred by a \" +\n \"recipient's quiet hours. Supports filtering by channel and pagination.\",\n inputSchema: {\n limit: z\n .number()\n .int()\n .min(1)\n .max(100)\n .optional()\n .describe(\"How many rows to return. Defaults to 50.\"),\n cursor: z\n .string()\n .optional()\n .describe(\"Pagination cursor (taskId) from a previous call's `nextCursor`.\"),\n channel: z\n .enum(CHANNELS)\n .optional()\n .describe(\"Only list scheduled messages intended for this channel.\"),\n },\n annotations: { title: \"List scheduled sends\", readOnlyHint: true },\n },\n handler(async (args) => api.get(\"/v1/notifications/scheduled\", args)),\n );\n\n server.registerTool(\n \"get_delivery_logs\",\n {\n title: \"Get delivery logs\",\n description:\n \"Query the durable delivery log: what was sent, on which channel, and whether it succeeded. Call \" +\n \"this to answer 'did it go out?' after a send, or to investigate failures. Filter by template, \" +\n \"channel, status, campaign, or task ID. Results are paginated — pass the returned `nextCursor` \" +\n \"back as `cursor` for the next page.\",\n inputSchema: {\n limit: z\n .number()\n .int()\n .min(1)\n .max(200)\n .optional()\n .describe(\"Rows per page. Defaults to the server's page size.\"),\n cursor: z\n .string()\n .optional()\n .describe(\"Pagination cursor from a previous call's `nextCursor`.\"),\n templateId: z.string().optional().describe(\"Only log entries rendered from this template.\"),\n workflowInstanceId: z\n .string()\n .optional()\n .describe(\"Only entries emitted by this workflow instance.\"),\n channel: z.enum(CHANNELS).optional().describe(\"Only entries delivered on this channel.\"),\n status: z\n .string()\n .optional()\n .describe(\n \"Delivery status to filter on, e.g. 'dispatched', 'delivered', 'failed', 'opened'.\",\n ),\n campaign: z\n .string()\n .optional()\n .describe(\"Only log entries tagged with this campaign label.\"),\n taskId: z\n .string()\n .optional()\n .describe(\"Only log entries for this specific notification task ID.\"),\n search: z\n .string()\n .optional()\n .describe(\n \"Search keyword across task IDs, template IDs, provider message IDs, or campaign labels.\",\n ),\n },\n annotations: { title: \"Get delivery logs\", readOnlyHint: true },\n },\n handler(async (args) => api.get(\"/v1/notifications/logs\", args)),\n );\n\n server.registerTool(\n \"get_notification\",\n {\n title: \"Get notification status\",\n description:\n \"Fetch the delivery history and latest state of a specific notification by its task ID. \" +\n \"Shows each attempt, provider status, timestamps, and error messages.\",\n inputSchema: {\n taskId: z\n .string()\n .min(1)\n .describe(\"Task ID returned from send_notification or send_campaign.\"),\n },\n annotations: { title: \"Get notification status\", readOnlyHint: true },\n },\n handler(async (args) => api.get(`/v1/notifications/${encodeURIComponent(args.taskId)}`)),\n );\n\n server.registerTool(\n \"cancel_notification\",\n {\n title: \"Cancel a scheduled notification\",\n description:\n \"Cancel a pending or quiet-hours deferred notification before it is dispatched to the provider. \" +\n \"Takes the taskId from send_notification or list_scheduled.\",\n inputSchema: {\n taskId: z.string().min(1).describe(\"Task ID of the scheduled notification to cancel.\"),\n },\n annotations: {\n title: \"Cancel a scheduled notification\",\n readOnlyHint: false,\n destructiveHint: true,\n idempotentHint: true,\n },\n },\n handler(async (args) => {\n await api.request(\"DELETE\", `/v1/notifications/${encodeURIComponent(args.taskId)}`);\n return `Cancelled scheduled notification ${args.taskId}.`;\n }),\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"sending.js","sourceRoot":"","sources":["../../src/tools/sending.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,QAAQ,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AO,oCAAoC,IAAI,CAAC,MAAM,GAAG,CAAC;IAC5D,CAAC,CAAC,CACH,CAAC;AACJ,CAAC","sourcesContent":["import { z } from \"zod\";\nimport type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport type { NotifkitApi } from \"../client.js\";\nimport { CHANNELS, CONTACT_CHANNELS, PRIORITIES, handler } from \"./shared.js\";\n\nexport function registerSendingTools(server: McpServer, api: NotifkitApi): void {\n server.registerTool(\n \"send_notification\",\n {\n title: \"Send a notification\",\n description:\n \"Queue a notification and return immediately with its message id. This is the primitive behind \" +\n \"both one-off sends and broadcasts: target a single user by id, a list of user ids, a `segment` \" +\n \"(every user tagged with it), or a `topic` (every user opted in to it). Exactly one of `user`, \" +\n \"`segment`, or `topic` must be given. Set `sendAt` to schedule a future send, which can then be \" +\n \"inspected with list_scheduled. Delivery is filtered by each recipient's preferences, consent, and \" +\n \"quiet hours, so the number of messages actually delivered is usually lower than the audience size. \" +\n \"Call list_segments first when the user names an audience you have not confirmed exists, and \" +\n \"list_templates when you are unsure of the template id.\",\n inputSchema: {\n template: z.string().min(1).describe(\"Template id to render, e.g. 'order-shipped'.\"),\n user: z\n .union([z.string().min(1), z.array(z.string().min(1)).nonempty()])\n .optional()\n .describe(\n \"A single user id or a list of user ids. Mutually exclusive with segment and topic.\",\n ),\n segment: z\n .string()\n .min(1)\n .optional()\n .describe(\n \"Send to every user tagged with this segment. Mutually exclusive with user and topic.\",\n ),\n topic: z\n .string()\n .min(1)\n .optional()\n .describe(\n \"Send to every user opted in to this topic. Mutually exclusive with user and segment.\",\n ),\n data: z\n .record(z.string(), z.unknown())\n .optional()\n .describe(\"Variables interpolated into the template's {{placeholders}}.\"),\n channels: z\n .array(z.enum(CHANNELS))\n .nonempty()\n .optional()\n .describe(\"Channels to use. Defaults to ['email'].\"),\n fallback: z\n .boolean()\n .optional()\n .describe(\n \"When true, channels are tried in order and only the first success counts. When false or \" +\n \"omitted, every listed channel is delivered to.\",\n ),\n priority: z\n .enum(PRIORITIES)\n .optional()\n .describe(\"Queue lane. 'critical' bypasses quiet hours and per-user rate limits.\"),\n sendAt: z\n .string()\n .datetime()\n .optional()\n .describe(\"ISO 8601 timestamp to send at. Omit to send now.\"),\n campaign: z\n .string()\n .min(1)\n .max(128)\n .optional()\n .describe(\n \"Label grouping this send for later reporting via get_campaign_stats. Set it on any send \" +\n \"whose results someone may ask about; without it the messages cannot be attributed.\",\n ),\n },\n annotations: { title: \"Send a notification\", readOnlyHint: false, idempotentHint: false },\n },\n handler(async (args) => {\n const targets = [args.user, args.segment, args.topic].filter((t) => t !== undefined);\n if (targets.length !== 1) {\n throw new Error(\"Provide exactly one of `user`, `segment`, or `topic`.\");\n }\n return api.post(\"/v1/notify\", args);\n }),\n );\n\n server.registerTool(\n \"send_campaign\",\n {\n title: \"Send a campaign to a list of addresses\",\n description:\n \"Send one template to a list of recipient destinations (email, SMS/phone, push tokens, webhook URLs, \" +\n \"Telegram chat ids, Discord webhook URLs, WhatsApp phone numbers, Slack channel/user IDs/webhook URLs, or Teams Workflows webhook URLs) given directly — the tool creates or updates a user \" +\n \"record for each address, then sends, and tags every message with a campaign label so the results \" +\n \"can be read back later with get_campaign_stats. Supports 'email', 'sms', 'push', 'webhook', \" +\n \"'telegram', 'discord', 'whatsapp', 'slack', and 'teams' channels. Use this when the person supplies the recipients themselves \" +\n \"(a pasted list, a spreadsheet column). Always report the returned campaign label back to the user \" +\n \"— it is how they ask about results later. Suppressed addresses (previous unsubscribes, complaints, \" +\n \"hard bounces) are dropped automatically at send time, so the delivered count is normally lower than \" +\n \"the list size.\",\n inputSchema: {\n campaign: z\n .string()\n .min(1)\n .max(128)\n .describe(\n \"Label for this send, e.g. 'spring-sale-2026-08-13'. Must be unique per send — reusing a \" +\n \"label merges the two into one set of statistics.\",\n ),\n template: z.string().min(1).describe(\"Template id to render.\"),\n channel: z\n .enum(CONTACT_CHANNELS)\n .optional()\n .describe(\n \"Channel to send on ('email', 'sms', 'push', 'webhook', 'telegram', 'discord', 'whatsapp', 'slack', or 'teams'). Defaults to 'email'.\",\n ),\n recipients: z\n .array(z.string().min(1))\n .min(1)\n .max(10000)\n .optional()\n .describe(\n \"Recipient destination addresses: email addresses for email, E.164 phone numbers for sms/whatsapp, \" +\n \"device tokens for push, URLs for webhook, chat ids for telegram, webhook URLs for discord, channel/user IDs for slack, or Workflows webhook URLs for teams.\",\n ),\n emails: z\n .array(z.string().email())\n .min(1)\n .max(10000)\n .optional()\n .describe(\n \"Recipient email addresses (alias for recipients when sending on email channel).\",\n ),\n data: z\n .record(z.string(), z.unknown())\n .optional()\n .describe(\"Variables interpolated into the template, shared by every recipient.\"),\n priority: z\n .enum(PRIORITIES)\n .optional()\n .describe(\n \"Queue lane. Leave unset for 'normal'; do not use 'critical' for marketing sends.\",\n ),\n sendAt: z\n .string()\n .datetime()\n .optional()\n .describe(\"ISO 8601 timestamp to send at. Omit to send now.\"),\n },\n annotations: { title: \"Send a campaign\", readOnlyHint: false, idempotentHint: false },\n },\n handler(async (args) => {\n const channel = args.channel ?? \"email\";\n const rawList = args.recipients ?? args.emails;\n if (!rawList || rawList.length === 0) {\n throw new Error(\"Provide a list of `recipients` (or `emails`) to send to.\");\n }\n\n const seen = new Set<string>();\n const recipients = [];\n for (const raw of rawList) {\n const target = channel === \"email\" ? raw.trim().toLowerCase() : raw.trim();\n if (seen.has(target)) continue;\n seen.add(target);\n\n // Every channel needs a contact on that channel to be reached. Chat\n // channels used to get a bare user record, and WhatsApp a phone\n // number filed as an SMS contact, so those campaigns sent nothing.\n const userRecord: Record<string, unknown> =\n channel === \"email\"\n ? { id: `email:${target}`, email: target }\n : channel === \"sms\"\n ? { id: `phone:${target}`, phone: target }\n : channel === \"push\"\n ? { id: `push:${target}`, pushToken: target }\n : { id: `${channel}:${target}`, contacts: [{ channel, target }] };\n recipients.push(userRecord);\n }\n\n const result = await api.post<Record<string, unknown>>(\"/v1/notify\", {\n user: recipients,\n template: args.template,\n campaign: args.campaign,\n channels: [channel],\n ...(args.data ? { data: args.data } : {}),\n ...(args.priority ? { priority: args.priority } : {}),\n ...(args.sendAt ? { sendAt: args.sendAt } : {}),\n });\n\n const duplicates = rawList.length - recipients.length;\n return {\n campaign: args.campaign,\n channel,\n queued: recipients.length,\n ...(duplicates > 0 ? { duplicatesRemoved: duplicates } : {}),\n note:\n \"Queued, not yet delivered. Preferences, quiet hours, and suppressions are applied during \" +\n \"delivery — call get_campaign_stats for what actually landed.\",\n result,\n };\n }),\n );\n\n server.registerTool(\n \"list_campaigns\",\n {\n title: \"List campaigns\",\n description:\n \"List recent campaign labels with their size and when they last saw activity, newest first. Call \" +\n \"this when the user refers to a past send without naming its exact label ('the one I sent \" +\n \"yesterday') to find the label to pass to get_campaign_stats. Supports filtering by search query, \" +\n \"channel, date range, or minimum message count.\",\n inputSchema: {\n limit: z\n .number()\n .int()\n .min(1)\n .max(100)\n .optional()\n .describe(\"How many campaigns to return. Defaults to 20.\"),\n search: z\n .string()\n .optional()\n .describe(\"Filter campaigns whose label contains this string (case-insensitive).\"),\n channel: z\n .enum(CHANNELS)\n .optional()\n .describe(\"Only list campaigns that sent messages on this channel.\"),\n since: z\n .string()\n .datetime()\n .optional()\n .describe(\n \"ISO 8601 timestamp; only return campaigns with activity on or after this date.\",\n ),\n until: z\n .string()\n .datetime()\n .optional()\n .describe(\n \"ISO 8601 timestamp; only return campaigns with activity on or before this date.\",\n ),\n minMessages: z\n .number()\n .int()\n .min(1)\n .optional()\n .describe(\"Minimum number of distinct messages/recipients for a campaign.\"),\n },\n annotations: { title: \"List campaigns\", readOnlyHint: true },\n },\n handler(async (args) => api.get(\"/v1/campaigns\", args)),\n );\n\n server.registerTool(\n \"get_campaign_stats\",\n {\n title: \"Get campaign performance\",\n description:\n \"The delivery and engagement funnel for one campaign: sent, delivered, failed, opened, clicked, \" +\n \"bounced, complained, unsubscribed, with rates and a per-channel breakdown. This is the tool for \" +\n \"'how did that send perform?'. Every count is people, not events — opening an email twice counts \" +\n \"once. Always surface the `warnings` field to the user: it says when opens and clicks are not \" +\n \"tracked on a channel, which is different from them being zero. A high complaint rate (above \" +\n \"~0.3%) is worth flagging unprompted, as it damages deliverability for all future sends.\",\n inputSchema: {\n campaign: z.string().min(1).describe(\"Campaign label, as returned by list_campaigns.\"),\n },\n annotations: { title: \"Get campaign performance\", readOnlyHint: true },\n },\n handler(async (args) => api.get(`/v1/campaigns/${encodeURIComponent(args.campaign)}/stats`)),\n );\n\n server.registerTool(\n \"list_suppressions\",\n {\n title: \"List suppressed addresses\",\n description:\n \"List destinations that will not be contacted again, with the reason each was suppressed \" +\n \"(unsubscribed, complained, bounced, or manual). Call this to explain why someone did not receive \" +\n \"a message, or to review unsubscribes after a campaign.\",\n inputSchema: {\n limit: z.number().int().min(1).max(500).optional().describe(\"How many rows to return.\"),\n channel: z.enum(CONTACT_CHANNELS).optional().describe(\"Only this channel.\"),\n reason: z\n .enum([\"unsubscribed\", \"complained\", \"bounced\", \"manual\"])\n .optional()\n .describe(\"Only suppressions with this reason.\"),\n target: z\n .string()\n .optional()\n .describe(\"Filter suppressions matching this email, phone, or push token.\"),\n },\n annotations: { title: \"List suppressed addresses\", readOnlyHint: true },\n },\n handler(async (args) => api.get(\"/v1/suppressions\", args)),\n );\n\n server.registerTool(\n \"suppress_address\",\n {\n title: \"Suppress an address\",\n description:\n \"Stop sending to a destination on a channel — use when someone asks to be removed by replying, \" +\n \"over the phone, or any route the provider does not report automatically. Takes effect on the \" +\n \"next send and outranks every other setting, including 'critical' priority.\",\n inputSchema: {\n channel: z.enum(CONTACT_CHANNELS).describe(\"Channel to suppress on.\"),\n target: z.string().min(1).describe(\"The address: email, phone number, or push token.\"),\n reason: z\n .enum([\"unsubscribed\", \"complained\", \"bounced\", \"manual\"])\n .optional()\n .describe(\"Why. Defaults to 'manual'.\"),\n },\n annotations: { title: \"Suppress an address\", readOnlyHint: false, idempotentHint: true },\n },\n handler(async (args) => api.post(\"/v1/suppressions\", args)),\n );\n\n server.registerTool(\n \"unsuppress_address\",\n {\n title: \"Remove a suppression\",\n description:\n \"Re-enable sending to a previously suppressed destination. Only do this on an explicit request \" +\n \"from the user — a suppression usually records that the person asked not to be contacted, and \" +\n \"removing it to fix a low delivery count is how a sending domain gets blocked. Confirm before \" +\n \"calling.\",\n inputSchema: {\n channel: z.enum(CONTACT_CHANNELS).describe(\"Channel the suppression is on.\"),\n target: z.string().min(1).describe(\"The suppressed address.\"),\n },\n annotations: {\n title: \"Remove a suppression\",\n readOnlyHint: false,\n destructiveHint: true,\n idempotentHint: true,\n },\n },\n handler(async (args) => {\n await api.request(\n \"DELETE\",\n `/v1/suppressions/${encodeURIComponent(args.channel)}/${encodeURIComponent(args.target)}`,\n );\n return `Removed the suppression on ${args.target} for ${args.channel}.`;\n }),\n );\n\n server.registerTool(\n \"list_segments\",\n {\n title: \"List segments\",\n description:\n \"List every segment tag currently in use across the project's users. Call this to discover the \" +\n \"valid audiences for send_notification's `segment` argument before broadcasting.\",\n annotations: { title: \"List segments\", readOnlyHint: true },\n },\n handler(async () => api.get(\"/v1/segments\")),\n );\n\n server.registerTool(\n \"list_scheduled\",\n {\n title: \"List scheduled sends\",\n description:\n \"List notifications queued for future delivery — those given a `sendAt`, plus any deferred by a \" +\n \"recipient's quiet hours. Supports filtering by channel and pagination.\",\n inputSchema: {\n limit: z\n .number()\n .int()\n .min(1)\n .max(100)\n .optional()\n .describe(\"How many rows to return. Defaults to 50.\"),\n cursor: z\n .string()\n .optional()\n .describe(\"Pagination cursor (taskId) from a previous call's `nextCursor`.\"),\n channel: z\n .enum(CHANNELS)\n .optional()\n .describe(\"Only list scheduled messages intended for this channel.\"),\n },\n annotations: { title: \"List scheduled sends\", readOnlyHint: true },\n },\n handler(async (args) => api.get(\"/v1/notifications/scheduled\", args)),\n );\n\n server.registerTool(\n \"get_delivery_logs\",\n {\n title: \"Get delivery logs\",\n description:\n \"Query the durable delivery log: what was sent, on which channel, and whether it succeeded. Call \" +\n \"this to answer 'did it go out?' after a send, or to investigate failures. Filter by template, \" +\n \"channel, status, campaign, or task ID. Results are paginated — pass the returned `nextCursor` \" +\n \"back as `cursor` for the next page.\",\n inputSchema: {\n limit: z\n .number()\n .int()\n .min(1)\n .max(200)\n .optional()\n .describe(\"Rows per page. Defaults to the server's page size.\"),\n cursor: z\n .string()\n .optional()\n .describe(\"Pagination cursor from a previous call's `nextCursor`.\"),\n templateId: z.string().optional().describe(\"Only log entries rendered from this template.\"),\n workflowInstanceId: z\n .string()\n .optional()\n .describe(\"Only entries emitted by this workflow instance.\"),\n channel: z.enum(CHANNELS).optional().describe(\"Only entries delivered on this channel.\"),\n status: z\n .string()\n .optional()\n .describe(\n \"Delivery status to filter on, e.g. 'dispatched', 'delivered', 'failed', 'opened'.\",\n ),\n campaign: z\n .string()\n .optional()\n .describe(\"Only log entries tagged with this campaign label.\"),\n taskId: z\n .string()\n .optional()\n .describe(\"Only log entries for this specific notification task ID.\"),\n search: z\n .string()\n .optional()\n .describe(\n \"Search keyword across task IDs, template IDs, provider message IDs, or campaign labels.\",\n ),\n },\n annotations: { title: \"Get delivery logs\", readOnlyHint: true },\n },\n handler(async (args) => api.get(\"/v1/notifications/logs\", args)),\n );\n\n server.registerTool(\n \"get_notification\",\n {\n title: \"Get notification status\",\n description:\n \"Fetch the delivery history and latest state of a specific notification by its task ID. \" +\n \"Shows each attempt, provider status, timestamps, and error messages.\",\n inputSchema: {\n taskId: z\n .string()\n .min(1)\n .describe(\"Task ID returned from send_notification or send_campaign.\"),\n },\n annotations: { title: \"Get notification status\", readOnlyHint: true },\n },\n handler(async (args) => api.get(`/v1/notifications/${encodeURIComponent(args.taskId)}`)),\n );\n\n server.registerTool(\n \"cancel_notification\",\n {\n title: \"Cancel a scheduled notification\",\n description:\n \"Cancel a pending or quiet-hours deferred notification before it is dispatched to the provider. \" +\n \"Takes the taskId from send_notification or list_scheduled.\",\n inputSchema: {\n taskId: z.string().min(1).describe(\"Task ID of the scheduled notification to cancel.\"),\n },\n annotations: {\n title: \"Cancel a scheduled notification\",\n readOnlyHint: false,\n destructiveHint: true,\n idempotentHint: true,\n },\n },\n handler(async (args) => {\n await api.request(\"DELETE\", `/v1/notifications/${encodeURIComponent(args.taskId)}`);\n return `Cancelled scheduled notification ${args.taskId}.`;\n }),\n );\n}\n"]}
|
package/dist/tools/shared.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export declare const CHANNELS: readonly ["email", "sms", "push", "webhook", "in-app", "telegram", "discord", "whatsapp", "slack"];
|
|
2
|
-
export declare const CONTACT_CHANNELS: readonly ["email", "sms", "push", "webhook", "in-app", "telegram", "discord", "whatsapp", "slack"];
|
|
1
|
+
export declare const CHANNELS: readonly ["email", "sms", "push", "webhook", "in-app", "telegram", "discord", "whatsapp", "slack", "teams"];
|
|
2
|
+
export declare const CONTACT_CHANNELS: readonly ["email", "sms", "push", "webhook", "in-app", "telegram", "discord", "whatsapp", "slack", "teams"];
|
|
3
3
|
export declare const PRIORITIES: readonly ["low", "normal", "high", "critical"];
|
|
4
4
|
interface ToolResult {
|
|
5
5
|
[key: string]: unknown;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/tools/shared.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,QAAQ,
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/tools/shared.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,QAAQ,6GAWX,CAAC;AAEX,eAAO,MAAM,gBAAgB,6GAAW,CAAC;AACzC,eAAO,MAAM,UAAU,gDAAiD,CAAC;AAEzE,UAAU,UAAU;IAGlB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;IACvB,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC1C,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAuBD,iGAAiG;AACjG,wBAAgB,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,IAC5C,MAAM,CAAC,KAAG,OAAO,CAAC,UAAU,CAAC,CAO5C;AAiBD,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,CAAC;AA0BpD,uFAAuF;AACvF,wBAAgB,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CASjF;AA6BD,yFAAyF;AACzF,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,EAAE,CAaxD;AAED,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,OAAO,EACb,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClC,IAAI,EAAE,UAAU,GACf,OAAO,CAWT"}
|
package/dist/tools/shared.js
CHANGED
package/dist/tools/shared.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../src/tools/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,OAAO;IACP,KAAK;IACL,MAAM;IACN,SAAS;IACT,QAAQ;IACR,UAAU;IACV,SAAS;IACT,UAAU;IACV,OAAO;CACC,CAAC;AACX,iEAAiE;AACjE,MAAM,CAAC,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AACzC,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAU,CAAC;AAUzE,8EAA8E;AAC9E,SAAS,EAAE,CAAC,KAAc;IACxB,MAAM,IAAI,GACR,KAAK,KAAK,SAAS;QACjB,CAAC,CAAC,OAAO;QACT,CAAC,CAAC,OAAO,KAAK,KAAK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AACd,CAAC","sourcesContent":["import { NotifkitApiError } from \"../client.js\";\n\nexport const CHANNELS = [\n \"email\",\n \"sms\",\n \"push\",\n \"webhook\",\n \"in-app\",\n \"telegram\",\n \"discord\",\n \"whatsapp\",\n \"slack\",\n] as const;\n// The server accepts contacts on every channel, in-app included.\nexport const CONTACT_CHANNELS = CHANNELS;\nexport const PRIORITIES = [\"low\", \"normal\", \"high\", \"critical\"] as const;\n\ninterface ToolResult {\n // The SDK's tool-result type carries an index signature for protocol\n // extensions; without one here an interface is not assignable to it.\n [key: string]: unknown;\n content: { type: \"text\"; text: string }[];\n isError?: boolean;\n}\n\n/** Render any handler return value as the text payload MCP clients expect. */\nfunction ok(value: unknown): ToolResult {\n const text =\n value === undefined\n ? \"Done.\"\n : typeof value === \"string\"\n ? value\n : JSON.stringify(value, null, 2);\n return { content: [{ type: \"text\", text }] };\n}\n\nfunction fail(error: unknown): ToolResult {\n const text =\n error instanceof NotifkitApiError\n ? `notifkit API error (HTTP ${error.status}): ${error.message}`\n : error instanceof Error\n ? error.message\n : String(error);\n return { content: [{ type: \"text\", text }], isError: true };\n}\n\n/** Wrap a handler so a failed request is reported to the model instead of killing the server. */\nexport function handler<T>(fn: (args: T) => Promise<unknown>) {\n return async (args: T): Promise<ToolResult> => {\n try {\n return ok(await fn(args));\n } catch (error) {\n return fail(error);\n }\n };\n}\n\nfunction escapeHtml(unsafe: string): string {\n return String(unsafe)\n .replace(/&/g, \"&\")\n .replace(/</g, \"<\")\n .replace(/>/g, \">\")\n .replace(/\"/g, \""\")\n .replace(/'/g, \"'\");\n}\n\nfunction escapeHeader(unsafe: string): string {\n return String(unsafe)\n .replace(/[\\r\\n]+/g, \" \")\n .trim();\n}\n\nexport type EscapeMode = \"html\" | \"header\" | \"text\";\nconst HTML_FIELDS = new Set([\"html\", \"htmlbody\", \"bodyhtml\", \"htmlcontent\"]);\nconst HEADER_FIELDS = new Set([\n \"subject\",\n \"title\",\n \"from\",\n \"replyto\",\n \"cc\",\n \"bcc\",\n \"preheader\",\n \"preview\",\n]);\n\nfunction escapeModeFor(key: string, inherited: EscapeMode): EscapeMode {\n const k = key.toLowerCase().replace(/[-_]/g, \"\");\n if (HTML_FIELDS.has(k)) return \"html\";\n if (HEADER_FIELDS.has(k)) return \"header\";\n return inherited;\n}\n\n// Placeholders follow the server's renderer (src/templates/render.ts) so a\n// preview shows what will be sent: `{{{path}}}` (group 1) or `{{path}}`\n// (group 2), a path being a name or a dotted path (`user.name`), with optional\n// whitespace inside the braces.\nconst PLACEHOLDER = /\\{\\{\\{\\s*(\\w+(?:\\.\\w+)*)\\s*\\}\\}\\}|\\{\\{\\s*(\\w+(?:\\.\\w+)*)\\s*\\}\\}/g;\n\n/** The value at a dotted path, reading own properties only; undefined when missing. */\nexport function valueAt(variables: Record<string, unknown>, path: string): unknown {\n let value: unknown = variables;\n for (const segment of path.split(\".\")) {\n if (value === null || typeof value !== \"object\" || !Object.hasOwn(value, segment)) {\n return undefined;\n }\n value = (value as Record<string, unknown>)[segment];\n }\n return value;\n}\n\nfunction lookup(variables: Record<string, unknown>, path: string): string {\n const value = valueAt(variables, path);\n if (value === undefined || value === null) return \"\";\n return typeof value === \"string\" ? value : JSON.stringify(value);\n}\n\nfunction applyEscape(value: string, mode: EscapeMode): string {\n if (mode === \"html\") return escapeHtml(value);\n if (mode === \"header\") return escapeHeader(value);\n return value;\n}\n\n// One pass, so an inserted value is never scanned for placeholders again.\nfunction interpolateValue(\n tmpl: string,\n variables: Record<string, unknown>,\n mode: EscapeMode,\n): string {\n return tmpl.replace(\n PLACEHOLDER,\n (_, rawPath: string | undefined, escapedPath: string | undefined) =>\n rawPath !== undefined\n ? lookup(variables, rawPath)\n : applyEscape(lookup(variables, escapedPath ?? \"\"), mode),\n );\n}\n\n/** Every placeholder path used in the strings of a content tree, once each, in order. */\nexport function placeholderPaths(node: unknown): string[] {\n const paths = new Set<string>();\n const visit = (value: unknown): void => {\n if (typeof value === \"string\") {\n for (const match of value.matchAll(PLACEHOLDER)) paths.add(match[1] ?? match[2] ?? \"\");\n } else if (Array.isArray(value)) {\n value.forEach(visit);\n } else if (value && typeof value === \"object\") {\n Object.values(value).forEach(visit);\n }\n };\n visit(node);\n return [...paths];\n}\n\nexport function renderContentNode(\n node: unknown,\n variables: Record<string, unknown>,\n mode: EscapeMode,\n): unknown {\n if (typeof node === \"string\") return interpolateValue(node, variables, mode);\n if (Array.isArray(node)) return node.map((item) => renderContentNode(item, variables, mode));\n if (node && typeof node === \"object\") {\n const out: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(node as Record<string, unknown>)) {\n out[key] = renderContentNode(value, variables, escapeModeFor(key, mode));\n }\n return out;\n }\n return node;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../src/tools/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,OAAO;IACP,KAAK;IACL,MAAM;IACN,SAAS;IACT,QAAQ;IACR,UAAU;IACV,SAAS;IACT,UAAU;IACV,OAAO;IACP,OAAO;CACC,CAAC;AACX,iEAAiE;AACjE,MAAM,CAAC,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AACzC,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAU,CAAC;AAUzE,8EAA8E;AAC9E,SAAS,EAAE,CAAC,KAAc;IACxB,MAAM,IAAI,GACR,KAAK,KAAK,SAAS;QACjB,CAAC,CAAC,OAAO;QACT,CAAC,CAAC,OAAO,KAAK,KAAK,QAAQ;YACzB,CAAC,CAAC,KAAK;YACP,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IACvC,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE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AAC,CAAC;QACvB,CAAC;aAAM,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9C,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACtC,CAAC;IACH,CAAC,CAAC;IACF,KAAK,CAAC,IAAI,CAAC,CAAC;IACZ,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC;AACpB,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,IAAa,EACb,SAAkC,EAClC,IAAgB;IAEhB,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,gBAAgB,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;IAC7E,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,iBAAiB,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC;IAC7F,IAAI,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QACrC,MAAM,GAAG,GAA4B,EAAE,CAAC;QACxC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAA+B,CAAC,EAAE,CAAC;YAC3E,GAAG,CAAC,GAAG,CAAC,GAAG,iBAAiB,CAAC,KAAK,EAAE,SAAS,EAAE,aAAa,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;QAC3E,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { NotifkitApiError } from \"../client.js\";\n\nexport const CHANNELS = [\n \"email\",\n \"sms\",\n \"push\",\n \"webhook\",\n \"in-app\",\n \"telegram\",\n \"discord\",\n \"whatsapp\",\n \"slack\",\n \"teams\",\n] as const;\n// The server accepts contacts on every channel, in-app included.\nexport const CONTACT_CHANNELS = CHANNELS;\nexport const PRIORITIES = [\"low\", \"normal\", \"high\", \"critical\"] as const;\n\ninterface ToolResult {\n // The SDK's tool-result type carries an index signature for protocol\n // extensions; without one here an interface is not assignable to it.\n [key: string]: unknown;\n content: { type: \"text\"; text: string }[];\n isError?: boolean;\n}\n\n/** Render any handler return value as the text payload MCP clients expect. */\nfunction ok(value: unknown): ToolResult {\n const text =\n value === undefined\n ? \"Done.\"\n : typeof value === \"string\"\n ? value\n : JSON.stringify(value, null, 2);\n return { content: [{ type: \"text\", text }] };\n}\n\nfunction fail(error: unknown): ToolResult {\n const text =\n error instanceof NotifkitApiError\n ? `notifkit API error (HTTP ${error.status}): ${error.message}`\n : error instanceof Error\n ? error.message\n : String(error);\n return { content: [{ type: \"text\", text }], isError: true };\n}\n\n/** Wrap a handler so a failed request is reported to the model instead of killing the server. */\nexport function handler<T>(fn: (args: T) => Promise<unknown>) {\n return async (args: T): Promise<ToolResult> => {\n try {\n return ok(await fn(args));\n } catch (error) {\n return fail(error);\n }\n };\n}\n\nfunction escapeHtml(unsafe: string): string {\n return String(unsafe)\n .replace(/&/g, \"&\")\n .replace(/</g, \"<\")\n .replace(/>/g, \">\")\n .replace(/\"/g, \""\")\n .replace(/'/g, \"'\");\n}\n\nfunction escapeHeader(unsafe: string): string {\n return String(unsafe)\n .replace(/[\\r\\n]+/g, \" \")\n .trim();\n}\n\nexport type EscapeMode = \"html\" | \"header\" | \"text\";\nconst HTML_FIELDS = new Set([\"html\", \"htmlbody\", \"bodyhtml\", \"htmlcontent\"]);\nconst HEADER_FIELDS = new Set([\n \"subject\",\n \"title\",\n \"from\",\n \"replyto\",\n \"cc\",\n \"bcc\",\n \"preheader\",\n \"preview\",\n]);\n\nfunction escapeModeFor(key: string, inherited: EscapeMode): EscapeMode {\n const k = key.toLowerCase().replace(/[-_]/g, \"\");\n if (HTML_FIELDS.has(k)) return \"html\";\n if (HEADER_FIELDS.has(k)) return \"header\";\n return inherited;\n}\n\n// Placeholders follow the server's renderer (src/templates/render.ts) so a\n// preview shows what will be sent: `{{{path}}}` (group 1) or `{{path}}`\n// (group 2), a path being a name or a dotted path (`user.name`), with optional\n// whitespace inside the braces.\nconst PLACEHOLDER = /\\{\\{\\{\\s*(\\w+(?:\\.\\w+)*)\\s*\\}\\}\\}|\\{\\{\\s*(\\w+(?:\\.\\w+)*)\\s*\\}\\}/g;\n\n/** The value at a dotted path, reading own properties only; undefined when missing. */\nexport function valueAt(variables: Record<string, unknown>, path: string): unknown {\n let value: unknown = variables;\n for (const segment of path.split(\".\")) {\n if (value === null || typeof value !== \"object\" || !Object.hasOwn(value, segment)) {\n return undefined;\n }\n value = (value as Record<string, unknown>)[segment];\n }\n return value;\n}\n\nfunction lookup(variables: Record<string, unknown>, path: string): string {\n const value = valueAt(variables, path);\n if (value === undefined || value === null) return \"\";\n return typeof value === \"string\" ? value : JSON.stringify(value);\n}\n\nfunction applyEscape(value: string, mode: EscapeMode): string {\n if (mode === \"html\") return escapeHtml(value);\n if (mode === \"header\") return escapeHeader(value);\n return value;\n}\n\n// One pass, so an inserted value is never scanned for placeholders again.\nfunction interpolateValue(\n tmpl: string,\n variables: Record<string, unknown>,\n mode: EscapeMode,\n): string {\n return tmpl.replace(\n PLACEHOLDER,\n (_, rawPath: string | undefined, escapedPath: string | undefined) =>\n rawPath !== undefined\n ? lookup(variables, rawPath)\n : applyEscape(lookup(variables, escapedPath ?? \"\"), mode),\n );\n}\n\n/** Every placeholder path used in the strings of a content tree, once each, in order. */\nexport function placeholderPaths(node: unknown): string[] {\n const paths = new Set<string>();\n const visit = (value: unknown): void => {\n if (typeof value === \"string\") {\n for (const match of value.matchAll(PLACEHOLDER)) paths.add(match[1] ?? match[2] ?? \"\");\n } else if (Array.isArray(value)) {\n value.forEach(visit);\n } else if (value && typeof value === \"object\") {\n Object.values(value).forEach(visit);\n }\n };\n visit(node);\n return [...paths];\n}\n\nexport function renderContentNode(\n node: unknown,\n variables: Record<string, unknown>,\n mode: EscapeMode,\n): unknown {\n if (typeof node === \"string\") return interpolateValue(node, variables, mode);\n if (Array.isArray(node)) return node.map((item) => renderContentNode(item, variables, mode));\n if (node && typeof node === \"object\") {\n const out: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(node as Record<string, unknown>)) {\n out[key] = renderContentNode(value, variables, escapeModeFor(key, mode));\n }\n return out;\n }\n return node;\n}\n"]}
|
package/dist/tools/users.js
CHANGED
|
@@ -30,7 +30,7 @@ export function registerUsersTools(server, api) {
|
|
|
30
30
|
.enum(CONTACT_CHANNELS)
|
|
31
31
|
.optional()
|
|
32
32
|
.describe("Only list users who have a registered contact for this channel " +
|
|
33
|
-
"(email, sms, push, webhook, telegram, discord, whatsapp, slack)."),
|
|
33
|
+
"(email, sms, push, webhook, telegram, discord, whatsapp, slack, teams)."),
|
|
34
34
|
},
|
|
35
35
|
annotations: { title: "List users", readOnlyHint: true },
|
|
36
36
|
}, handler(async (args) => api.get("/v1/users", args)));
|
package/dist/tools/users.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"users.js","sourceRoot":"","sources":["../../src/tools/users.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAElE,MAAM,UAAU,kBAAkB,CAAC,MAAiB,EAAE,GAAgB;IACpE,MAAM,CAAC,YAAY,CACjB,YAAY,EACZ;QACE,KAAK,EAAE,YAAY;QACnB,WAAW,EACT,8FAA8F;YAC9F,uFAAuF;YACvF,8FAA8F;YAC9F,+DAA+D;QACjE,WAAW,EAAE;YACX,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,iBAAiB,CAAC;YAC9E,MAAM,E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AAG,CAAC,KAAK,CAAC,aAAa,kBAAkB,CAAC,MAAM,CAAC,cAAc,EAAE,WAAW,CAAC,CAC9E,CACF,CAAC;AACJ,CAAC","sourcesContent":["import { z } from \"zod\";\nimport type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport type { NotifkitApi } from \"../client.js\";\nimport { CHANNELS, CONTACT_CHANNELS, handler } from \"./shared.js\";\n\nexport function registerUsersTools(server: McpServer, api: NotifkitApi): void {\n server.registerTool(\n \"list_users\",\n {\n title: \"List users\",\n description:\n \"Page through the project's users with comprehensive filtering. Supports filtering by search \" +\n \"keyword (external ID or email), segment tag, language, timezone, or channel contact. \" +\n \"Results are paginated — pass the returned `nextCursor` back as `cursor`. For one known user \" +\n \"prefer get_user, which also returns contacts and preferences.\",\n inputSchema: {\n limit: z.number().int().min(1).max(200).optional().describe(\"Users per page.\"),\n cursor: z\n .string()\n .optional()\n .describe(\"Pagination cursor from a previous call's `nextCursor`.\"),\n search: z\n .string()\n .optional()\n .describe(\"Filter users whose external ID or email contains this search keyword.\"),\n segment: z.string().optional().describe(\"Only list users assigned to this segment tag.\"),\n language: z\n .string()\n .optional()\n .describe(\"Filter users by language tag, e.g. 'en', 'es', 'fr'.\"),\n timezone: z\n .string()\n .optional()\n .describe(\"Filter users by IANA timezone, e.g. 'Europe/London', 'America/New_York'.\"),\n channel: z\n .enum(CONTACT_CHANNELS)\n .optional()\n .describe(\n \"Only list users who have a registered contact for this channel \" +\n \"(email, sms, push, webhook, telegram, discord, whatsapp, slack).\",\n ),\n },\n annotations: { title: \"List users\", readOnlyHint: true },\n },\n handler(async (args) => api.get(\"/v1/users\", args)),\n );\n\n server.registerTool(\n \"get_user\",\n {\n title: \"Get a user\",\n description:\n \"Fetch one user with their contacts, segments, and notification preferences. Call this before \" +\n \"sending to a single user when you need to know which channels they can actually be reached on.\",\n inputSchema: { id: z.string().min(1).describe(\"User id.\") },\n annotations: { title: \"Get a user\", readOnlyHint: true },\n },\n handler(async (args) => api.get(`/v1/users/${encodeURIComponent(args.id)}/details`)),\n );\n\n server.registerTool(\n \"upsert_user\",\n {\n title: \"Create or update a user\",\n description:\n \"Create a user profile, or update an existing one with the same id. Sets contact targets, segment \" +\n \"tags, timezone, and preferences in one call. Segments assigned here are what send_notification's \" +\n \"`segment` targeting matches on. Timezone drives quiet-hours maths, so set it when known.\",\n inputSchema: {\n id: z.string().min(1).describe(\"Your own stable user id, e.g. 'usr_123'.\"),\n contacts: z\n .array(\n z.object({\n channel: z.enum(CHANNELS).describe(\"Contact delivery channel.\"),\n target: z.string().min(1).describe(\"Destination address, phone, token, or URL.\"),\n label: z.string().optional().describe(\"Friendly label for this contact.\"),\n isPrimary: z\n .boolean()\n .optional()\n .describe(\"Whether this is the primary contact for this channel.\"),\n }),\n )\n .optional()\n .describe(\n \"Array of user contacts across any supported channels (preferred over legacy email/phone/pushToken).\",\n ),\n email: z\n .union([z.string().min(1), z.array(z.string().min(1))])\n .optional()\n .describe(\"One email address or several.\"),\n phone: z\n .union([z.string().min(1), z.array(z.string().min(1))])\n .optional()\n .describe(\"One phone number or several, in E.164 form.\"),\n pushToken: z\n .union([z.string().min(1), z.array(z.string().min(1))])\n .optional()\n .describe(\"One device push token or several.\"),\n segments: z\n .array(z.string().min(1))\n .optional()\n .describe(\"Segment tags to assign to this user.\"),\n language: z\n .string()\n .optional()\n .describe(\"BCP 47 language tag used to pick localised content.\"),\n timezone: z\n .string()\n .optional()\n .describe(\"IANA timezone, e.g. 'Europe/London'. Drives quiet hours.\"),\n preferences: z\n .object({\n channels: z\n .record(z.string(), z.boolean())\n .optional()\n .describe(\"Per-channel opt-in map, e.g. { email: true, sms: false }.\"),\n topics: z.record(z.string(), z.boolean()).optional().describe(\"Per-topic opt-in map.\"),\n quietHours: z\n .array(\n z.object({\n start: z.string().describe(\"HH:MM, 24h, in the user's timezone.\"),\n end: z.string().describe(\"HH:MM, 24h, in the user's timezone.\"),\n }),\n )\n .optional()\n .describe(\"Windows during which non-critical sends are deferred.\"),\n })\n .optional()\n .describe(\"Consent and quiet-hours settings.\"),\n },\n annotations: { title: \"Create or update a user\", readOnlyHint: false, idempotentHint: true },\n },\n handler(async (args) => api.post(\"/v1/users\", args)),\n );\n\n server.registerTool(\n \"update_user\",\n {\n title: \"Update a user\",\n description:\n \"Partially update an existing user profile (e.g. language, timezone, segment tags, preferences, or append new contacts) without replacing unspecified fields.\",\n inputSchema: {\n id: z.string().min(1).describe(\"User id.\"),\n contacts: z\n .array(\n z.object({\n channel: z.enum(CHANNELS).describe(\"Contact delivery channel.\"),\n target: z.string().min(1).describe(\"Destination address, phone, token, or URL.\"),\n label: z.string().optional().describe(\"Friendly label for this contact.\"),\n isPrimary: z\n .boolean()\n .optional()\n .describe(\"Whether this is the primary contact for this channel.\"),\n }),\n )\n .optional()\n .describe(\"Array of user contacts across any supported channels to append or update.\"),\n email: z\n .union([z.string().min(1), z.array(z.string().min(1))])\n .optional()\n .describe(\"One email address or several.\"),\n phone: z\n .union([z.string().min(1), z.array(z.string().min(1))])\n .optional()\n .describe(\"One phone number or several, in E.164 form.\"),\n pushToken: z\n .union([z.string().min(1), z.array(z.string().min(1))])\n .optional()\n .describe(\"One device push token or several.\"),\n segments: z\n .array(z.string().min(1))\n .optional()\n .describe(\"Segment tags to assign to this user.\"),\n language: z\n .string()\n .optional()\n .describe(\"BCP 47 language tag used to pick localised content.\"),\n timezone: z\n .string()\n .optional()\n .describe(\"IANA timezone, e.g. 'Europe/London'. Drives quiet hours.\"),\n preferences: z\n .object({\n channels: z\n .record(z.string(), z.boolean())\n .optional()\n .describe(\"Per-channel opt-in map, e.g. { email: true, sms: false }.\"),\n topics: z.record(z.string(), z.boolean()).optional().describe(\"Per-topic opt-in map.\"),\n quietHours: z\n .array(\n z.object({\n start: z.string().describe(\"HH:MM, 24h, in the user's timezone.\"),\n end: z.string().describe(\"HH:MM, 24h, in the user's timezone.\"),\n }),\n )\n .optional()\n .describe(\"Windows during which non-critical sends are deferred.\"),\n })\n .optional()\n .describe(\"Consent and quiet-hours settings.\"),\n },\n annotations: { title: \"Update a user\", readOnlyHint: false, idempotentHint: true },\n },\n handler(async ({ id, ...body }) => api.patch(`/v1/users/${encodeURIComponent(id)}`, body)),\n );\n\n server.registerTool(\n \"delete_user\",\n {\n title: \"Delete a user\",\n description:\n \"Permanently delete a user profile and all associated contacts and preferences by user id.\",\n inputSchema: {\n id: z.string().min(1).describe(\"User id to delete.\"),\n },\n annotations: {\n title: \"Delete a user\",\n readOnlyHint: false,\n destructiveHint: true,\n idempotentHint: true,\n },\n },\n handler(async (args) => {\n await api.delete(`/v1/users/${encodeURIComponent(args.id)}`);\n return `Deleted user ${args.id}.`;\n }),\n );\n\n server.registerTool(\n \"get_user_contacts\",\n {\n title: \"Get user contacts\",\n description: \"Fetch all registered contact addresses and tokens for a specific user.\",\n inputSchema: {\n userId: z.string().min(1).describe(\"User id.\"),\n },\n annotations: { title: \"Get user contacts\", readOnlyHint: true },\n },\n handler(async (args) => api.get(`/v1/users/${encodeURIComponent(args.userId)}/contacts`)),\n );\n\n server.registerTool(\n \"add_user_contact\",\n {\n title: \"Add a contact to a user\",\n description:\n \"Add one addressable target (email address, phone number, push token, or webhook URL) to an \" +\n \"existing user without replacing their other contacts. Prefer this over upsert_user when adding a \" +\n \"second device or address to someone who already exists.\",\n inputSchema: {\n userId: z.string().min(1).describe(\"Id of the user to add the contact to.\"),\n channel: z.enum(CONTACT_CHANNELS).describe(\"Channel this target belongs to.\"),\n target: z.string().min(1).describe(\"The address itself: email, phone, push token, or URL.\"),\n },\n annotations: { title: \"Add a contact to a user\", readOnlyHint: false },\n },\n handler(async ({ userId, ...body }) =>\n api.post(`/v1/users/${encodeURIComponent(userId)}/contacts`, body),\n ),\n );\n\n server.registerTool(\n \"delete_user_contact\",\n {\n title: \"Delete a user contact\",\n description:\n \"Remove one contact destination (email, phone, push token, or webhook URL) from a user profile.\",\n inputSchema: {\n userId: z.string().min(1).describe(\"User id.\"),\n channel: z.enum(CONTACT_CHANNELS).describe(\"Channel of the contact to delete.\"),\n target: z.string().min(1).describe(\"The address/number/token/URL to remove.\"),\n },\n annotations: {\n title: \"Delete a user contact\",\n readOnlyHint: false,\n destructiveHint: true,\n idempotentHint: true,\n },\n },\n handler(async (args) => {\n await api.delete(\n `/v1/users/${encodeURIComponent(args.userId)}/contacts/${encodeURIComponent(args.channel)}/${encodeURIComponent(args.target)}`,\n );\n return `Deleted ${args.channel} contact '${args.target}' for user ${args.userId}.`;\n }),\n );\n\n server.registerTool(\n \"get_user_preferences\",\n {\n title: \"Get user preferences\",\n description:\n \"Fetch notification channel/topic opt-in preferences and quiet hours for a user.\",\n inputSchema: {\n userId: z.string().min(1).describe(\"User id.\"),\n },\n annotations: { title: \"Get user preferences\", readOnlyHint: true },\n },\n handler(async (args) => api.get(`/v1/users/${encodeURIComponent(args.userId)}/preferences`)),\n );\n\n server.registerTool(\n \"update_user_preferences\",\n {\n title: \"Update user preferences\",\n description: \"Update notification channel/topic opt-ins and quiet hours settings for a user.\",\n inputSchema: {\n userId: z.string().min(1).describe(\"User id.\"),\n channels: z\n .record(z.string(), z.boolean())\n .optional()\n .describe(\"Per-channel opt-in map, e.g. { email: true, sms: false }.\"),\n topics: z.record(z.string(), z.boolean()).optional().describe(\"Per-topic opt-in map.\"),\n quietHours: z\n .array(\n z.object({\n start: z.string().describe(\"HH:MM, 24h, in the user's timezone.\"),\n end: z.string().describe(\"HH:MM, 24h, in the user's timezone.\"),\n }),\n )\n .optional()\n .describe(\"Windows during which non-critical sends are deferred.\"),\n },\n annotations: { title: \"Update user preferences\", readOnlyHint: false, idempotentHint: true },\n },\n handler(async ({ userId, ...preferences }) =>\n api.patch(`/v1/users/${encodeURIComponent(userId)}/preferences`, preferences),\n ),\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"users.js","sourceRoot":"","sources":["../../src/tools/users.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,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AK,CACJ,CAAC,CAAC,MAAM,CAAC;gBACP,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,qCAAqC,CAAC;gBACjE,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,qCAAqC,CAAC;aAChE,CAAC,CACH;iBACA,QAAQ,EAAE;iBACV,QAAQ,CAAC,uDAAuD,CAAC;SACrE;QACD,WAAW,EAAE,EAAE,KAAK,EAAE,yBAAyB,EAAE,YAAY,EAAE,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE;KAC7F,EACD,OAAO,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,GAAG,WAAW,EAAE,EAAE,EAAE,CAC3C,GAAG,CAAC,KAAK,CAAC,aAAa,kBAAkB,CAAC,MAAM,CAAC,cAAc,EAAE,WAAW,CAAC,CAC9E,CACF,CAAC;AACJ,CAAC","sourcesContent":["import { z } from \"zod\";\nimport type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport type { NotifkitApi } from \"../client.js\";\nimport { CHANNELS, CONTACT_CHANNELS, handler } from \"./shared.js\";\n\nexport function registerUsersTools(server: McpServer, api: NotifkitApi): void {\n server.registerTool(\n \"list_users\",\n {\n title: \"List users\",\n description:\n \"Page through the project's users with comprehensive filtering. Supports filtering by search \" +\n \"keyword (external ID or email), segment tag, language, timezone, or channel contact. \" +\n \"Results are paginated — pass the returned `nextCursor` back as `cursor`. For one known user \" +\n \"prefer get_user, which also returns contacts and preferences.\",\n inputSchema: {\n limit: z.number().int().min(1).max(200).optional().describe(\"Users per page.\"),\n cursor: z\n .string()\n .optional()\n .describe(\"Pagination cursor from a previous call's `nextCursor`.\"),\n search: z\n .string()\n .optional()\n .describe(\"Filter users whose external ID or email contains this search keyword.\"),\n segment: z.string().optional().describe(\"Only list users assigned to this segment tag.\"),\n language: z\n .string()\n .optional()\n .describe(\"Filter users by language tag, e.g. 'en', 'es', 'fr'.\"),\n timezone: z\n .string()\n .optional()\n .describe(\"Filter users by IANA timezone, e.g. 'Europe/London', 'America/New_York'.\"),\n channel: z\n .enum(CONTACT_CHANNELS)\n .optional()\n .describe(\n \"Only list users who have a registered contact for this channel \" +\n \"(email, sms, push, webhook, telegram, discord, whatsapp, slack, teams).\",\n ),\n },\n annotations: { title: \"List users\", readOnlyHint: true },\n },\n handler(async (args) => api.get(\"/v1/users\", args)),\n );\n\n server.registerTool(\n \"get_user\",\n {\n title: \"Get a user\",\n description:\n \"Fetch one user with their contacts, segments, and notification preferences. Call this before \" +\n \"sending to a single user when you need to know which channels they can actually be reached on.\",\n inputSchema: { id: z.string().min(1).describe(\"User id.\") },\n annotations: { title: \"Get a user\", readOnlyHint: true },\n },\n handler(async (args) => api.get(`/v1/users/${encodeURIComponent(args.id)}/details`)),\n );\n\n server.registerTool(\n \"upsert_user\",\n {\n title: \"Create or update a user\",\n description:\n \"Create a user profile, or update an existing one with the same id. Sets contact targets, segment \" +\n \"tags, timezone, and preferences in one call. Segments assigned here are what send_notification's \" +\n \"`segment` targeting matches on. Timezone drives quiet-hours maths, so set it when known.\",\n inputSchema: {\n id: z.string().min(1).describe(\"Your own stable user id, e.g. 'usr_123'.\"),\n contacts: z\n .array(\n z.object({\n channel: z.enum(CHANNELS).describe(\"Contact delivery channel.\"),\n target: z.string().min(1).describe(\"Destination address, phone, token, or URL.\"),\n label: z.string().optional().describe(\"Friendly label for this contact.\"),\n isPrimary: z\n .boolean()\n .optional()\n .describe(\"Whether this is the primary contact for this channel.\"),\n }),\n )\n .optional()\n .describe(\n \"Array of user contacts across any supported channels (preferred over legacy email/phone/pushToken).\",\n ),\n email: z\n .union([z.string().min(1), z.array(z.string().min(1))])\n .optional()\n .describe(\"One email address or several.\"),\n phone: z\n .union([z.string().min(1), z.array(z.string().min(1))])\n .optional()\n .describe(\"One phone number or several, in E.164 form.\"),\n pushToken: z\n .union([z.string().min(1), z.array(z.string().min(1))])\n .optional()\n .describe(\"One device push token or several.\"),\n segments: z\n .array(z.string().min(1))\n .optional()\n .describe(\"Segment tags to assign to this user.\"),\n language: z\n .string()\n .optional()\n .describe(\"BCP 47 language tag used to pick localised content.\"),\n timezone: z\n .string()\n .optional()\n .describe(\"IANA timezone, e.g. 'Europe/London'. Drives quiet hours.\"),\n preferences: z\n .object({\n channels: z\n .record(z.string(), z.boolean())\n .optional()\n .describe(\"Per-channel opt-in map, e.g. { email: true, sms: false }.\"),\n topics: z.record(z.string(), z.boolean()).optional().describe(\"Per-topic opt-in map.\"),\n quietHours: z\n .array(\n z.object({\n start: z.string().describe(\"HH:MM, 24h, in the user's timezone.\"),\n end: z.string().describe(\"HH:MM, 24h, in the user's timezone.\"),\n }),\n )\n .optional()\n .describe(\"Windows during which non-critical sends are deferred.\"),\n })\n .optional()\n .describe(\"Consent and quiet-hours settings.\"),\n },\n annotations: { title: \"Create or update a user\", readOnlyHint: false, idempotentHint: true },\n },\n handler(async (args) => api.post(\"/v1/users\", args)),\n );\n\n server.registerTool(\n \"update_user\",\n {\n title: \"Update a user\",\n description:\n \"Partially update an existing user profile (e.g. language, timezone, segment tags, preferences, or append new contacts) without replacing unspecified fields.\",\n inputSchema: {\n id: z.string().min(1).describe(\"User id.\"),\n contacts: z\n .array(\n z.object({\n channel: z.enum(CHANNELS).describe(\"Contact delivery channel.\"),\n target: z.string().min(1).describe(\"Destination address, phone, token, or URL.\"),\n label: z.string().optional().describe(\"Friendly label for this contact.\"),\n isPrimary: z\n .boolean()\n .optional()\n .describe(\"Whether this is the primary contact for this channel.\"),\n }),\n )\n .optional()\n .describe(\"Array of user contacts across any supported channels to append or update.\"),\n email: z\n .union([z.string().min(1), z.array(z.string().min(1))])\n .optional()\n .describe(\"One email address or several.\"),\n phone: z\n .union([z.string().min(1), z.array(z.string().min(1))])\n .optional()\n .describe(\"One phone number or several, in E.164 form.\"),\n pushToken: z\n .union([z.string().min(1), z.array(z.string().min(1))])\n .optional()\n .describe(\"One device push token or several.\"),\n segments: z\n .array(z.string().min(1))\n .optional()\n .describe(\"Segment tags to assign to this user.\"),\n language: z\n .string()\n .optional()\n .describe(\"BCP 47 language tag used to pick localised content.\"),\n timezone: z\n .string()\n .optional()\n .describe(\"IANA timezone, e.g. 'Europe/London'. Drives quiet hours.\"),\n preferences: z\n .object({\n channels: z\n .record(z.string(), z.boolean())\n .optional()\n .describe(\"Per-channel opt-in map, e.g. { email: true, sms: false }.\"),\n topics: z.record(z.string(), z.boolean()).optional().describe(\"Per-topic opt-in map.\"),\n quietHours: z\n .array(\n z.object({\n start: z.string().describe(\"HH:MM, 24h, in the user's timezone.\"),\n end: z.string().describe(\"HH:MM, 24h, in the user's timezone.\"),\n }),\n )\n .optional()\n .describe(\"Windows during which non-critical sends are deferred.\"),\n })\n .optional()\n .describe(\"Consent and quiet-hours settings.\"),\n },\n annotations: { title: \"Update a user\", readOnlyHint: false, idempotentHint: true },\n },\n handler(async ({ id, ...body }) => api.patch(`/v1/users/${encodeURIComponent(id)}`, body)),\n );\n\n server.registerTool(\n \"delete_user\",\n {\n title: \"Delete a user\",\n description:\n \"Permanently delete a user profile and all associated contacts and preferences by user id.\",\n inputSchema: {\n id: z.string().min(1).describe(\"User id to delete.\"),\n },\n annotations: {\n title: \"Delete a user\",\n readOnlyHint: false,\n destructiveHint: true,\n idempotentHint: true,\n },\n },\n handler(async (args) => {\n await api.delete(`/v1/users/${encodeURIComponent(args.id)}`);\n return `Deleted user ${args.id}.`;\n }),\n );\n\n server.registerTool(\n \"get_user_contacts\",\n {\n title: \"Get user contacts\",\n description: \"Fetch all registered contact addresses and tokens for a specific user.\",\n inputSchema: {\n userId: z.string().min(1).describe(\"User id.\"),\n },\n annotations: { title: \"Get user contacts\", readOnlyHint: true },\n },\n handler(async (args) => api.get(`/v1/users/${encodeURIComponent(args.userId)}/contacts`)),\n );\n\n server.registerTool(\n \"add_user_contact\",\n {\n title: \"Add a contact to a user\",\n description:\n \"Add one addressable target (email address, phone number, push token, or webhook URL) to an \" +\n \"existing user without replacing their other contacts. Prefer this over upsert_user when adding a \" +\n \"second device or address to someone who already exists.\",\n inputSchema: {\n userId: z.string().min(1).describe(\"Id of the user to add the contact to.\"),\n channel: z.enum(CONTACT_CHANNELS).describe(\"Channel this target belongs to.\"),\n target: z.string().min(1).describe(\"The address itself: email, phone, push token, or URL.\"),\n },\n annotations: { title: \"Add a contact to a user\", readOnlyHint: false },\n },\n handler(async ({ userId, ...body }) =>\n api.post(`/v1/users/${encodeURIComponent(userId)}/contacts`, body),\n ),\n );\n\n server.registerTool(\n \"delete_user_contact\",\n {\n title: \"Delete a user contact\",\n description:\n \"Remove one contact destination (email, phone, push token, or webhook URL) from a user profile.\",\n inputSchema: {\n userId: z.string().min(1).describe(\"User id.\"),\n channel: z.enum(CONTACT_CHANNELS).describe(\"Channel of the contact to delete.\"),\n target: z.string().min(1).describe(\"The address/number/token/URL to remove.\"),\n },\n annotations: {\n title: \"Delete a user contact\",\n readOnlyHint: false,\n destructiveHint: true,\n idempotentHint: true,\n },\n },\n handler(async (args) => {\n await api.delete(\n `/v1/users/${encodeURIComponent(args.userId)}/contacts/${encodeURIComponent(args.channel)}/${encodeURIComponent(args.target)}`,\n );\n return `Deleted ${args.channel} contact '${args.target}' for user ${args.userId}.`;\n }),\n );\n\n server.registerTool(\n \"get_user_preferences\",\n {\n title: \"Get user preferences\",\n description:\n \"Fetch notification channel/topic opt-in preferences and quiet hours for a user.\",\n inputSchema: {\n userId: z.string().min(1).describe(\"User id.\"),\n },\n annotations: { title: \"Get user preferences\", readOnlyHint: true },\n },\n handler(async (args) => api.get(`/v1/users/${encodeURIComponent(args.userId)}/preferences`)),\n );\n\n server.registerTool(\n \"update_user_preferences\",\n {\n title: \"Update user preferences\",\n description: \"Update notification channel/topic opt-ins and quiet hours settings for a user.\",\n inputSchema: {\n userId: z.string().min(1).describe(\"User id.\"),\n channels: z\n .record(z.string(), z.boolean())\n .optional()\n .describe(\"Per-channel opt-in map, e.g. { email: true, sms: false }.\"),\n topics: z.record(z.string(), z.boolean()).optional().describe(\"Per-topic opt-in map.\"),\n quietHours: z\n .array(\n z.object({\n start: z.string().describe(\"HH:MM, 24h, in the user's timezone.\"),\n end: z.string().describe(\"HH:MM, 24h, in the user's timezone.\"),\n }),\n )\n .optional()\n .describe(\"Windows during which non-critical sends are deferred.\"),\n },\n annotations: { title: \"Update user preferences\", readOnlyHint: false, idempotentHint: true },\n },\n handler(async ({ userId, ...preferences }) =>\n api.patch(`/v1/users/${encodeURIComponent(userId)}/preferences`, preferences),\n ),\n );\n}\n"]}
|
package/package.json
CHANGED
package/src/tools/sending.ts
CHANGED
|
@@ -91,10 +91,10 @@ export function registerSendingTools(server: McpServer, api: NotifkitApi): void
|
|
|
91
91
|
title: "Send a campaign to a list of addresses",
|
|
92
92
|
description:
|
|
93
93
|
"Send one template to a list of recipient destinations (email, SMS/phone, push tokens, webhook URLs, " +
|
|
94
|
-
"Telegram chat ids, Discord webhook URLs, WhatsApp phone numbers,
|
|
94
|
+
"Telegram chat ids, Discord webhook URLs, WhatsApp phone numbers, Slack channel/user IDs/webhook URLs, or Teams Workflows webhook URLs) given directly — the tool creates or updates a user " +
|
|
95
95
|
"record for each address, then sends, and tags every message with a campaign label so the results " +
|
|
96
96
|
"can be read back later with get_campaign_stats. Supports 'email', 'sms', 'push', 'webhook', " +
|
|
97
|
-
"'telegram', 'discord', 'whatsapp', and '
|
|
97
|
+
"'telegram', 'discord', 'whatsapp', 'slack', and 'teams' channels. Use this when the person supplies the recipients themselves " +
|
|
98
98
|
"(a pasted list, a spreadsheet column). Always report the returned campaign label back to the user " +
|
|
99
99
|
"— it is how they ask about results later. Suppressed addresses (previous unsubscribes, complaints, " +
|
|
100
100
|
"hard bounces) are dropped automatically at send time, so the delivered count is normally lower than " +
|
|
@@ -113,7 +113,7 @@ export function registerSendingTools(server: McpServer, api: NotifkitApi): void
|
|
|
113
113
|
.enum(CONTACT_CHANNELS)
|
|
114
114
|
.optional()
|
|
115
115
|
.describe(
|
|
116
|
-
"Channel to send on ('email', 'sms', 'push', 'webhook', 'telegram', 'discord', 'whatsapp', or '
|
|
116
|
+
"Channel to send on ('email', 'sms', 'push', 'webhook', 'telegram', 'discord', 'whatsapp', 'slack', or 'teams'). Defaults to 'email'.",
|
|
117
117
|
),
|
|
118
118
|
recipients: z
|
|
119
119
|
.array(z.string().min(1))
|
|
@@ -122,7 +122,7 @@ export function registerSendingTools(server: McpServer, api: NotifkitApi): void
|
|
|
122
122
|
.optional()
|
|
123
123
|
.describe(
|
|
124
124
|
"Recipient destination addresses: email addresses for email, E.164 phone numbers for sms/whatsapp, " +
|
|
125
|
-
"device tokens for push, URLs for webhook, chat ids for telegram, webhook URLs for discord,
|
|
125
|
+
"device tokens for push, URLs for webhook, chat ids for telegram, webhook URLs for discord, channel/user IDs for slack, or Workflows webhook URLs for teams.",
|
|
126
126
|
),
|
|
127
127
|
emails: z
|
|
128
128
|
.array(z.string().email())
|
package/src/tools/shared.ts
CHANGED
package/src/tools/users.ts
CHANGED
|
@@ -37,7 +37,7 @@ export function registerUsersTools(server: McpServer, api: NotifkitApi): void {
|
|
|
37
37
|
.optional()
|
|
38
38
|
.describe(
|
|
39
39
|
"Only list users who have a registered contact for this channel " +
|
|
40
|
-
"(email, sms, push, webhook, telegram, discord, whatsapp, slack).",
|
|
40
|
+
"(email, sms, push, webhook, telegram, discord, whatsapp, slack, teams).",
|
|
41
41
|
),
|
|
42
42
|
},
|
|
43
43
|
annotations: { title: "List users", readOnlyHint: true },
|