@knocklabs/agent-toolkit 0.1.0

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 (76) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +156 -0
  3. package/dist/ai-sdk/index.d.ts +21 -0
  4. package/dist/ai-sdk/index.js +1108 -0
  5. package/dist/ai-sdk/index.js.map +1 -0
  6. package/dist/ai-sdk/tool-converter.d.ts +12 -0
  7. package/dist/ai-sdk/tool-converter.js +14 -0
  8. package/dist/ai-sdk/tool-converter.js.map +1 -0
  9. package/dist/index.d.ts +2 -0
  10. package/dist/index.js +1 -0
  11. package/dist/index.js.map +1 -0
  12. package/dist/lib/knock-client.d.ts +4 -0
  13. package/dist/lib/knock-client.js +28 -0
  14. package/dist/lib/knock-client.js.map +1 -0
  15. package/dist/lib/knock-tool.d.ts +4 -0
  16. package/dist/lib/knock-tool.js +29 -0
  17. package/dist/lib/knock-tool.js.map +1 -0
  18. package/dist/lib/tools/channels.d.ts +13 -0
  19. package/dist/lib/tools/channels.js +52 -0
  20. package/dist/lib/tools/channels.js.map +1 -0
  21. package/dist/lib/tools/commits.d.ts +16 -0
  22. package/dist/lib/tools/commits.js +98 -0
  23. package/dist/lib/tools/commits.js.map +1 -0
  24. package/dist/lib/tools/email-layouts.d.ts +13 -0
  25. package/dist/lib/tools/email-layouts.js +60 -0
  26. package/dist/lib/tools/email-layouts.js.map +1 -0
  27. package/dist/lib/tools/environments.d.ts +13 -0
  28. package/dist/lib/tools/environments.js +52 -0
  29. package/dist/lib/tools/environments.js.map +1 -0
  30. package/dist/lib/tools/index.d.ts +4 -0
  31. package/dist/lib/tools/index.js +1020 -0
  32. package/dist/lib/tools/index.js.map +1 -0
  33. package/dist/lib/tools/message-types.d.ts +15 -0
  34. package/dist/lib/tools/message-types.js +214 -0
  35. package/dist/lib/tools/message-types.js.map +1 -0
  36. package/dist/lib/tools/messages.d.ts +13 -0
  37. package/dist/lib/tools/messages.js +55 -0
  38. package/dist/lib/tools/messages.js.map +1 -0
  39. package/dist/lib/tools/objects.d.ts +19 -0
  40. package/dist/lib/tools/objects.js +163 -0
  41. package/dist/lib/tools/objects.js.map +1 -0
  42. package/dist/lib/tools/partials.d.ts +13 -0
  43. package/dist/lib/tools/partials.js +60 -0
  44. package/dist/lib/tools/partials.js.map +1 -0
  45. package/dist/lib/tools/tenants.d.ts +16 -0
  46. package/dist/lib/tools/tenants.js +98 -0
  47. package/dist/lib/tools/tenants.js.map +1 -0
  48. package/dist/lib/tools/users.d.ts +19 -0
  49. package/dist/lib/tools/users.js +233 -0
  50. package/dist/lib/tools/users.js.map +1 -0
  51. package/dist/lib/tools/workflows.d.ts +18 -0
  52. package/dist/lib/tools/workflows.js +207 -0
  53. package/dist/lib/tools/workflows.js.map +1 -0
  54. package/dist/lib/utils.d.ts +33 -0
  55. package/dist/lib/utils.js +1075 -0
  56. package/dist/lib/utils.js.map +1 -0
  57. package/dist/modelcontextprotocol/adapter.d.ts +11 -0
  58. package/dist/modelcontextprotocol/adapter.js +26 -0
  59. package/dist/modelcontextprotocol/adapter.js.map +1 -0
  60. package/dist/modelcontextprotocol/index.d.ts +27 -0
  61. package/dist/modelcontextprotocol/index.js +978 -0
  62. package/dist/modelcontextprotocol/index.js.map +1 -0
  63. package/dist/modelcontextprotocol/local-server.d.ts +1 -0
  64. package/dist/modelcontextprotocol/local-server.js +1100 -0
  65. package/dist/modelcontextprotocol/local-server.js.map +1 -0
  66. package/dist/openai/index.d.ts +36 -0
  67. package/dist/openai/index.js +1151 -0
  68. package/dist/openai/index.js.map +1 -0
  69. package/dist/openai/tool-converter.d.ts +15 -0
  70. package/dist/openai/tool-converter.js +18 -0
  71. package/dist/openai/tool-converter.js.map +1 -0
  72. package/dist/types-B-9pppCQ.d.ts +199 -0
  73. package/dist/types.d.ts +4 -0
  74. package/dist/types.js +1 -0
  75. package/dist/types.js.map +1 -0
  76. package/package.json +73 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Knock Labs, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,156 @@
