7
*/
8
import ComposioClient from '@composio/client';
9
import {
10
+ CustomToolkitCreateParams,
11
+ CustomToolkitCreateParamsSchema,
12
+ CustomToolkitCreateResponse,
13
CustomToolkitDeleteResponse,
14
CustomToolkitSyncParams,
15
CustomToolkitSyncParamsSchema,
16
CustomToolkitSyncResponse,
17
+ CustomToolkitUpdateParams,
18
+ CustomToolkitUpdateParamsSchema,
19
+ CustomToolkitUpdateResponse,
20
CustomToolkitUpsertParams,
21
CustomToolkitUpsertParamsSchema,
22
CustomToolkitUpsertResponse,
25
import { ValidationError } from '../errors/ValidationErrors';
26
import { telemetry } from '../telemetry/Telemetry';
27
import { withCancellation } from '../utils/cancellation';
28
+import logger from '../utils/logger';
29
import {
30
+ transformCustomToolkitCreateParams,
31
+ transformCustomToolkitCreateResponse,
32
transformCustomToolkitDeleteResponse,
33
transformCustomToolkitSyncParams,
34
transformCustomToolkitSyncResponse,
35
+ transformCustomToolkitUpdateParams,
36
+ transformCustomToolkitUpdateResponse,
37
transformCustomToolkitUpsertParams,
38
transformCustomToolkitUpsertResponse,
39
} from '../utils/transformers/customToolkits';
40
41
+const UPSERT_DEPRECATION =
42
+ '[Deprecation] composio.experimental.customToolkits.upsert() is deprecated. ' +
43
+ 'Use create() for a new toolkit and update(slug, ...) to change its name, logo or API key field.';
44
+let _upsertDeprecationWarned = false;
45
+
46
/**
47
* `composio.experimental.customToolkits` — toolkits your project registers
48
* from its own app or MCP server, with their own auth configs and connected
54
*
55
* @example
56
* ```typescript
41
- * const { slug } = await composio.experimental.customToolkits.upsert({
42
- * slug: 'MY_TOOLKIT',
43
- * toolkitConfig: {
44
- * name: 'My Toolkit',
45
- * appUrl: 'https://mcp.example.com/mcp',
46
- * authSchemes: [{ mode: 'DCR_OAUTH', discoveryUrl: 'https://mcp.example.com/.well-known/oauth-authorization-server' }],
47
- * },
57
+ * const { slug } = await composio.experimental.customToolkits.create({
58
+ * name: 'My Toolkit',
59
+ * appUrl: 'https://mcp.example.com/mcp',
60
+ * authSchemes: [{ mode: 'DCR_OAUTH', discoveryUrl: 'https://mcp.example.com/.well-known/oauth-authorization-server' }],
61
+ * userId: 'all',
62
* });
49
- * await composio.experimental.customToolkits.sync(slug);
63
+ * await composio.experimental.customToolkits.update(slug, { name: 'My Renamed Toolkit' });
64
* ```
65
*/
66
export class CustomToolkits {
71
telemetry.instrument(this, 'CustomToolkits');
72
}
73
74
+ /**
75
+ * Creates a custom MCP toolkit and returns its generated slug.
76
+ * **Experimental — custom toolkits are in pilot; shape may change.**
77
+ *
78
+ * Set `userId` to `'all'` to share the toolkit with every user in the
79
+ * project, or to a user ID to make it private to that user. `appUrl`,
80
+ * `authSchemes` and `userId` cannot change later: delete and re-create the
81
+ * toolkit instead. For a private toolkit, `connectLink` is where to send
82
+ * that user to connect.
83
+ *
84
+ * @param {CustomToolkitCreateParams} params - The toolkit to create
85
+ * @returns {Promise<CustomToolkitCreateResponse>} The toolkit's slug and, for a private toolkit, a connect link
86
+ * @throws {ValidationError} If the params fail validation
87
+ *
88
+ * @example
89
+ * ```typescript
90
+ * const { slug, connectLink } = await composio.experimental.customToolkits.create({
91
+ * name: 'Internal API',
92
+ * appUrl: 'https://mcp.internal.example.com/mcp',
93
+ * authSchemes: [
94
+ * { mode: 'API_KEY', headers: { Authorization: 'Bearer {{generic_api_key}}' } },
95
+ * ],
96
+ * userId: 'user_123',
97
+ * });
98
+ * ```
99
+ */
100
+ async create(
101
+ params: CustomToolkitCreateParams,
102
+ requestOptions?: ComposioRequestOptions
103
+ ): Promise<CustomToolkitCreateResponse> {
104
+ const parsedParams = CustomToolkitCreateParamsSchema.safeParse(params);
105
+ if (!parsedParams.success) {
106
+ throw new ValidationError('Failed to parse custom toolkit create params', {
107
+ cause: parsedParams.error,
108
+ });
109
+ }
110
+ const body = transformCustomToolkitCreateParams(parsedParams.data);
111
+ const result = await withCancellation(
112
+ () => this.client.custom.createToolkit(body, requestOptions),
113
+ requestOptions?.signal
114
+ );
115
+ return transformCustomToolkitCreateResponse(result);
116
+ }
117
+
118
+ /**
119
+ * Updates a custom toolkit's name, logo or API key field copy. Omitted
120
+ * fields keep their current value.
121
+ * **Experimental — custom toolkits are in pilot; shape may change.**
122
+ *
123
+ * On a project with 2FA enabled, updating a private toolkit requires the
124
+ * `userId` it is private to.
125
+ *
126
+ * @param {string} slug - The custom toolkit slug returned by `create()`
127
+ * @param {CustomToolkitUpdateParams} params - At least one of `name`, `logoFile`, `apiKeyField`
128
+ * @returns {Promise<CustomToolkitUpdateResponse>} `{ success: true }`
129
+ * @throws {ValidationError} If the params fail validation
130
+ *
131
+ * @example
132
+ * ```typescript
133
+ * await composio.experimental.customToolkits.update('CUSTOM_INTERNAL_API_K7F2Q', {
134
+ * name: 'Internal API (prod)',
135
+ * userId: 'user_123',
136
+ * });
137
+ * ```
138
+ */
139
+ async update(
140
+ slug: string,
141
+ params: CustomToolkitUpdateParams,
142
+ requestOptions?: ComposioRequestOptions
143
+ ): Promise<CustomToolkitUpdateResponse> {
144
+ const parsedParams = CustomToolkitUpdateParamsSchema.safeParse(params);
145
+ if (!parsedParams.success) {
146
+ throw new ValidationError('Failed to parse custom toolkit update params', {
147
+ cause: parsedParams.error,
148
+ });
149
+ }
150
+ const body = transformCustomToolkitUpdateParams(parsedParams.data);
151
+ const result = await withCancellation(
152
+ () => this.client.custom.updateToolkits(slug, body, requestOptions),
153
+ requestOptions?.signal
154
+ );
155
+ return transformCustomToolkitUpdateResponse(result);
156
+ }
157
+
158
/**
159
* Creates a custom toolkit, or updates its display metadata (name, API key
160
* field copy) when the project already owns a toolkit with this slug.
181
* },
182
* });
183
* ```
184
+ *
185
+ * @deprecated Use `create()` for a new toolkit and `update(slug, ...)` to change
186
+ * its name, logo or API key field. `create()` generates the slug, so store the
187
+ * slug it returns.
188
*/
189
async upsert(
190
params: CustomToolkitUpsertParams,
191
requestOptions?: ComposioRequestOptions
192
): Promise<CustomToolkitUpsertResponse> {
193
+ if (!_upsertDeprecationWarned) {
194
+ _upsertDeprecationWarned = true;
195
+ logger.warn(UPSERT_DEPRECATION);
196
+ }
197
const parsedParams = CustomToolkitUpsertParamsSchema.safeParse(params);
198
if (!parsedParams.success) {
199
throw new ValidationError('Failed to parse custom toolkit upsert params', {