@knocklabs/agent-toolkit 0.1.2 → 0.1.3

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.
Files changed (83) hide show
  1. package/dist/ai-sdk/index.js +22 -1085
  2. package/dist/ai-sdk/index.js.map +1 -1
  3. package/dist/ai-sdk/tool-converter.js +3 -10
  4. package/dist/ai-sdk/tool-converter.js.map +1 -1
  5. package/dist/chunk-2CNJ4XX6.js +33 -0
  6. package/dist/chunk-2CNJ4XX6.js.map +1 -0
  7. package/dist/chunk-3LZK6RH6.js +29 -0
  8. package/dist/chunk-3LZK6RH6.js.map +1 -0
  9. package/dist/chunk-4VR65G5W.js +66 -0
  10. package/dist/chunk-4VR65G5W.js.map +1 -0
  11. package/dist/chunk-6H3BXH2Y.js +15 -0
  12. package/dist/chunk-6H3BXH2Y.js.map +1 -0
  13. package/dist/chunk-BY4KQPUO.js +39 -0
  14. package/dist/chunk-BY4KQPUO.js.map +1 -0
  15. package/dist/chunk-DSRTYV37.js +39 -0
  16. package/dist/chunk-DSRTYV37.js.map +1 -0
  17. package/dist/chunk-JTYQTWCX.js +75 -0
  18. package/dist/chunk-JTYQTWCX.js.map +1 -0
  19. package/dist/chunk-NZB2TMJW.js +92 -0
  20. package/dist/chunk-NZB2TMJW.js.map +1 -0
  21. package/dist/chunk-O6DWF42E.js +31 -0
  22. package/dist/chunk-O6DWF42E.js.map +1 -0
  23. package/dist/chunk-OD5VHBGN.js +32 -0
  24. package/dist/chunk-OD5VHBGN.js.map +1 -0
  25. package/dist/chunk-PDMA6RIB.js +19 -0
  26. package/dist/chunk-PDMA6RIB.js.map +1 -0
  27. package/dist/chunk-RYMJEH6P.js +140 -0
  28. package/dist/chunk-RYMJEH6P.js.map +1 -0
  29. package/dist/chunk-THLK376Y.js +191 -0
  30. package/dist/chunk-THLK376Y.js.map +1 -0
  31. package/dist/chunk-TLHETJRF.js +75 -0
  32. package/dist/chunk-TLHETJRF.js.map +1 -0
  33. package/dist/chunk-TOBLV65T.js +30 -0
  34. package/dist/chunk-TOBLV65T.js.map +1 -0
  35. package/dist/chunk-VJFA3ZVW.js +210 -0
  36. package/dist/chunk-VJFA3ZVW.js.map +1 -0
  37. package/dist/chunk-WB4XCCUS.js +19 -0
  38. package/dist/chunk-WB4XCCUS.js.map +1 -0
  39. package/dist/chunk-XRQWR3LY.js +184 -0
  40. package/dist/chunk-XRQWR3LY.js.map +1 -0
  41. package/dist/chunk-XUYE3AGB.js +27 -0
  42. package/dist/chunk-XUYE3AGB.js.map +1 -0
  43. package/dist/lib/knock-client.js +3 -24
  44. package/dist/lib/knock-client.js.map +1 -1
  45. package/dist/lib/knock-tool.js +3 -25
  46. package/dist/lib/knock-tool.js.map +1 -1
  47. package/dist/lib/tools/channels.js +5 -49
  48. package/dist/lib/tools/channels.js.map +1 -1
  49. package/dist/lib/tools/commits.js +5 -93
  50. package/dist/lib/tools/commits.js.map +1 -1
  51. package/dist/lib/tools/email-layouts.js +5 -55
  52. package/dist/lib/tools/email-layouts.js.map +1 -1
  53. package/dist/lib/tools/environments.js +5 -47
  54. package/dist/lib/tools/environments.js.map +1 -1
  55. package/dist/lib/tools/index.js +17 -1016
  56. package/dist/lib/tools/index.js.map +1 -1
  57. package/dist/lib/tools/message-types.js +5 -209
  58. package/dist/lib/tools/message-types.js.map +1 -1
  59. package/dist/lib/tools/messages.js +5 -50
  60. package/dist/lib/tools/messages.js.map +1 -1
  61. package/dist/lib/tools/objects.js +5 -158
  62. package/dist/lib/tools/objects.js.map +1 -1
  63. package/dist/lib/tools/partials.js +5 -55
  64. package/dist/lib/tools/partials.js.map +1 -1
  65. package/dist/lib/tools/tenants.js +5 -93
  66. package/dist/lib/tools/tenants.js.map +1 -1
  67. package/dist/lib/tools/users.js +5 -228
  68. package/dist/lib/tools/users.js.map +1 -1
  69. package/dist/lib/tools/workflows.js +5 -202
  70. package/dist/lib/tools/workflows.js.map +1 -1
  71. package/dist/lib/utils.js +18 -1071
  72. package/dist/lib/utils.js.map +1 -1
  73. package/dist/modelcontextprotocol/adapter.js +3 -22
  74. package/dist/modelcontextprotocol/adapter.js.map +1 -1
  75. package/dist/modelcontextprotocol/index.js +17 -976
  76. package/dist/modelcontextprotocol/index.js.map +1 -1
  77. package/dist/modelcontextprotocol/local-server.js +25 -1041
  78. package/dist/modelcontextprotocol/local-server.js.map +1 -1
  79. package/dist/openai/index.js +22 -1089
  80. package/dist/openai/index.js.map +1 -1
  81. package/dist/openai/tool-converter.js +3 -14
  82. package/dist/openai/tool-converter.js.map +1 -1
  83. package/package.json +3 -3
