@notifkit/mcp 0.1.6 → 0.1.7
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflows.d.ts","sourceRoot":"","sources":["../../src/tools/workflows.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGhD,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,WAAW,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"workflows.d.ts","sourceRoot":"","sources":["../../src/tools/workflows.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGhD,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,WAAW,GAAG,IAAI,CAiKhF"}
|
package/dist/tools/workflows.js
CHANGED
|
@@ -27,7 +27,14 @@ export function registerWorkflowsTools(server, api) {
|
|
|
27
27
|
action: z.literal("waitForEvent"),
|
|
28
28
|
event: z.string().describe("Event name to wait for, as passed to ingest_event."),
|
|
29
29
|
options: z
|
|
30
|
-
.object({
|
|
30
|
+
.object({
|
|
31
|
+
timeout: z.string().optional().describe("e.g. '24h'."),
|
|
32
|
+
match: z
|
|
33
|
+
.record(z.string(), z.unknown())
|
|
34
|
+
.optional()
|
|
35
|
+
.describe("Fields the event must carry to wake this instance, e.g. { userId: 'u1' }. " +
|
|
36
|
+
"Without it any event of that name wakes every waiting instance."),
|
|
37
|
+
})
|
|
31
38
|
.optional()
|
|
32
39
|
.describe("Give a timeout so the instance cannot wait forever."),
|
|
33
40
|
}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"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C,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,iCAAiC,CAAC,EAAE;QAC1F,WAAW,EAAE;YACX,KAAK,EAAE,uBAAuB;YAC9B,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,2BAA2B,kBAAkB,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;QAC9F,OAAO,+BAA+B,IAAI,CAAC,UAAU,GAAG,CAAC;IAC3D,CAAC,CAAC,CACH,CAAC;IAEF,MAAM,CAAC,YAAY,CACjB,cAAc,EACd;QACE,KAAK,EAAE,iBAAiB;QACxB,WAAW,EACT,0FAA0F;YAC1F,kGAAkG;YAClG,gEAAgE;QAClE,WAAW,EAAE;YACX,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,sDAAsD,CAAC;YACxF,UAAU,EAAE,CAAC;iBACV,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;iBAC/B,QAAQ,CAAC,wDAAwD,CAAC;SACtE;QACD,WAAW,EAAE,EAAE,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE;KACtF,EACD,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC,CACtD,CAAC;AACJ,CAAC","sourcesContent":["import { z } from \"zod\";\nimport type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport type { NotifkitApi } from \"../client.js\";\nimport { handler } from \"./shared.js\";\n\nexport function registerWorkflowsTools(server: McpServer, api: NotifkitApi): void {\n server.registerTool(\n \"create_workflow\",\n {\n title: \"Create a workflow\",\n description:\n \"Define a named multi-step sequence — the way to build a drip, an onboarding series, or a reminder \" +\n \"chain rather than a single send. Steps run in order and are one of: `notify` (send, using the \" +\n \"same fields as send_notification), `wait` (pause for a duration like '1h' or '3d'), or \" +\n \"`waitForEvent` (block until ingest_event reports a named event, with an optional timeout). A \" +\n \"notify step with no target inherits the user the instance was triggered for. Creating a workflow \" +\n \"does not run it — call trigger_workflow per user.\",\n inputSchema: {\n name: z.string().min(1).describe(\"Workflow name, used later by trigger_workflow.\"),\n steps: z\n .array(\n z.union([\n z.object({\n action: z.literal(\"notify\"),\n payload: z\n .record(z.string(), z.unknown())\n .describe(\n \"Same shape as send_notification's arguments. Omit the target to use the instance's own user.\",\n ),\n }),\n z.object({\n action: z.literal(\"wait\"),\n duration: z.string().describe(\"Duration string, e.g. '5m', '1h', '3d'.\"),\n }),\n z.object({\n action: z.literal(\"waitForEvent\"),\n event: z.string().describe(\"Event name to wait for, as passed to ingest_event.\"),\n options: z\n .object({ timeout: z.string().optional().describe(\"e.g. '24h'.\") })\n .optional()\n .describe(\"Give a timeout so the instance cannot wait forever.\"),\n }),\n ]),\n )\n .min(1)\n .describe(\"Ordered steps.\"),\n },\n annotations: { title: \"Create a workflow\", readOnlyHint: false, idempotentHint: true },\n },\n handler(async (args) => api.post(\"/v1/workflows\", args)),\n );\n\n server.registerTool(\n \"list_workflows\",\n {\n title: \"List workflows\",\n description:\n \"List registered workflow definitions and their steps. Call this to find the name to pass to \" +\n \"trigger_workflow, or to check a sequence before triggering it. Supports filtering by search keyword.\",\n inputSchema: {\n limit: z\n .number()\n .int()\n .min(1)\n .max(100)\n .optional()\n .describe(\"Maximum number of workflow definitions to return.\"),\n search: z\n .string()\n .optional()\n .describe(\"Filter workflow definitions whose name contains this search keyword.\"),\n },\n annotations: { title: \"List workflows\", readOnlyHint: true },\n },\n handler(async (args) => api.get(\"/v1/workflows\", args)),\n );\n\n server.registerTool(\n \"trigger_workflow\",\n {\n title: \"Trigger a workflow\",\n description:\n \"Start one run of a registered workflow, optionally for a specific user, and return the instance \" +\n \"id. Each call starts an independent instance, so triggering the same workflow twice for one user \" +\n \"enrols them twice. Track the returned instance with get_workflow_run.\",\n inputSchema: {\n name: z.string().min(1).describe(\"Name of the workflow to run.\"),\n user: z\n .string()\n .min(1)\n .optional()\n .describe(\"User id this run is for. Notify steps default to them.\"),\n input: z\n .record(z.string(), z.unknown())\n .optional()\n .describe(\"Data made available to the run's steps.\"),\n },\n annotations: { title: \"Trigger a workflow\", readOnlyHint: false, idempotentHint: false },\n },\n handler(async (args) => api.post(\"/v1/workflows/trigger\", args)),\n );\n\n server.registerTool(\n \"get_workflow_run\",\n {\n title: \"Get a workflow run\",\n description:\n \"Fetch one workflow instance by id: which step it is on, its status, and what it is waiting for. \" +\n \"Use this to check on a run started by trigger_workflow.\",\n inputSchema: { instanceId: z.string().min(1).describe(\"Workflow instance id.\") },\n annotations: { title: \"Get a workflow run\", readOnlyHint: true },\n },\n handler(async (args) =>\n api.get(`/v1/workflows/instances/${encodeURIComponent(args.instanceId)}`),\n ),\n );\n\n server.registerTool(\n \"cancel_workflow_run\",\n {\n title: \"Cancel a workflow run\",\n description:\n \"Stop a running or suspended workflow instance so its remaining steps never fire. This does not \" +\n \"recall notifications already sent, and it cannot be undone — confirm with the user before \" +\n \"cancelling a run you did not start in this session.\",\n inputSchema: { instanceId: z.string().min(1).describe(\"Workflow instance id to cancel.\") },\n annotations: {\n title: \"Cancel a workflow run\",\n readOnlyHint: false,\n destructiveHint: true,\n idempotentHint: true,\n },\n },\n handler(async (args) => {\n await api.request(\"DELETE\", `/v1/workflows/instances/${encodeURIComponent(args.instanceId)}`);\n return `Cancelled workflow instance ${args.instanceId}.`;\n }),\n );\n\n server.registerTool(\n \"ingest_event\",\n {\n title: \"Ingest an event\",\n description:\n \"Report that something happened in your product. Workflow instances parked on a matching \" +\n \"`waitForEvent` step resume. Call this to unblock a waiting sequence, e.g. emitting 'order.paid' \" +\n \"so an abandoned-cart workflow stops before its reminder fires.\",\n inputSchema: {\n name: z.string().min(1).describe(\"Event name, matching a workflow's waitForEvent step.\"),\n properties: z\n .record(z.string(), z.unknown())\n .describe(\"Event payload. Include the user id the event is about.\"),\n },\n annotations: { title: \"Ingest an event\", readOnlyHint: false, idempotentHint: false },\n },\n handler(async (args) => api.post(\"/v1/events\", args)),\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"workflows.js","sourceRoot":"","sources":["../../src/tools/workflows.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC,MAAM,UAAU,sBAAsB,CAAC,MAAiB,EAAE,GAAgB;IACxE,MAAM,CAAC,YAAY,CACjB,iBAAiB,EACjB;QACE,KAAK,EAAE,mBAAmB;QAC1B,WAAW,EACT,oGAAoG;YACpG,gGAAgG;YAChG,yFAAyF;YACzF,+FAA+F;YAC/F,mGAAmG;YACnG,mDAAmD;QACrD,WAAW,EAAE;YACX,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,gDAAgD,CAAC;YAClF,KAAK,EAAE,CAAC;iBACL,KAAK,CACJ,CAAC,CAAC,KAAK,CAAC;gBACN,CAAC,CAAC,MAAM,CAAC;oBACP,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC;oBAC3B,OAAO,EAAE,CAAC;yBACP,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;yBAC/B,QAAQ,CACP,8FAA8F,CAC/F;iBACJ,CAAC;gBACF,CAAC,CAAC,MAAM,CAAC;oBACP,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC;oBACzB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,yC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AAC;iBAC/B,QAAQ,CAAC,wDAAwD,CAAC;SACtE;QACD,WAAW,EAAE,EAAE,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE;KACtF,EACD,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC,CACtD,CAAC;AACJ,CAAC","sourcesContent":["import { z } from \"zod\";\nimport type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport type { NotifkitApi } from \"../client.js\";\nimport { handler } from \"./shared.js\";\n\nexport function registerWorkflowsTools(server: McpServer, api: NotifkitApi): void {\n server.registerTool(\n \"create_workflow\",\n {\n title: \"Create a workflow\",\n description:\n \"Define a named multi-step sequence — the way to build a drip, an onboarding series, or a reminder \" +\n \"chain rather than a single send. Steps run in order and are one of: `notify` (send, using the \" +\n \"same fields as send_notification), `wait` (pause for a duration like '1h' or '3d'), or \" +\n \"`waitForEvent` (block until ingest_event reports a named event, with an optional timeout). A \" +\n \"notify step with no target inherits the user the instance was triggered for. Creating a workflow \" +\n \"does not run it — call trigger_workflow per user.\",\n inputSchema: {\n name: z.string().min(1).describe(\"Workflow name, used later by trigger_workflow.\"),\n steps: z\n .array(\n z.union([\n z.object({\n action: z.literal(\"notify\"),\n payload: z\n .record(z.string(), z.unknown())\n .describe(\n \"Same shape as send_notification's arguments. Omit the target to use the instance's own user.\",\n ),\n }),\n z.object({\n action: z.literal(\"wait\"),\n duration: z.string().describe(\"Duration string, e.g. '5m', '1h', '3d'.\"),\n }),\n z.object({\n action: z.literal(\"waitForEvent\"),\n event: z.string().describe(\"Event name to wait for, as passed to ingest_event.\"),\n options: z\n .object({\n timeout: z.string().optional().describe(\"e.g. '24h'.\"),\n match: z\n .record(z.string(), z.unknown())\n .optional()\n .describe(\n \"Fields the event must carry to wake this instance, e.g. { userId: 'u1' }. \" +\n \"Without it any event of that name wakes every waiting instance.\",\n ),\n })\n .optional()\n .describe(\"Give a timeout so the instance cannot wait forever.\"),\n }),\n ]),\n )\n .min(1)\n .describe(\"Ordered steps.\"),\n },\n annotations: { title: \"Create a workflow\", readOnlyHint: false, idempotentHint: true },\n },\n handler(async (args) => api.post(\"/v1/workflows\", args)),\n );\n\n server.registerTool(\n \"list_workflows\",\n {\n title: \"List workflows\",\n description:\n \"List registered workflow definitions and their steps. Call this to find the name to pass to \" +\n \"trigger_workflow, or to check a sequence before triggering it. Supports filtering by search keyword.\",\n inputSchema: {\n limit: z\n .number()\n .int()\n .min(1)\n .max(100)\n .optional()\n .describe(\"Maximum number of workflow definitions to return.\"),\n search: z\n .string()\n .optional()\n .describe(\"Filter workflow definitions whose name contains this search keyword.\"),\n },\n annotations: { title: \"List workflows\", readOnlyHint: true },\n },\n handler(async (args) => api.get(\"/v1/workflows\", args)),\n );\n\n server.registerTool(\n \"trigger_workflow\",\n {\n title: \"Trigger a workflow\",\n description:\n \"Start one run of a registered workflow, optionally for a specific user, and return the instance \" +\n \"id. Each call starts an independent instance, so triggering the same workflow twice for one user \" +\n \"enrols them twice. Track the returned instance with get_workflow_run.\",\n inputSchema: {\n name: z.string().min(1).describe(\"Name of the workflow to run.\"),\n user: z\n .string()\n .min(1)\n .optional()\n .describe(\"User id this run is for. Notify steps default to them.\"),\n input: z\n .record(z.string(), z.unknown())\n .optional()\n .describe(\"Data made available to the run's steps.\"),\n },\n annotations: { title: \"Trigger a workflow\", readOnlyHint: false, idempotentHint: false },\n },\n handler(async (args) => api.post(\"/v1/workflows/trigger\", args)),\n );\n\n server.registerTool(\n \"get_workflow_run\",\n {\n title: \"Get a workflow run\",\n description:\n \"Fetch one workflow instance by id: which step it is on, its status, and what it is waiting for. \" +\n \"Use this to check on a run started by trigger_workflow.\",\n inputSchema: { instanceId: z.string().min(1).describe(\"Workflow instance id.\") },\n annotations: { title: \"Get a workflow run\", readOnlyHint: true },\n },\n handler(async (args) =>\n api.get(`/v1/workflows/instances/${encodeURIComponent(args.instanceId)}`),\n ),\n );\n\n server.registerTool(\n \"cancel_workflow_run\",\n {\n title: \"Cancel a workflow run\",\n description:\n \"Stop a running or suspended workflow instance so its remaining steps never fire. This does not \" +\n \"recall notifications already sent, and it cannot be undone — confirm with the user before \" +\n \"cancelling a run you did not start in this session.\",\n inputSchema: { instanceId: z.string().min(1).describe(\"Workflow instance id to cancel.\") },\n annotations: {\n title: \"Cancel a workflow run\",\n readOnlyHint: false,\n destructiveHint: true,\n idempotentHint: true,\n },\n },\n handler(async (args) => {\n await api.request(\"DELETE\", `/v1/workflows/instances/${encodeURIComponent(args.instanceId)}`);\n return `Cancelled workflow instance ${args.instanceId}.`;\n }),\n );\n\n server.registerTool(\n \"ingest_event\",\n {\n title: \"Ingest an event\",\n description:\n \"Report that something happened in your product. Workflow instances parked on a matching \" +\n \"`waitForEvent` step resume. Call this to unblock a waiting sequence, e.g. emitting 'order.paid' \" +\n \"so an abandoned-cart workflow stops before its reminder fires.\",\n inputSchema: {\n name: z.string().min(1).describe(\"Event name, matching a workflow's waitForEvent step.\"),\n properties: z\n .record(z.string(), z.unknown())\n .describe(\"Event payload. Include the user id the event is about.\"),\n },\n annotations: { title: \"Ingest an event\", readOnlyHint: false, idempotentHint: false },\n },\n handler(async (args) => api.post(\"/v1/events\", args)),\n );\n}\n"]}
|
package/package.json
CHANGED
package/src/tools/workflows.ts
CHANGED
|
@@ -36,7 +36,16 @@ export function registerWorkflowsTools(server: McpServer, api: NotifkitApi): voi
|
|
|
36
36
|
action: z.literal("waitForEvent"),
|
|
37
37
|
event: z.string().describe("Event name to wait for, as passed to ingest_event."),
|
|
38
38
|
options: z
|
|
39
|
-
.object({
|
|
39
|
+
.object({
|
|
40
|
+
timeout: z.string().optional().describe("e.g. '24h'."),
|
|
41
|
+
match: z
|
|
42
|
+
.record(z.string(), z.unknown())
|
|
43
|
+
.optional()
|
|
44
|
+
.describe(
|
|
45
|
+
"Fields the event must carry to wake this instance, e.g. { userId: 'u1' }. " +
|
|
46
|
+
"Without it any event of that name wakes every waiting instance.",
|
|
47
|
+
),
|
|
48
|
+
})
|
|
40
49
|
.optional()
|
|
41
50
|
.describe("Give a timeout so the instance cannot wait forever."),
|
|
42
51
|
}),
|