1
+ # Knock Agent Toolkit (Beta)
2
+
3
+ ## Table of contents
4
+
5
+ - [Getting started](#getting-started)
6
+ - [API reference](#api-reference)
7
+ - [Prerequisites](#prerequisites)
8
+ - [Available tools](#available-tools)
9
+ - [Context](#context)
10
+ - [Usage](#usage)
11
+ - [Model Context Protocol (MCP)](#model-context-protocol-mcp)
12
+ - [AI SDK](#ai-sdk)
13
+ - [OpenAI](#openai)
14
+
15
+ ## Getting started
16
+
17
+ The Knock Agent toolkit enables popular agent frameworks including [OpenAI](https://platform.openai.com/docs/guides/function-calling?api-mode=chat&lang=javascript) and [Vercel's AI SDK](https://sdk.vercel.ai/) to integrate with Knock's APIs using tools (otherwise known as function calling). It also allows you to integrate Knock into a Model Context Protocol (MCP) client such as Cursor, Windsurf, or Claude Code.
18
+
19
+ Using the Knock agent toolkit allows you to build powerful agent systems that are capable of sending cross-channel notifications to the humans who need to be in the loop. As a developer, it also helps you build Knock integrations and manage your Knock account.
20
+
21
+ ## API reference
22
+
23
+ The Knock Agent Toolkit provides three main entry points:
24
+
25
+ - `@knocklabs/agent-toolkit/ai-sdk`: Helpers for integrating with Vercel's AI SDK.
26
+ - `@knocklabs/agent-toolkit/openai`: Helpers for integrating with the OpenAI SDK.
27
+ - `@knocklabs/agent-toolkit/modelcontextprotocol`: Low level helpers for integrating with the Model Context Protocol (MCP).
28
+
29
+ ## Prerequisites
30
+
31
+ - You must have a [Knock account](https://dashboard.knock.app/signup).
32
+ - You must have a [service token generated](https://docs.knock.app/developer-tools/service-tokens) on your Knock account. The Knock agent toolkit uses your service token to interact with your Knock account.
33
+
34
+ ## Available tools
35
+
36
+ The agent toolkit exposes a large subset of the [Knock Management API](https://docs.knock.app/mapi) and [API](https://docs.knock.app/reference) that you might need to invoke via an agent. You can see the full list of tools in the source code.
37
+
38
+ ## Context
39
+
40
+ It's possible to pass additional context to the configuration of each library to help scope the calls made by the agent toolkit to Knock. The available properties to configure are:
41
+
42
+ - `environment`: The slug of the Knock environment you wish to execute actions in by default, such as `development`.
43
+ - `userId`: The user ID of the current user. When set, this will be the default passed to user tools.
44
+ - `tenantId`: The ID of the current tenant. When set, will be the default passed to any tool that accepts the tenant.
45
+
46
+ ## Usage
47
+
48
+ ### Model Context Protocol (MCP)
49
+
50
+ To start using the Knock MCP as a local server, you must start it with a service token. You can run it using `npx`.
51
+
52
+ ```
53
+ npx -y @knocklabs/agent-toolkit -p local-mcp --service-token kst_12345
54
+ ```
55
+
56
+ By default, the MCP server will expose **all tools** to the LLM. To limit the tools available you can use the `--tools` (`-t`) flag:
57
+
58
+ ```
59
+ // Pass all tools
60
+ npx -y @knocklabs/agent-toolkit -p local-mcp --tools="*"
61
+
62
+ // Specific category
63
+ npx -y @knocklabs/agent-toolkit -p local-mcp --tools "workflows.*"
64
+
65
+ // Specific tools
66
+ npx -y @knocklabs/agent-toolkit -p local-mcp --tools "workflows.triggerWorkflow"
67
+ ```
68
+
69
+ It's also possible to pass `environment`, `userId`, and `tenant` to the local MCP server to set default values. Use the `--help` flag to view additional server options.
70
+
71
+ ### AI SDK
72
+
73
+ The agent toolkit provides a `createKnockToolkit` under the `/ai-sdk` path for easily integrating into the AI SDK and returning tools ready for use.
74
+
75
+ 1. Install the package:
76
+
77
+ ```
78
+ npm install @knocklabs/agent-toolkit
79
+ ```
80
+
81
+ 2. Import the `createKnockToolkit` helper, configure it, and use it in your LLM calling:
82
+
83
+ ```typescript
84
+ import { createKnockToolkit } from "@knocklabs/agent-toolkit/ai-sdk";
85
+ import { openai } from "@ai-sdk/openai";
86
+ import { streamText } from "ai";
87
+ import { auth } from "@clerk/nextjs/server";
88
+ import { systemPrompt } from "@/lib/ai/prompts";
89
+
90
+ export const maxDuration = 30;
91
+
92
+ export async function POST(req: Request) {
93
+ const { messages } = await req.json();
94
+
95
+ const toolkit = await createKnockToolkit({
96
+ serviceToken: "kst_12345",
97
+ permissions: {
98
+ workflows: { read: true, trigger: true, manage: true },
99
+ },
100
+ });
101
+
102
+ const result = streamText({
103
+ model: openai("gpt-4o"),
104
+ messages,
105
+ tools: {
106
+ // The tools given here are determined by the `permissions`
107
+ // list above in the configuration. For instance, here we're only
108
+ // allowing the workflows
109
+ ...toolkit.getAllTools(),
110
+ },
111
+ });
112
+
113
+ return result.toDataStreamResponse();
114
+ }
115
+ ```
116
+
117
+ ### OpenAI
118
+
119
+ The agent toolkit provides a `createKnockToolkit` under the `/openai` path for easily integrating into the Open AI SDK and returning tools ready for use.
120
+
121
+ 1. Install the package:
122
+
123
+ ```
124
+ npm install @knocklabs/agent-toolkit
125
+ ```
126
+
127
+ 2. Import the `createKnockToolkit` helper, configure it, and use it in your LLM calling:
128
+
129
+ ```typescript
130
+ import { createKnockToolkit } from "@knocklabs/agent-toolkit/openai";
131
+ import OpenAI from "openai";
132
+
133
+ const openai = new OpenAI();
134
+
135
+ const toolkit = await createKnockToolkit({
136
+ serviceToken: "kst_12345",
137
+ permissions: {
138
+ // Set the permissions of the tools to expose
139
+ workflows: { read: true, trigger: true, manage: true },
140
+ },
141
+ });
142
+
143
+ const completion = await openai.chat.completions.create({
144
+ model: "gpt-4o",
145
+ messages,
146
+ // The tools given here are determined by the `permissions`
147
+ // list above in the configuration. For instance, here we're only
148
+ // allowing the workflows
149
+ tools: toolkit.getAllTools(),
150
+ });
151
+
152
+ // Execute the tool calls
153
+ const toolMessages = await Promise.all(
154
+ message.tool_calls.map((tc) => toolkit.handleToolCall(tc))
155
+ );
156
+ ```
@@ -0,0 +1,21 @@
1
+ import { T as ToolkitConfig, t as toolPermissions } from '../types-B-9pppCQ.js';
2
+ import { Tool } from 'ai';
3
+ import 'zod';
4
+ import '@knocklabs/node';
5
+ import '@knocklabs/mgmt';
6
+
7
+ declare const createKnockToolkit: (config: ToolkitConfig) => {
8
+ /**
9
+ * Get all tools for all categories
10
+ * @returns An array of all tools
11
+ */
12
+ getAllTools: () => Tool[];
13
+ /**
14
+ * Get all tools for a specific category
15
+ * @param category - The category of tools to get
16
+ * @returns An array of tools for the given category
17
+ */
18
+ getTools: (category: keyof typeof toolPermissions) => Tool[];
19
+ };
20
+
21
+ export { createKnockToolkit };