@@ -0,0 +1,30 @@
1
+ // src/lib/knock-tool.ts
2
+ import { z } from "zod";
3
+ var trimLines = (text) => text.split("\n").map((l) => l.trim()).filter(Boolean).join("\n");
4
+ var KnockTool = (args) => {
5
+ const { execute, ...restOfArgs } = args;
6
+ const parameters = restOfArgs.parameters ? restOfArgs.parameters : z.object({});
7
+ const schemaEntries = Object.entries(parameters.shape);
8
+ const argsStr = schemaEntries.length === 0 ? "Takes no arguments" : schemaEntries.map(([key, value]) => {
9
+ return `- ${key}: ${value.description || ""}`;
10
+ }).join("\n");
11
+ const fullDescription = trimLines(`
12
+ Tool name:
13
+ ${args.name}
14
+ Description:
15
+ ${args.description}.
16
+ Arguments:
17
+ ${argsStr}
18
+ `);
19
+ return {
20
+ ...restOfArgs,
21
+ parameters,
22
+ fullDescription,
23
+ bindExecute: (knockClient, config) => execute(knockClient, config)
24
+ };
25
+ };
26
+
27
+ export {
28
+ KnockTool
29
+ };
30
+ //# sourceMappingURL=chunk-TOBLV65T.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/knock-tool.ts"],"sourcesContent":["import type { ZodObject } from \"zod\";\nimport { z } from \"zod\";\nimport { Config } from \"../types.js\";\nimport { KnockClient } from \"./knock-client.js\";\n\nexport interface KnockToolDefinition {\n /**\n * The method name of the tool. This is a machine-readable string.\n */\n method: string;\n /**\n * The name of the tool. This can be used to reference the tool in the code.\n * A descriptive LLM-readable string.\n */\n name: string;\n\n /**\n * A descriptive prompt explaining the tool's purpose, including examples where useful.\n */\n description: string;\n\n /**\n * A descriptive prompt explaining the tool's purpose, usage and input parameters.\n * Ths is intended to be used by the underlying LLM.\n */\n fullDescription: string;\n\n /**\n * The Zod schema for the input parameters of the tool\n */\n parameters?: ZodObject<any>;\n /**\n * The actual implementation of the tool.\n */\n execute: (\n knockClient: KnockClient,\n config: Config\n ) => (input: any) => Promise<unknown>;\n}\n\nexport interface KnockTool extends Omit<KnockToolDefinition, \"execute\"> {\n bindExecute: (\n knockClient: KnockClient,\n config: Config\n ) => (input: any) => Promise<unknown>;\n}\n\nconst trimLines = (text: string) =>\n text\n .split(\"\\n\")\n .map((l) => l.trim())\n .filter(Boolean)\n .join(\"\\n\");\n\nexport const KnockTool = (\n args: Omit<KnockToolDefinition, \"fullDescription\">\n): KnockTool => {\n const { execute, ...restOfArgs } = args;\n const parameters = restOfArgs.parameters\n ? restOfArgs.parameters\n : z.object({});\n\n const schemaEntries = Object.entries(parameters.shape);\n\n const argsStr =\n schemaEntries.length === 0\n ? \"Takes no arguments\"\n : schemaEntries\n .map(([key, value]) => {\n return `- ${key}: ${(value as any).description || \"\"}`;\n })\n .join(\"\\n\");\n\n const fullDescription = trimLines(`\n Tool name:\n ${args.name}\n Description:\n ${args.description}.\n Arguments:\n ${argsStr}\n `);\n\n return {\n ...restOfArgs,\n parameters,\n fullDescription,\n bindExecute: (knockClient: KnockClient, config: Config) =>\n execute(knockClient, config),\n };\n};\n"],"mappings":";AACA,SAAS,SAAS;AA8ClB,IAAM,YAAY,CAAC,SACjB,KACG,MAAM,IAAI,EACV,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,EACnB,OAAO,OAAO,EACd,KAAK,IAAI;AAEP,IAAM,YAAY,CACvB,SACc;AACd,QAAM,EAAE,SAAS,GAAG,WAAW,IAAI;AACnC,QAAM,aAAa,WAAW,aAC1B,WAAW,aACX,EAAE,OAAO,CAAC,CAAC;AAEf,QAAM,gBAAgB,OAAO,QAAQ,WAAW,KAAK;AAErD,QAAM,UACJ,cAAc,WAAW,IACrB,uBACA,cACG,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM;AACrB,WAAO,KAAK,GAAG,KAAM,MAAc,eAAe,EAAE;AAAA,EACtD,CAAC,EACA,KAAK,IAAI;AAElB,QAAM,kBAAkB,UAAU;AAAA;AAAA,IAEhC,KAAK,IAAI;AAAA;AAAA,IAET,KAAK,WAAW;AAAA;AAAA,IAEhB,OAAO;AAAA,GACR;AAED,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA;AAAA,IACA,aAAa,CAAC,aAA0B,WACtC,QAAQ,aAAa,MAAM;AAAA,EAC/B;AACF;","names":[]}
@@ -0,0 +1,210 @@
1
+ import {
2
+ KnockTool
3
+ } from "./chunk-TOBLV65T.js";
4
+
5
+ // src/lib/tools/users.ts
6
+ import { z } from "zod";
7
+ var getUser = KnockTool({
8
+ method: "get_user",
9
+ name: "Get user",
10
+ description: `
11
+ Retrieves the complete user object for the given userId, including email, name, phone number, and any custom properties. Use this tool when you need to retrieve a user's complete profile.
12
+
13
+ If the userId is not provided, it will use the userId from the config.
14
+ `,
15
+ parameters: z.object({
16
+ userId: z.string().describe("(string): The userId of the User to retrieve.")
17
+ }),
18
+ execute: (knockClient, config) => async (params) => {
19
+ const publicClient = await knockClient.publicApi();
20
+ return await publicClient.users.get(params.userId ?? config.userId);
21
+ }
22
+ });
23
+ var createOrUpdateUser = KnockTool({
24
+ method: "create_or_update_user",
25
+ name: "Create or update user",
26
+ description: `
27
+ Creates a new user if they don't exist, or updates the user object for the given userId, including email, name, phone number, and any custom properties.
28
+
29
+ Use this tool when you need to update a user's profile.
30
+
31
+ If the userId is not provided, it will use the userId from the config.
32
+ `,
33
+ parameters: z.object({
34
+ userId: z.string().describe("(string): The userId of the User to update."),
35
+ email: z.string().describe("(string): The email of the User to update."),
36
+ name: z.string().describe("(string): The name of the User to update."),
37
+ phoneNumber: z.string().describe("(string): The phone number of the User to update."),
38
+ customProperties: z.record(z.string(), z.any()).describe(
39
+ "(object): A dictionary of custom properties to update for the User."
40
+ )
41
+ }),
42
+ execute: (knockClient, config) => async (params) => {
43
+ const publicClient = await knockClient.publicApi();
44
+ return await publicClient.users.identify(params.userId, {
45
+ email: params.email,
46
+ name: params.name,
47
+ phone_number: params.phoneNumber,
48
+ ...params.customProperties ?? {}
49
+ });
50
+ }
51
+ });
52
+ var deleteUser = KnockTool({
53
+ method: "delete_user",
54
+ name: "Delete user",
55
+ description: `
56
+ Deletes a user. Use this tool when you've been asked to remove a user from the system.
57
+ `,
58
+ parameters: z.object({
59
+ userId: z.string().describe("(string): The userId of the User to delete.")
60
+ }),
61
+ execute: (knockClient, config) => async (params) => {
62
+ const publicClient = await knockClient.publicApi();
63
+ await publicClient.users.delete(params.userId);
64
+ return { success: true };
65
+ }
66
+ });
67
+ var getUserPreferences = KnockTool({
68
+ method: "get_user_preferences",
69
+ name: "Get user preferences",
70
+ description: `
71
+ Retrieves the user's notification preferences for the given userId.
72
+
73
+ If the userId is not provided, it will use the userId from the config.
74
+ `,
75
+ parameters: z.object({
76
+ userId: z.string().describe(
77
+ "(string): The userId of the User to retrieve Preferences for."
78
+ ),
79
+ preferenceSetId: z.string().describe(
80
+ "(string): The preferenceSetId of the User to retrieve preferences for. Defaults to `default`."
81
+ )
82
+ }),
83
+ execute: (knockClient, config) => async (params) => {
84
+ const publicClient = await knockClient.publicApi();
85
+ return await publicClient.users.getPreferences(
86
+ params.userId ?? config.userId,
87
+ {
88
+ preferenceSet: params.preferenceSetId ?? "default"
89
+ }
90
+ );
91
+ }
92
+ });
93
+ var setUserPreferences = KnockTool({
94
+ method: "set_user_preferences",
95
+ name: "Set user preferences",
96
+ description: `
97
+ Overwrites the user's notification preferences for the given userId. Allows setting per-workflow, per-category, or per-channel notification preferences. Use this tool when you are asked to update a user's notification preferences.
98
+
99
+ If the userId is not provided, it will use the userId from the config.
100
+
101
+ Instructions:
102
+
103
+ - You must ALWAYS provide a full preference set to this tool.
104
+ - When setting per-workflow preferences, the key in the object should be the workflow key.
105
+ - Workflow and category preferences should always have channel types underneath.
106
+ - The channel types available to you are: email, sms, push, chat, and in_app_feed.
107
+ - To turn OFF a preference, you must set it to false.
108
+ - To turn ON a preference, you must set it to true.
109
+
110
+ <examples>
111
+ <example>
112
+ <description>
113
+ Update the user's preferences to turn off email notifications for the "welcome" workflow.
114
+ </description>
115
+ <input>
116
+ {
117
+ "workflows": {
118
+ "welcome": {
119
+ "channel_types": {
120
+ "email": false
121
+ }
122
+ }
123
+ }
124
+ }
125
+ </example>
126
+ </examples>
127
+ `,
128
+ parameters: z.object({
129
+ userId: z.string().describe("(string): The userId of the User to update preferences for."),
130
+ workflows: z.record(z.string(), z.any()).describe(
131
+ "(object): The workflows to update where the key is the workflow key, and the value of the object is an object that contains a `channel_types` key with a boolean value for each channel type."
132
+ ),
133
+ categories: z.record(z.string(), z.any()).describe(
134
+ "(object): The categories to update where the key is the category key, and the value of the object is an object that contains a `channel_types` key with a boolean value for each channel type."
135
+ ),
136
+ channel_types: z.record(z.string(), z.boolean()).describe(
137
+ "(object): The channel types to update where the key is the channel type, and the value of the object is a boolean value."
138
+ )
139
+ }),
140
+ execute: (knockClient, config) => async (params) => {
141
+ const publicClient = await knockClient.publicApi();
142
+ const existingPreferences = await publicClient.users.getPreferences(
143
+ params.userId ?? config.userId,
144
+ {
145
+ preferenceSet: "default"
146
+ }
147
+ );
148
+ const updatedPreferences = {
149
+ ...existingPreferences,
150
+ workflows: {
151
+ ...existingPreferences.workflows,
152
+ ...params.workflows
153
+ },
154
+ categories: {
155
+ ...existingPreferences.categories,
156
+ ...params.categories
157
+ },
158
+ channel_types: {
159
+ ...existingPreferences.channel_types,
160
+ ...params.channel_types
161
+ }
162
+ };
163
+ return await publicClient.users.setPreferences(
164
+ params.userId ?? config.userId,
165
+ updatedPreferences
166
+ );
167
+ }
168
+ });
169
+ var getUserMessages = KnockTool({
170
+ method: "get_user_messages",
171
+ name: "Get user messages",
172
+ description: `
173
+ Retrieves the messages that this user has received from the service. Use this tool when you need information about the notifications that the user has received, including if the message has been read, seen, or interacted with. This will return a list of messages across all of the channels.
174
+
175
+ If the userId is not provided, it will use the userId from the config.
176
+ `,
177
+ parameters: z.object({
178
+ userId: z.string().describe("(string): The userId of the User to retrieve messages for."),
179
+ workflowRunId: z.string().describe(
180
+ "(string): The workflowRunId of the User to retrieve. Use this when you want to retrieve messages sent from a workflow trigger."
181
+ )
182
+ }),
183
+ execute: (knockClient, config) => async (params) => {
184
+ const publicClient = await knockClient.publicApi();
185
+ return await publicClient.users.getMessages(
186
+ params.userId ?? config.userId,
187
+ {
188
+ workflow_run_id: params.workflowRunId
189
+ }
190
+ );
191
+ }
192
+ });
193
+ var users = {
194
+ getUser,
195
+ deleteUser,
196
+ createOrUpdateUser,
197
+ getUserPreferences,
198
+ setUserPreferences,
199
+ getUserMessages
200
+ };
201
+ var permissions = {
202
+ read: ["getUser", "getUserPreferences", "getUserMessages"],
203
+ manage: ["createOrUpdateUser", "deleteUser", "setUserPreferences"]
204
+ };
205
+
206
+ export {
207
+ users,
208
+ permissions
209
+ };
210
+ //# sourceMappingURL=chunk-VJFA3ZVW.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/tools/users.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { KnockTool } from \"../knock-tool.js\";\n\nconst getUser = KnockTool({\n method: \"get_user\",\n name: \"Get user\",\n description: `\n Retrieves the complete user object for the given userId, including email, name, phone number, and any custom properties. Use this tool when you need to retrieve a user's complete profile.\n\n If the userId is not provided, it will use the userId from the config.\n `,\n parameters: z.object({\n userId: z\n .string()\n .describe(\"(string): The userId of the User to retrieve.\"),\n }),\n execute: (knockClient, config) => async (params) => {\n const publicClient = await knockClient.publicApi();\n\n return await publicClient.users.get(params.userId ?? config.userId);\n },\n});\n\nconst createOrUpdateUser = KnockTool({\n method: \"create_or_update_user\",\n name: \"Create or update user\",\n description: `\n Creates a new user if they don't exist, or updates the user object for the given userId, including email, name, phone number, and any custom properties.\n \n Use this tool when you need to update a user's profile.\n\n If the userId is not provided, it will use the userId from the config.\n `,\n parameters: z.object({\n userId: z.string().describe(\"(string): The userId of the User to update.\"),\n email: z.string().describe(\"(string): The email of the User to update.\"),\n name: z.string().describe(\"(string): The name of the User to update.\"),\n phoneNumber: z\n .string()\n .describe(\"(string): The phone number of the User to update.\"),\n customProperties: z\n .record(z.string(), z.any())\n .describe(\n \"(object): A dictionary of custom properties to update for the User.\"\n ),\n }),\n execute: (knockClient, config) => async (params) => {\n const publicClient = await knockClient.publicApi();\n\n return await publicClient.users.identify(params.userId, {\n email: params.email,\n name: params.name,\n phone_number: params.phoneNumber,\n ...(params.customProperties ?? {}),\n });\n },\n});\n\nconst deleteUser = KnockTool({\n method: \"delete_user\",\n name: \"Delete user\",\n description: `\n Deletes a user. Use this tool when you've been asked to remove a user from the system.\n `,\n parameters: z.object({\n userId: z.string().describe(\"(string): The userId of the User to delete.\"),\n }),\n execute: (knockClient, config) => async (params) => {\n const publicClient = await knockClient.publicApi();\n await publicClient.users.delete(params.userId);\n return { success: true };\n },\n});\n\nconst getUserPreferences = KnockTool({\n method: \"get_user_preferences\",\n name: \"Get user preferences\",\n description: `\n Retrieves the user's notification preferences for the given userId.\n\n If the userId is not provided, it will use the userId from the config. \n `,\n parameters: z.object({\n userId: z\n .string()\n .describe(\n \"(string): The userId of the User to retrieve Preferences for.\"\n ),\n preferenceSetId: z\n .string()\n .describe(\n \"(string): The preferenceSetId of the User to retrieve preferences for. Defaults to `default`.\"\n ),\n }),\n execute: (knockClient, config) => async (params) => {\n const publicClient = await knockClient.publicApi();\n\n return await publicClient.users.getPreferences(\n params.userId ?? config.userId,\n {\n preferenceSet: params.preferenceSetId ?? \"default\",\n }\n );\n },\n});\n\nconst setUserPreferences = KnockTool({\n method: \"set_user_preferences\",\n name: \"Set user preferences\",\n description: `\n Overwrites the user's notification preferences for the given userId. Allows setting per-workflow, per-category, or per-channel notification preferences. Use this tool when you are asked to update a user's notification preferences.\n\n If the userId is not provided, it will use the userId from the config.\n\n Instructions:\n\n - You must ALWAYS provide a full preference set to this tool.\n - When setting per-workflow preferences, the key in the object should be the workflow key.\n - Workflow and category preferences should always have channel types underneath.\n - The channel types available to you are: email, sms, push, chat, and in_app_feed.\n - To turn OFF a preference, you must set it to false.\n - To turn ON a preference, you must set it to true.\n\n <examples>\n <example>\n <description>\n Update the user's preferences to turn off email notifications for the \"welcome\" workflow.\n </description>\n <input>\n {\n \"workflows\": {\n \"welcome\": {\n \"channel_types\": {\n \"email\": false\n }\n }\n }\n }\n </example>\n </examples>\n `,\n parameters: z.object({\n userId: z\n .string()\n .describe(\"(string): The userId of the User to update preferences for.\"),\n workflows: z\n .record(z.string(), z.any())\n .describe(\n \"(object): The workflows to update where the key is the workflow key, and the value of the object is an object that contains a `channel_types` key with a boolean value for each channel type.\"\n ),\n categories: z\n .record(z.string(), z.any())\n .describe(\n \"(object): The categories to update where the key is the category key, and the value of the object is an object that contains a `channel_types` key with a boolean value for each channel type.\"\n ),\n channel_types: z\n .record(z.string(), z.boolean())\n .describe(\n \"(object): The channel types to update where the key is the channel type, and the value of the object is a boolean value.\"\n ),\n }),\n execute: (knockClient, config) => async (params) => {\n const publicClient = await knockClient.publicApi();\n\n const existingPreferences = await publicClient.users.getPreferences(\n params.userId ?? config.userId,\n {\n preferenceSet: \"default\",\n }\n );\n\n const updatedPreferences = {\n ...existingPreferences,\n workflows: {\n ...existingPreferences.workflows,\n ...params.workflows,\n },\n categories: {\n ...existingPreferences.categories,\n ...params.categories,\n },\n channel_types: {\n ...existingPreferences.channel_types,\n ...params.channel_types,\n },\n };\n\n return await publicClient.users.setPreferences(\n params.userId ?? config.userId,\n updatedPreferences\n );\n },\n});\n\nconst getUserMessages = KnockTool({\n method: \"get_user_messages\",\n name: \"Get user messages\",\n description: `\n Retrieves the messages that this user has received from the service. Use this tool when you need information about the notifications that the user has received, including if the message has been read, seen, or interacted with. This will return a list of messages across all of the channels.\n\n If the userId is not provided, it will use the userId from the config.\n `,\n parameters: z.object({\n userId: z\n .string()\n .describe(\"(string): The userId of the User to retrieve messages for.\"),\n workflowRunId: z\n .string()\n .describe(\n \"(string): The workflowRunId of the User to retrieve. Use this when you want to retrieve messages sent from a workflow trigger.\"\n ),\n }),\n execute: (knockClient, config) => async (params) => {\n const publicClient = await knockClient.publicApi();\n\n return await publicClient.users.getMessages(\n params.userId ?? config.userId,\n {\n workflow_run_id: params.workflowRunId,\n }\n );\n },\n});\n\nexport const users = {\n getUser,\n deleteUser,\n createOrUpdateUser,\n getUserPreferences,\n setUserPreferences,\n getUserMessages,\n};\n\nexport const permissions = {\n read: [\"getUser\", \"getUserPreferences\", \"getUserMessages\"],\n manage: [\"createOrUpdateUser\", \"deleteUser\", \"setUserPreferences\"],\n};\n"],"mappings":";;;;;AAAA,SAAS,SAAS;AAGlB,IAAM,UAAU,UAAU;AAAA,EACxB,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA,EAKb,YAAY,EAAE,OAAO;AAAA,IACnB,QAAQ,EACL,OAAO,EACP,SAAS,+CAA+C;AAAA,EAC7D,CAAC;AAAA,EACD,SAAS,CAAC,aAAa,WAAW,OAAO,WAAW;AAClD,UAAM,eAAe,MAAM,YAAY,UAAU;AAEjD,WAAO,MAAM,aAAa,MAAM,IAAI,OAAO,UAAU,OAAO,MAAM;AAAA,EACpE;AACF,CAAC;AAED,IAAM,qBAAqB,UAAU;AAAA,EACnC,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOb,YAAY,EAAE,OAAO;AAAA,IACnB,QAAQ,EAAE,OAAO,EAAE,SAAS,6CAA6C;AAAA,IACzE,OAAO,EAAE,OAAO,EAAE,SAAS,4CAA4C;AAAA,IACvE,MAAM,EAAE,OAAO,EAAE,SAAS,2CAA2C;AA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Aa,MAAM;AAAA,MAC9B,OAAO,UAAU,OAAO;AAAA,MACxB;AAAA,IACF;AAAA,EACF;AACF,CAAC;AAED,IAAM,kBAAkB,UAAU;AAAA,EAChC,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA,EAKb,YAAY,EAAE,OAAO;AAAA,IACnB,QAAQ,EACL,OAAO,EACP,SAAS,4DAA4D;AAAA,IACxE,eAAe,EACZ,OAAO,EACP;AAAA,MACC;AAAA,IACF;AAAA,EACJ,CAAC;AAAA,EACD,SAAS,CAAC,aAAa,WAAW,OAAO,WAAW;AAClD,UAAM,eAAe,MAAM,YAAY,UAAU;AAEjD,WAAO,MAAM,aAAa,MAAM;AAAA,MAC9B,OAAO,UAAU,OAAO;AAAA,MACxB;AAAA,QACE,iBAAiB,OAAO;AAAA,MAC1B;AAAA,IACF;AAAA,EACF;AACF,CAAC;AAEM,IAAM,QAAQ;AAAA,EACnB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEO,IAAM,cAAc;AAAA,EACzB,MAAM,CAAC,WAAW,sBAAsB,iBAAiB;AAAA,EACzD,QAAQ,CAAC,sBAAsB,cAAc,oBAAoB;AACnE;","names":[]}
@@ -0,0 +1,19 @@
1
+ // src/openai/tool-converter.ts
2
+ import { z } from "zod";
3
+ import { zodToJsonSchema } from "zod-to-json-schema";
4
+ function knockToolToChatCompletionTool(knockTool) {
5
+ return {
6
+ type: "function",
7
+ function: {
8
+ // NOTE: We use the method here as the function name as it's machine readable.
9
+ name: knockTool.method,
10
+ description: knockTool.description,
11
+ parameters: zodToJsonSchema(knockTool.parameters ?? z.object({}))
12
+ }
13
+ };
14
+ }
15
+
16
+ export {
17
+ knockToolToChatCompletionTool
18
+ };
19
+ //# sourceMappingURL=chunk-WB4XCCUS.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/openai/tool-converter.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { KnockTool } from \"../lib/knock-tool.js\";\nimport { ChatCompletionTool } from \"openai/resources.mjs\";\nimport { zodToJsonSchema } from \"zod-to-json-schema\";\n\n/**\n * Convert a KnockTool to a ChatCompletionTool, ready to be used with the OpenAI API.\n *\n * @param knockTool - The KnockTool to convert\n * @returns The converted ChatCompletionTool\n */\nexport function knockToolToChatCompletionTool(\n knockTool: KnockTool\n): ChatCompletionTool {\n return {\n type: \"function\",\n function: {\n // NOTE: We use the method here as the function name as it's machine readable.\n name: knockTool.method,\n description: knockTool.description,\n parameters: zodToJsonSchema(knockTool.parameters ?? z.object({})),\n },\n };\n}\n"],"mappings":";AAAA,SAAS,SAAS;AAGlB,SAAS,uBAAuB;AAQzB,SAAS,8BACd,WACoB;AACpB,SAAO;AAAA,IACL,MAAM;AAAA,IACN,UAAU;AAAA;AAAA,MAER,MAAM,UAAU;AAAA,MAChB,aAAa,UAAU;AAAA,MACvB,YAAY,gBAAgB,UAAU,cAAc,EAAE,OAAO,CAAC,CAAC,CAAC;AAAA,IAClE;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,184 @@
1
+ import {
2
+ KnockTool
3
+ } from "./chunk-TOBLV65T.js";
4
+
5
+ // src/lib/tools/workflows.ts
6
+ import { z } from "zod";
7
+ var listWorkflows = KnockTool({
8
+ method: "list_workflows",
9
+ name: "List workflows",
10
+ description: `
11
+ List all workflows available for the given environment. Returns structural information about the workflows, including the key, name, description, and categories. Will also return the steps that make up the workflow.
12
+
13
+ Use this tool when you need to understand which workflows are available to be called.
14
+ `,
15
+ parameters: z.object({
16
+ environment: z.string().describe(
17
+ "(string): The environment to list workflows for. Defaults to `development`."
18
+ )
19
+ }),
20
+ execute: (knockClient, config) => async (params) => {
21
+ const allWorkflows = [];
22
+ const listParams = {
23
+ environment: params.environment ?? config.environment ?? "development"
24
+ };
25
+ for await (const workflow of knockClient.workflows.list(listParams)) {
26
+ allWorkflows.push(workflow);
27
+ }
28
+ return allWorkflows;
29
+ }
30
+ });
31
+ var triggerWorkflow = KnockTool({
32
+ method: "trigger_workflow",
33
+ name: "Trigger workflow",
34
+ description: `
35
+ Trigger a workflow for one or more recipients.
36
+
37
+ Use this tool when you need to trigger a workflow to send a notification across the channels configured for the workflow. The workflow must be committed in the environment for you to trigger it.
38
+
39
+ When recipients aren't provided, the workflow will be triggered for the current user specified in the config.
40
+ `,
41
+ parameters: z.object({
42
+ workflowKey: z.string().describe("(string): The key of the workflow to trigger."),
43
+ recipients: z.array(z.string()).describe("(array): The recipients to trigger the workflow for."),
44
+ data: z.record(z.string(), z.any()).describe("(object): Data to pass to the workflow."),
45
+ tenant: z.record(z.string(), z.any()).describe(
46
+ "(object): The tenant to trigger the workflow for. Must contain an id if being sent."
47
+ )
48
+ }),
49
+ execute: (knockClient, config) => async (params) => {
50
+ const publicClient = await knockClient.publicApi();
51
+ const result = await publicClient.workflows.trigger(params.workflowKey, {
52
+ recipients: params.recipients,
53
+ data: params.data,
54
+ tenant: params.tenant
55
+ });
56
+ return result.workflow_run_id;
57
+ }
58
+ });
59
+ var createEmailWorkflow = KnockTool({
60
+ method: "create_email_workflow",
61
+ name: "Create email workflow",
62
+ description: `
63
+ Creates a simple email workflow with a single step that sends an email to the recipient. Use this tool when you need to need to create an email notification, and you don't need to specify any additional steps. You can only create workflows in the development environment.
64
+
65
+ The content of the email you supply should ONLY ever be in markdown format for simplicity. You can supply dynamic variables to the subject and body of the email using the liquid template language.
66
+
67
+ When writing markdown, be sure to use headings (##) to separate sections of the email. Use an informal writing style, and avoid using complex language.
68
+
69
+ The following variables are available to use in the email subject and body:
70
+
71
+ - \`recipient.name\`: The name of the recipient.
72
+ - \`recipient.email\`: The email of the recipient.
73
+ - \`recipient.phone_number\`: The phone number of the recipient.
74
+ - \`tenant.id\`: The id of the tenant.
75
+ - \`tenant.name\`: The name of the tenant.
76
+
77
+ You can supply any other dynamic variables by referencing them under the \`data\` key in the \`data\` parameter when triggering the workflow. You add those like \`{{ data.variable_name }}\`.
78
+
79
+ You can also supply a list of categories to the workflow. These are used to categorize workflows for notification preferences. Categories should be supplied as lowercase strings in kebab case.
80
+
81
+ Once you've created the workflow, you should ask if you should commit the changes to the environment.
82
+ `,
83
+ parameters: z.object({
84
+ environment: z.string().describe(
85
+ "(string): The environment to create the workflow in. Defaults to `development`."
86
+ ),
87
+ workflowKey: z.string().describe("(string): The key of the workflow."),
88
+ name: z.string().describe("(string): The name of the workflow."),
89
+ categories: z.array(z.string()).describe("(array): The categories to add to the workflow."),
90
+ subject: z.string().describe("(string): The subject of the email."),
91
+ body: z.string().describe("(string): The body of the email.")
92
+ }),
93
+ execute: (knockClient, config) => async (params) => {
94
+ const emailChannelsPage = await knockClient.channels.list();
95
+ const emailChannels = emailChannelsPage.entries.filter(
96
+ (channel) => channel.type === "email"
97
+ );
98
+ if (emailChannels.length === 0) {
99
+ throw new Error("No email channels found");
100
+ }
101
+ const workflowParams = {
102
+ environment: params.environment ?? config.environment ?? "development",
103
+ workflow: {
104
+ name: params.name,
105
+ categories: params.categories ?? [],
106
+ steps: [
107
+ {
108
+ type: "channel",
109
+ channel_key: emailChannels[0].key,
110
+ template: {
111
+ settings: {
112
+ layout_key: "default"
113
+ },
114
+ subject: params.subject,
115
+ visual_blocks: [
116
+ // @ts-ignore
117
+ {
118
+ type: "markdown",
119
+ content: params.body
120
+ }
121
+ ]
122
+ },
123
+ name: "Email",
124
+ ref: "email_1"
125
+ }
126
+ ]
127
+ }
128
+ };
129
+ return await knockClient.workflows.upsert(
130
+ params.workflowKey,
131
+ workflowParams
132
+ );
133
+ }
134
+ });
135
+ var createOneOffWorkflowSchedule = KnockTool({
136
+ method: "create_one_off_workflow_schedule",
137
+ name: "Create one-off workflow schedule",
138
+ description: `
139
+ Create a one-off workflow schedule for a user. Use this tool when you need to schedule the execution of a workflow for a specific user in the future, like to power a delayed notification.
140
+
141
+ Schedules can accept a set of data that will be passed to the workflow trigger when it is executed. When the userId is not provided, the schedule will be created for the current user specified in the config.
142
+
143
+ Examples:
144
+
145
+ - In three days, send a welcome email to a user
146
+ - In one hour, send a password reset email to a user
147
+ - In two weeks, send a survey to a user
148
+ `,
149
+ parameters: z.object({
150
+ workflowKey: z.string().describe("(string): The key of the workflow to schedule."),
151
+ userId: z.string().describe(
152
+ "(string): The userId of the user to schedule the workflow for."
153
+ ),
154
+ scheduledAt: z.string().describe(
155
+ "(string): The date and time to schedule the workflow for. Must be in ISO 8601 format."
156
+ ),
157
+ data: z.record(z.string(), z.any()).describe("(object): Data to pass to the workflow.")
158
+ }),
159
+ execute: (knockClient, config) => async (params) => {
160
+ const publicClient = await knockClient.publicApi();
161
+ return await publicClient.workflows.createSchedules(params.workflowKey, {
162
+ recipients: [params.userId ?? config.userId],
163
+ scheduled_at: params.scheduledAt,
164
+ data: params.data
165
+ });
166
+ }
167
+ });
168
+ var workflows = {
169
+ listWorkflows,
170
+ triggerWorkflow,
171
+ createEmailWorkflow,
172
+ createOneOffWorkflowSchedule
173
+ };
174
+ var permissions = {
175
+ read: ["listWorkflows"],
176
+ manage: ["createEmailWorkflow", "createOneOffWorkflowSchedule"],
177
+ trigger: ["triggerWorkflow"]
178
+ };
179
+
180
+ export {
181
+ workflows,
182
+ permissions
183
+ };
184
+ //# sourceMappingURL=chunk-XRQWR3LY.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/tools/workflows.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { KnockTool } from \"../knock-tool.js\";\nimport {\n Workflow,\n WorkflowUpsertParams,\n} from \"@knocklabs/mgmt/resources/index.js\";\n\nconst listWorkflows = KnockTool({\n method: \"list_workflows\",\n name: \"List workflows\",\n description: `\n List all workflows available for the given environment. Returns structural information about the workflows, including the key, name, description, and categories. Will also return the steps that make up the workflow. \n\n Use this tool when you need to understand which workflows are available to be called. \n `,\n parameters: z.object({\n environment: z\n .string()\n .describe(\n \"(string): The environment to list workflows for. Defaults to `development`.\"\n ),\n }),\n execute: (knockClient, config) => async (params) => {\n const allWorkflows: Workflow[] = [];\n const listParams = {\n environment: params.environment ?? config.environment ?? \"development\",\n };\n\n for await (const workflow of knockClient.workflows.list(listParams)) {\n allWorkflows.push(workflow);\n }\n return allWorkflows;\n },\n});\n\nconst triggerWorkflow = KnockTool({\n method: \"trigger_workflow\",\n name: \"Trigger workflow\",\n description: `\n Trigger a workflow for one or more recipients.\n\n Use this tool when you need to trigger a workflow to send a notification across the channels configured for the workflow. The workflow must be committed in the environment for you to trigger it.\n\n When recipients aren't provided, the workflow will be triggered for the current user specified in the config.\n `,\n parameters: z.object({\n workflowKey: z\n .string()\n .describe(\"(string): The key of the workflow to trigger.\"),\n recipients: z\n .array(z.string())\n .describe(\"(array): The recipients to trigger the workflow for.\"),\n data: z\n .record(z.string(), z.any())\n .describe(\"(object): Data to pass to the workflow.\"),\n tenant: z\n .record(z.string(), z.any())\n .describe(\n \"(object): The tenant to trigger the workflow for. Must contain an id if being sent.\"\n ),\n }),\n execute: (knockClient, config) => async (params) => {\n const publicClient = await knockClient.publicApi();\n\n const result = await publicClient.workflows.trigger(params.workflowKey, {\n recipients: params.recipients,\n data: params.data,\n tenant: params.tenant,\n });\n\n return result.workflow_run_id;\n },\n});\n\nconst createEmailWorkflow = KnockTool({\n method: \"create_email_workflow\",\n name: \"Create email workflow\",\n description: `\n Creates a simple email workflow with a single step that sends an email to the recipient. Use this tool when you need to need to create an email notification, and you don't need to specify any additional steps. You can only create workflows in the development environment.\n\n The content of the email you supply should ONLY ever be in markdown format for simplicity. You can supply dynamic variables to the subject and body of the email using the liquid template language.\n\n When writing markdown, be sure to use headings (##) to separate sections of the email. Use an informal writing style, and avoid using complex language.\n\n The following variables are available to use in the email subject and body:\n\n - \\`recipient.name\\`: The name of the recipient.\n - \\`recipient.email\\`: The email of the recipient.\n - \\`recipient.phone_number\\`: The phone number of the recipient.\n - \\`tenant.id\\`: The id of the tenant.\n - \\`tenant.name\\`: The name of the tenant.\n\n You can supply any other dynamic variables by referencing them under the \\`data\\` key in the \\`data\\` parameter when triggering the workflow. You add those like \\`{{ data.variable_name }}\\`.\n\n You can also supply a list of categories to the workflow. These are used to categorize workflows for notification preferences. Categories should be supplied as lowercase strings in kebab case.\n\n Once you've created the workflow, you should ask if you should commit the changes to the environment.\n `,\n parameters: z.object({\n environment: z\n .string()\n .describe(\n \"(string): The environment to create the workflow in. Defaults to `development`.\"\n ),\n workflowKey: z.string().describe(\"(string): The key of the workflow.\"),\n name: z.string().describe(\"(string): The name of the workflow.\"),\n categories: z\n .array(z.string())\n .describe(\"(array): The categories to add to the workflow.\"),\n subject: z.string().describe(\"(string): The subject of the email.\"),\n body: z.string().describe(\"(string): The body of the email.\"),\n }),\n execute: (knockClient, config) => async (params) => {\n const emailChannelsPage = await knockClient.channels.list();\n const emailChannels = emailChannelsPage.entries.filter(\n (channel) => channel.type === \"email\"\n );\n\n if (emailChannels.length === 0) {\n throw new Error(\"No email channels found\");\n }\n\n const workflowParams: WorkflowUpsertParams = {\n environment: params.environment ?? config.environment ?? \"development\",\n workflow: {\n name: params.name,\n categories: params.categories ?? [],\n steps: [\n {\n type: \"channel\",\n channel_key: emailChannels[0].key,\n template: {\n settings: {\n layout_key: \"default\",\n },\n subject: params.subject,\n visual_blocks: [\n // @ts-ignore\n {\n type: \"markdown\",\n content: params.body,\n },\n ],\n },\n name: \"Email\",\n ref: \"email_1\",\n },\n ],\n },\n };\n\n return await knockClient.workflows.upsert(\n params.workflowKey,\n workflowParams\n );\n },\n});\n\nconst createOneOffWorkflowSchedule = KnockTool({\n method: \"create_one_off_workflow_schedule\",\n name: \"Create one-off workflow schedule\",\n description: `\n Create a one-off workflow schedule for a user. Use this tool when you need to schedule the execution of a workflow for a specific user in the future, like to power a delayed notification.\n \n Schedules can accept a set of data that will be passed to the workflow trigger when it is executed. When the userId is not provided, the schedule will be created for the current user specified in the config.\n\n Examples:\n \n - In three days, send a welcome email to a user\n - In one hour, send a password reset email to a user\n - In two weeks, send a survey to a user\n `,\n parameters: z.object({\n workflowKey: z\n .string()\n .describe(\"(string): The key of the workflow to schedule.\"),\n userId: z\n .string()\n .describe(\n \"(string): The userId of the user to schedule the workflow for.\"\n ),\n scheduledAt: z\n .string()\n .describe(\n \"(string): The date and time to schedule the workflow for. Must be in ISO 8601 format.\"\n ),\n data: z\n .record(z.string(), z.any())\n .describe(\"(object): Data to pass to the workflow.\"),\n }),\n execute: (knockClient, config) => async (params) => {\n const publicClient = await knockClient.publicApi();\n\n return await publicClient.workflows.createSchedules(params.workflowKey, {\n recipients: [params.userId ?? config.userId],\n scheduled_at: params.scheduledAt,\n data: params.data,\n });\n },\n});\n\nexport const workflows = {\n listWorkflows,\n triggerWorkflow,\n createEmailWorkflow,\n createOneOffWorkflowSchedule,\n};\n\nexport const permissions = {\n read: [\"listWorkflows\"],\n manage: [\"createEmailWorkflow\", \"createOneOffWorkflowSchedule\"],\n trigger: [\"triggerWorkflow\"],\n};\n"],"mappings":";;;;;AAAA,SAAS,SAAS;AAOlB,IAAM,gBAAgB,UAAU;AAAA,EAC9B,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA,EAKb,YAAY,EAAE,OAAO;AAAA,IACnB,aAAa,EACV,OAAO,EACP;AAAA,MACC;AAAA,IACF;AAAA,EACJ,CAAC;AAAA,EACD,SAAS,CAAC,aAAa,WAAW,OAAO,WAAW;AAClD,UAAM,eAA2B,CAAC;AAClC,UAAM,aAAa;AAAA,MACjB,aAAa,OAAO,eAAe,OAAO,eAAe;AAAA,IAC3D;AAEA,qBAAiB,YAAY,YAAY,UAAU,KAAK,UAAU,GAAG;AACnE,mBAAa,KAAK,QAAQ;AAAA,IAC5B;AACA,WAAO;AAAA,EACT;AACF,CAAC;AAED,IAAM,kBAAkB,UAAU;AAAA,EAChC,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOb,YAAY,EAAE,OAAO;AAAA,IACnB,aAAa,EACV,OAAO,EACP,SA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eAAe,MAAM,YAAY,UAAU;AAEjD,WAAO,MAAM,aAAa,UAAU,gBAAgB,OAAO,aAAa;AAAA,MACtE,YAAY,CAAC,OAAO,UAAU,OAAO,MAAM;AAAA,MAC3C,cAAc,OAAO;AAAA,MACrB,MAAM,OAAO;AAAA,IACf,CAAC;AAAA,EACH;AACF,CAAC;AAEM,IAAM,YAAY;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEO,IAAM,cAAc;AAAA,EACzB,MAAM,CAAC,eAAe;AAAA,EACtB,QAAQ,CAAC,uBAAuB,8BAA8B;AAAA,EAC9D,SAAS,CAAC,iBAAiB;AAC7B;","names":[]}
@@ -0,0 +1,27 @@
1
+ // src/modelcontextprotocol/adapter.ts
2
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
+ import { z } from "zod";
4
+ var KnockMcpServer = class extends McpServer {
5
+ constructor(knockClient, config, tools) {
6
+ super({ name: "Knock", version: "0.1.0" });
7
+ tools.forEach((tool) => {
8
+ const toolParams = tool.parameters ?? z.object({});
9
+ this.tool(
10
+ tool.name,
11
+ tool.description,
12
+ toolParams.shape,
13
+ async (arg) => {
14
+ const res = await tool.bindExecute(knockClient, config)(arg);
15
+ return {
16
+ content: [{ type: "text", text: JSON.stringify(res) }]
17
+ };
18
+ }
19
+ );
20
+ });
21
+ }
22
+ };
23
+
24
+ export {
25
+ KnockMcpServer
26
+ };
27
+ //# sourceMappingURL=chunk-XUYE3AGB.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/modelcontextprotocol/adapter.ts"],"sourcesContent":["import { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { z } from \"zod\";\nimport type { KnockTool } from \"../lib/knock-tool.js\";\nimport { Config } from \"../types.js\";\nimport { KnockClient } from \"../lib/knock-client.js\";\n\nexport class KnockMcpServer extends McpServer {\n constructor(knockClient: KnockClient, config: Config, tools: KnockTool[]) {\n super({ name: \"Knock\", version: \"0.1.0\" });\n\n tools.forEach((tool) => {\n const toolParams = tool.parameters ?? z.object({});\n\n this.tool(\n tool.name,\n tool.description,\n toolParams.shape,\n async (arg: unknown) => {\n const res = await tool.bindExecute(knockClient, config)(arg);\n\n return {\n content: [{ type: \"text\" as const, text: JSON.stringify(res) }],\n };\n }\n );\n });\n }\n}\n"],"mappings":";AAAA,SAAS,iBAAiB;AAC1B,SAAS,SAAS;AAKX,IAAM,iBAAN,cAA6B,UAAU;AAAA,EAC5C,YAAY,aAA0B,QAAgB,OAAoB;AACxE,UAAM,EAAE,MAAM,SAAS,SAAS,QAAQ,CAAC;AAEzC,UAAM,QAAQ,CAAC,SAAS;AACtB,YAAM,aAAa,KAAK,cAAc,EAAE,OAAO,CAAC,CAAC;AAEjD,WAAK;AAAA,QACH,KAAK;AAAA,QACL,KAAK;AAAA,QACL,WAAW;AAAA,QACX,OAAO,QAAiB;AACtB,gBAAM,MAAM,MAAM,KAAK,YAAY,aAAa,MAAM,EAAE,GAAG;AAE3D,iBAAO;AAAA,YACL,SAAS,CAAC,EAAE,MAAM,QAAiB,MAAM,KAAK,UAAU,GAAG,EAAE,CAAC;AAAA,UAChE;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AACF;","names":[]}
@@ -1,27 +1,6 @@
1
- // src/lib/knock-client.ts
2
- import { Knock } from "@knocklabs/node";
3
- import KnockMgmt from "@knocklabs/mgmt";
4
- var serviceTokensToApiClients = {};
5
- var createKnockClient = (config) => {
6
- const client = new KnockMgmt({
7
- serviceToken: config.serviceToken
8
- });
9
- return Object.assign(client, {
10
- publicApi: async (_environment) => {
11
- const environment = _environment ?? config.environment ?? "development";
12
- if (serviceTokensToApiClients?.[config.serviceToken]?.[environment]) {
13
- return serviceTokensToApiClients[config.serviceToken][environment];
14
- }
15
- const { api_key } = await client.apiKeys.exchange({ environment });
16
- const knock = new Knock(api_key);
17
- if (!serviceTokensToApiClients[config.serviceToken]) {
18
- serviceTokensToApiClients[config.serviceToken] = {};
19
- }
20
- serviceTokensToApiClients[config.serviceToken][environment] = knock;
21
- return knock;
22
- }
23
- });
24
- };
1
+ import {
2
+ createKnockClient
3
+ } from "../chunk-3LZK6RH6.js";
25
4
  export {
26
5
  createKnockClient
27
6
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/knock-client.ts"],"sourcesContent":["import { Knock } from \"@knocklabs/node\";\nimport KnockMgmt from \"@knocklabs/mgmt\";\nimport { Config } from \"../types.js\";\n\nconst serviceTokensToApiClients: Record<string, Record<string, Knock>> = {};\n\ntype KnockClient = ReturnType<typeof createKnockClient>;\n\nconst createKnockClient = (config: Config) => {\n const client = new KnockMgmt({\n serviceToken: config.serviceToken,\n });\n\n return Object.assign(client, {\n publicApi: async (_environment?: string): Promise<Knock> => {\n const environment = _environment ?? config.environment ?? \"development\";\n\n // If the client already exists for this service token and environment, return it\n if (serviceTokensToApiClients?.[config.serviceToken]?.[environment]) {\n return serviceTokensToApiClients[config.serviceToken][environment];\n }\n\n // Otherwise, fetch a public API key for this service token and environment\n const { api_key } = await client.apiKeys.exchange({ environment });\n\n // Create a new Knock client with the public API key\n const knock = new Knock(api_key);\n\n // Store the client in the cache\n if (!serviceTokensToApiClients[config.serviceToken]) {\n serviceTokensToApiClients[config.serviceToken] = {};\n }\n\n serviceTokensToApiClients[config.serviceToken][environment] = knock;\n\n return knock;\n },\n });\n};\n\nexport { createKnockClient, type KnockClient };\n"],"mappings":";AAAA,SAAS,aAAa;AACtB,OAAO,eAAe;AAGtB,IAAM,4BAAmE,CAAC;AAI1E,IAAM,oBAAoB,CAAC,WAAmB;AAC5C,QAAM,SAAS,IAAI,UAAU;AAAA,IAC3B,cAAc,OAAO;AAAA,EACvB,CAAC;AAED,SAAO,OAAO,OAAO,QAAQ;AAAA,IAC3B,WAAW,OAAO,iBAA0C;AAC1D,YAAM,cAAc,gBAAgB,OAAO,eAAe;AAG1D,UAAI,4BAA4B,OAAO,YAAY,IAAI,WAAW,GAAG;AACnE,eAAO,0BAA0B,OAAO,YAAY,EAAE,WAAW;AAAA,MACnE;AAGA,YAAM,EAAE,QAAQ,IAAI,MAAM,OAAO,QAAQ,SAAS,EAAE,YAAY,CAAC;AAGjE,YAAM,QAAQ,IAAI,MAAM,OAAO;AAG/B,UAAI,CAAC,0BAA0B,OAAO,YAAY,GAAG;AACnD,kCAA0B,OAAO,YAAY,IAAI,CAAC;AAAA,MACpD;AAEA,gCAA0B,OAAO,YAAY,EAAE,WAAW,IAAI;AAE9D,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,28 +1,6 @@
1
- // src/lib/knock-tool.ts
2
- import { z } from "zod";
3
- var trimLines = (text) => text.split("\n").map((l) => l.trim()).filter(Boolean).join("\n");
4
- var KnockTool = (args) => {
5
- const { execute, ...restOfArgs } = args;
6
- const parameters = restOfArgs.parameters ? restOfArgs.parameters : z.object({});
7
- const schemaEntries = Object.entries(parameters.shape);
8
- const argsStr = schemaEntries.length === 0 ? "Takes no arguments" : schemaEntries.map(([key, value]) => {
9
- return `- ${key}: ${value.description || ""}`;
10
- }).join("\n");
11
- const fullDescription = trimLines(`
12
- Tool name:
13
- ${args.name}
14
- Description:
15
- ${args.description}.
16
- Arguments:
17
- ${argsStr}
18
- `);
19
- return {
20
- ...restOfArgs,
21
- parameters,
22
- fullDescription,
23
- bindExecute: (knockClient, config) => execute(knockClient, config)
24
- };
25
- };
1
+ import {
2
+ KnockTool
3
+ } from "../chunk-TOBLV65T.js";
26
4
  export {
27
5
  KnockTool
28
6
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/knock-tool.ts"],"sourcesContent":["import type { ZodObject } from \"zod\";\nimport { z } from \"zod\";\nimport { Config } from \"../types.js\";\nimport { KnockClient } from \"./knock-client.js\";\n\nexport interface KnockToolDefinition {\n /**\n * The method name of the tool. This is a machine-readable string.\n */\n method: string;\n /**\n * The name of the tool. This can be used to reference the tool in the code.\n * A descriptive LLM-readable string.\n */\n name: string;\n\n /**\n * A descriptive prompt explaining the tool's purpose, including examples where useful.\n */\n description: string;\n\n /**\n * A descriptive prompt explaining the tool's purpose, usage and input parameters.\n * Ths is intended to be used by the underlying LLM.\n */\n fullDescription: string;\n\n /**\n * The Zod schema for the input parameters of the tool\n */\n parameters?: ZodObject<any>;\n /**\n * The actual implementation of the tool.\n */\n execute: (\n knockClient: KnockClient,\n config: Config\n ) => (input: any) => Promise<unknown>;\n}\n\nexport interface KnockTool extends Omit<KnockToolDefinition, \"execute\"> {\n bindExecute: (\n knockClient: KnockClient,\n config: Config\n ) => (input: any) => Promise<unknown>;\n}\n\nconst trimLines = (text: string) =>\n text\n .split(\"\\n\")\n .map((l) => l.trim())\n .filter(Boolean)\n .join(\"\\n\");\n\nexport const KnockTool = (\n args: Omit<KnockToolDefinition, \"fullDescription\">\n): KnockTool => {\n const { execute, ...restOfArgs } = args;\n const parameters = restOfArgs.parameters\n ? restOfArgs.parameters\n : z.object({});\n\n const schemaEntries = Object.entries(parameters.shape);\n\n const argsStr =\n schemaEntries.length === 0\n ? \"Takes no arguments\"\n : schemaEntries\n .map(([key, value]) => {\n return `- ${key}: ${(value as any).description || \"\"}`;\n })\n .join(\"\\n\");\n\n const fullDescription = trimLines(`\n Tool name:\n ${args.name}\n Description:\n ${args.description}.\n Arguments:\n ${argsStr}\n `);\n\n return {\n ...restOfArgs,\n parameters,\n fullDescription,\n bindExecute: (knockClient: KnockClient, config: Config) =>\n execute(knockClient, config),\n };\n};\n"],"mappings":";AACA,SAAS,SAAS;AA8ClB,IAAM,YAAY,CAAC,SACjB,KACG,MAAM,IAAI,EACV,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,EACnB,OAAO,OAAO,EACd,KAAK,IAAI;AAEP,IAAM,YAAY,CACvB,SACc;AACd,QAAM,EAAE,SAAS,GAAG,WAAW,IAAI;AACnC,QAAM,aAAa,WAAW,aAC1B,WAAW,aACX,EAAE,OAAO,CAAC,CAAC;AAEf,QAAM,gBAAgB,OAAO,QAAQ,WAAW,KAAK;AAErD,QAAM,UACJ,cAAc,WAAW,IACrB,uBACA,cACG,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM;AACrB,WAAO,KAAK,GAAG,KAAM,MAAc,eAAe,EAAE;AAAA,EACtD,CAAC,EACA,KAAK,IAAI;AAElB,QAAM,kBAAkB,UAAU;AAAA;AAAA,IAEhC,KAAK,IAAI;AAAA;AAAA,IAET,KAAK,WAAW;AAAA;AAAA,IAEhB,OAAO;AAAA,GACR;AAED,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA;AAAA,IACA,aAAa,CAAC,aAA0B,WACtC,QAAQ,aAAa,MAAM;AAAA,EAC/B;AACF;","names":[]}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}