@imagekit/api-mcp 7.2.2 → 7.4.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 (144) hide show
  1. package/auth.d.mts +6 -0
  2. package/auth.d.mts.map +1 -0
  3. package/auth.d.ts +6 -0
  4. package/auth.d.ts.map +1 -0
  5. package/{headers.mjs → auth.js} +21 -2
  6. package/auth.js.map +1 -0
  7. package/{headers.js → auth.mjs} +16 -6
  8. package/auth.mjs.map +1 -0
  9. package/code-tool-paths.cjs +8 -0
  10. package/code-tool-paths.cjs.map +1 -0
  11. package/code-tool-paths.d.cts +2 -0
  12. package/code-tool-paths.d.cts.map +1 -0
  13. package/code-tool-types.d.mts.map +1 -1
  14. package/code-tool-types.d.ts.map +1 -1
  15. package/code-tool-worker.d.mts +5 -0
  16. package/code-tool-worker.d.mts.map +1 -0
  17. package/code-tool-worker.d.ts +5 -0
  18. package/code-tool-worker.d.ts.map +1 -0
  19. package/code-tool-worker.js +314 -0
  20. package/code-tool-worker.js.map +1 -0
  21. package/code-tool-worker.mjs +276 -0
  22. package/code-tool-worker.mjs.map +1 -0
  23. package/code-tool.d.mts +11 -2
  24. package/code-tool.d.mts.map +1 -1
  25. package/code-tool.d.ts +11 -2
  26. package/code-tool.d.ts.map +1 -1
  27. package/code-tool.js +285 -42
  28. package/code-tool.js.map +1 -1
  29. package/code-tool.mjs +253 -43
  30. package/code-tool.mjs.map +1 -1
  31. package/docs-search-tool.d.mts +11 -3
  32. package/docs-search-tool.d.mts.map +1 -1
  33. package/docs-search-tool.d.ts +11 -3
  34. package/docs-search-tool.d.ts.map +1 -1
  35. package/docs-search-tool.js +58 -5
  36. package/docs-search-tool.js.map +1 -1
  37. package/docs-search-tool.mjs +57 -5
  38. package/docs-search-tool.mjs.map +1 -1
  39. package/http.d.mts +6 -3
  40. package/http.d.mts.map +1 -1
  41. package/http.d.ts +6 -3
  42. package/http.d.ts.map +1 -1
  43. package/http.js +130 -28
  44. package/http.js.map +1 -1
  45. package/http.mjs +130 -28
  46. package/http.mjs.map +1 -1
  47. package/index.js +17 -12
  48. package/index.js.map +1 -1
  49. package/index.mjs +17 -12
  50. package/index.mjs.map +1 -1
  51. package/instructions.d.mts +5 -0
  52. package/instructions.d.mts.map +1 -0
  53. package/instructions.d.ts +5 -0
  54. package/instructions.d.ts.map +1 -0
  55. package/instructions.js +61 -0
  56. package/instructions.js.map +1 -0
  57. package/instructions.mjs +55 -0
  58. package/instructions.mjs.map +1 -0
  59. package/local-docs-search.d.mts +28 -0
  60. package/local-docs-search.d.mts.map +1 -0
  61. package/local-docs-search.d.ts +28 -0
  62. package/local-docs-search.d.ts.map +1 -0
  63. package/local-docs-search.js +2807 -0
  64. package/local-docs-search.js.map +1 -0
  65. package/local-docs-search.mjs +2767 -0
  66. package/local-docs-search.mjs.map +1 -0
  67. package/logger.d.mts +7 -0
  68. package/logger.d.mts.map +1 -0
  69. package/logger.d.ts +7 -0
  70. package/logger.d.ts.map +1 -0
  71. package/logger.js +29 -0
  72. package/logger.js.map +1 -0
  73. package/logger.mjs +22 -0
  74. package/logger.mjs.map +1 -0
  75. package/methods.d.mts +10 -0
  76. package/methods.d.mts.map +1 -0
  77. package/methods.d.ts +10 -0
  78. package/methods.d.ts.map +1 -0
  79. package/methods.js +349 -0
  80. package/methods.js.map +1 -0
  81. package/methods.mjs +345 -0
  82. package/methods.mjs.map +1 -0
  83. package/options.d.mts +12 -0
  84. package/options.d.mts.map +1 -1
  85. package/options.d.ts +12 -0
  86. package/options.d.ts.map +1 -1
  87. package/options.js +81 -12
  88. package/options.js.map +1 -1
  89. package/options.mjs +81 -12
  90. package/options.mjs.map +1 -1
  91. package/package.json +89 -15
  92. package/server.d.mts +18 -11
  93. package/server.d.mts.map +1 -1
  94. package/server.d.ts +18 -11
  95. package/server.d.ts.map +1 -1
  96. package/server.js +89 -49
  97. package/server.js.map +1 -1
  98. package/server.mjs +88 -45
  99. package/server.mjs.map +1 -1
  100. package/src/{headers.ts → auth.ts} +18 -1
  101. package/src/code-tool-paths.cts +5 -0
  102. package/src/code-tool-types.ts +1 -0
  103. package/src/code-tool-worker.ts +327 -0
  104. package/src/code-tool.ts +339 -55
  105. package/src/docs-search-tool.ts +86 -7
  106. package/src/http.ts +154 -33
  107. package/src/index.ts +19 -13
  108. package/src/instructions.ts +83 -0
  109. package/src/local-docs-search.ts +3380 -0
  110. package/src/logger.ts +28 -0
  111. package/src/methods.ts +370 -0
  112. package/src/options.ts +105 -12
  113. package/src/server.ts +111 -57
  114. package/src/stdio.ts +9 -4
  115. package/src/types.ts +15 -4
  116. package/src/util.ts +25 -0
  117. package/stdio.d.mts +2 -1
  118. package/stdio.d.mts.map +1 -1
  119. package/stdio.d.ts +2 -1
  120. package/stdio.d.ts.map +1 -1
  121. package/stdio.js +8 -4
  122. package/stdio.js.map +1 -1
  123. package/stdio.mjs +8 -4
  124. package/stdio.mjs.map +1 -1
  125. package/types.d.mts +14 -1
  126. package/types.d.mts.map +1 -1
  127. package/types.d.ts +14 -1
  128. package/types.d.ts.map +1 -1
  129. package/types.js.map +1 -1
  130. package/types.mjs.map +1 -1
  131. package/util.d.mts +4 -0
  132. package/util.d.mts.map +1 -0
  133. package/util.d.ts +4 -0
  134. package/util.d.ts.map +1 -0
  135. package/util.js +30 -0
  136. package/util.js.map +1 -0
  137. package/util.mjs +24 -0
  138. package/util.mjs.map +1 -0
  139. package/headers.d.mts +0 -4
  140. package/headers.d.mts.map +0 -1
  141. package/headers.d.ts +0 -4
  142. package/headers.d.ts.map +0 -1
  143. package/headers.js.map +0 -1
  144. package/headers.mjs.map +0 -1
package/src/logger.ts ADDED
@@ -0,0 +1,28 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { pino, type Level, type Logger } from 'pino';
4
+ import pretty from 'pino-pretty';
5
+
6
+ let _logger: Logger | undefined;
7
+
8
+ export function configureLogger({ level, pretty: usePretty }: { level: Level; pretty: boolean }): void {
9
+ _logger = pino(
10
+ {
11
+ level,
12
+ timestamp: pino.stdTimeFunctions.isoTime,
13
+ formatters: {
14
+ level(label) {
15
+ return { level: label };
16
+ },
17
+ },
18
+ },
19
+ usePretty ? pretty({ colorize: true, levelFirst: true, destination: 2 }) : process.stderr,
20
+ );
21
+ }
22
+
23
+ export function getLogger(): Logger {
24
+ if (!_logger) {
25
+ throw new Error('Logger has not been configured. Call configureLogger() before using the logger.');
26
+ }
27
+ return _logger;
28
+ }
package/src/methods.ts ADDED
@@ -0,0 +1,370 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { McpOptions } from './options';
4
+
5
+ export type SdkMethod = {
6
+ clientCallName: string;
7
+ fullyQualifiedName: string;
8
+ httpMethod?: 'get' | 'post' | 'put' | 'patch' | 'delete' | 'query';
9
+ httpPath?: string;
10
+ };
11
+
12
+ export const sdkMethods: SdkMethod[] = [
13
+ {
14
+ clientCallName: 'client.customMetadataFields.create',
15
+ fullyQualifiedName: 'customMetadataFields.create',
16
+ httpMethod: 'post',
17
+ httpPath: '/v1/customMetadataFields',
18
+ },
19
+ {
20
+ clientCallName: 'client.customMetadataFields.update',
21
+ fullyQualifiedName: 'customMetadataFields.update',
22
+ httpMethod: 'patch',
23
+ httpPath: '/v1/customMetadataFields/{id}',
24
+ },
25
+ {
26
+ clientCallName: 'client.customMetadataFields.list',
27
+ fullyQualifiedName: 'customMetadataFields.list',
28
+ httpMethod: 'get',
29
+ httpPath: '/v1/customMetadataFields',
30
+ },
31
+ {
32
+ clientCallName: 'client.customMetadataFields.delete',
33
+ fullyQualifiedName: 'customMetadataFields.delete',
34
+ httpMethod: 'delete',
35
+ httpPath: '/v1/customMetadataFields/{id}',
36
+ },
37
+ {
38
+ clientCallName: 'client.files.update',
39
+ fullyQualifiedName: 'files.update',
40
+ httpMethod: 'patch',
41
+ httpPath: '/v1/files/{fileId}/details',
42
+ },
43
+ {
44
+ clientCallName: 'client.files.delete',
45
+ fullyQualifiedName: 'files.delete',
46
+ httpMethod: 'delete',
47
+ httpPath: '/v1/files/{fileId}',
48
+ },
49
+ {
50
+ clientCallName: 'client.files.copy',
51
+ fullyQualifiedName: 'files.copy',
52
+ httpMethod: 'post',
53
+ httpPath: '/v1/files/copy',
54
+ },
55
+ {
56
+ clientCallName: 'client.files.get',
57
+ fullyQualifiedName: 'files.get',
58
+ httpMethod: 'get',
59
+ httpPath: '/v1/files/{fileId}/details',
60
+ },
61
+ {
62
+ clientCallName: 'client.files.move',
63
+ fullyQualifiedName: 'files.move',
64
+ httpMethod: 'post',
65
+ httpPath: '/v1/files/move',
66
+ },
67
+ {
68
+ clientCallName: 'client.files.rename',
69
+ fullyQualifiedName: 'files.rename',
70
+ httpMethod: 'put',
71
+ httpPath: '/v1/files/rename',
72
+ },
73
+ {
74
+ clientCallName: 'client.files.upload',
75
+ fullyQualifiedName: 'files.upload',
76
+ httpMethod: 'post',
77
+ httpPath: '/api/v1/files/upload',
78
+ },
79
+ {
80
+ clientCallName: 'client.files.bulk.delete',
81
+ fullyQualifiedName: 'files.bulk.delete',
82
+ httpMethod: 'post',
83
+ httpPath: '/v1/files/batch/deleteByFileIds',
84
+ },
85
+ {
86
+ clientCallName: 'client.files.bulk.addTags',
87
+ fullyQualifiedName: 'files.bulk.addTags',
88
+ httpMethod: 'post',
89
+ httpPath: '/v1/files/addTags',
90
+ },
91
+ {
92
+ clientCallName: 'client.files.bulk.removeAITags',
93
+ fullyQualifiedName: 'files.bulk.removeAITags',
94
+ httpMethod: 'post',
95
+ httpPath: '/v1/files/removeAITags',
96
+ },
97
+ {
98
+ clientCallName: 'client.files.bulk.removeTags',
99
+ fullyQualifiedName: 'files.bulk.removeTags',
100
+ httpMethod: 'post',
101
+ httpPath: '/v1/files/removeTags',
102
+ },
103
+ {
104
+ clientCallName: 'client.files.versions.list',
105
+ fullyQualifiedName: 'files.versions.list',
106
+ httpMethod: 'get',
107
+ httpPath: '/v1/files/{fileId}/versions',
108
+ },
109
+ {
110
+ clientCallName: 'client.files.versions.delete',
111
+ fullyQualifiedName: 'files.versions.delete',
112
+ httpMethod: 'delete',
113
+ httpPath: '/v1/files/{fileId}/versions/{versionId}',
114
+ },
115
+ {
116
+ clientCallName: 'client.files.versions.get',
117
+ fullyQualifiedName: 'files.versions.get',
118
+ httpMethod: 'get',
119
+ httpPath: '/v1/files/{fileId}/versions/{versionId}',
120
+ },
121
+ {
122
+ clientCallName: 'client.files.versions.restore',
123
+ fullyQualifiedName: 'files.versions.restore',
124
+ httpMethod: 'put',
125
+ httpPath: '/v1/files/{fileId}/versions/{versionId}/restore',
126
+ },
127
+ {
128
+ clientCallName: 'client.files.metadata.get',
129
+ fullyQualifiedName: 'files.metadata.get',
130
+ httpMethod: 'get',
131
+ httpPath: '/v1/files/{fileId}/metadata',
132
+ },
133
+ {
134
+ clientCallName: 'client.files.metadata.getFromURL',
135
+ fullyQualifiedName: 'files.metadata.getFromURL',
136
+ httpMethod: 'get',
137
+ httpPath: '/v1/metadata',
138
+ },
139
+ {
140
+ clientCallName: 'client.savedExtensions.create',
141
+ fullyQualifiedName: 'savedExtensions.create',
142
+ httpMethod: 'post',
143
+ httpPath: '/v1/saved-extensions',
144
+ },
145
+ {
146
+ clientCallName: 'client.savedExtensions.update',
147
+ fullyQualifiedName: 'savedExtensions.update',
148
+ httpMethod: 'patch',
149
+ httpPath: '/v1/saved-extensions/{id}',
150
+ },
151
+ {
152
+ clientCallName: 'client.savedExtensions.list',
153
+ fullyQualifiedName: 'savedExtensions.list',
154
+ httpMethod: 'get',
155
+ httpPath: '/v1/saved-extensions',
156
+ },
157
+ {
158
+ clientCallName: 'client.savedExtensions.delete',
159
+ fullyQualifiedName: 'savedExtensions.delete',
160
+ httpMethod: 'delete',
161
+ httpPath: '/v1/saved-extensions/{id}',
162
+ },
163
+ {
164
+ clientCallName: 'client.savedExtensions.get',
165
+ fullyQualifiedName: 'savedExtensions.get',
166
+ httpMethod: 'get',
167
+ httpPath: '/v1/saved-extensions/{id}',
168
+ },
169
+ {
170
+ clientCallName: 'client.assets.list',
171
+ fullyQualifiedName: 'assets.list',
172
+ httpMethod: 'get',
173
+ httpPath: '/v1/files',
174
+ },
175
+ {
176
+ clientCallName: 'client.cache.invalidation.create',
177
+ fullyQualifiedName: 'cache.invalidation.create',
178
+ httpMethod: 'post',
179
+ httpPath: '/v1/files/purge',
180
+ },
181
+ {
182
+ clientCallName: 'client.cache.invalidation.get',
183
+ fullyQualifiedName: 'cache.invalidation.get',
184
+ httpMethod: 'get',
185
+ httpPath: '/v1/files/purge/{requestId}',
186
+ },
187
+ {
188
+ clientCallName: 'client.folders.create',
189
+ fullyQualifiedName: 'folders.create',
190
+ httpMethod: 'post',
191
+ httpPath: '/v1/folder',
192
+ },
193
+ {
194
+ clientCallName: 'client.folders.delete',
195
+ fullyQualifiedName: 'folders.delete',
196
+ httpMethod: 'delete',
197
+ httpPath: '/v1/folder',
198
+ },
199
+ {
200
+ clientCallName: 'client.folders.copy',
201
+ fullyQualifiedName: 'folders.copy',
202
+ httpMethod: 'post',
203
+ httpPath: '/v1/bulkJobs/copyFolder',
204
+ },
205
+ {
206
+ clientCallName: 'client.folders.move',
207
+ fullyQualifiedName: 'folders.move',
208
+ httpMethod: 'post',
209
+ httpPath: '/v1/bulkJobs/moveFolder',
210
+ },
211
+ {
212
+ clientCallName: 'client.folders.rename',
213
+ fullyQualifiedName: 'folders.rename',
214
+ httpMethod: 'post',
215
+ httpPath: '/v1/bulkJobs/renameFolder',
216
+ },
217
+ {
218
+ clientCallName: 'client.folders.job.get',
219
+ fullyQualifiedName: 'folders.job.get',
220
+ httpMethod: 'get',
221
+ httpPath: '/v1/bulkJobs/{jobId}',
222
+ },
223
+ {
224
+ clientCallName: 'client.accounts.usage.get',
225
+ fullyQualifiedName: 'accounts.usage.get',
226
+ httpMethod: 'get',
227
+ httpPath: '/v1/accounts/usage',
228
+ },
229
+ {
230
+ clientCallName: 'client.accounts.origins.create',
231
+ fullyQualifiedName: 'accounts.origins.create',
232
+ httpMethod: 'post',
233
+ httpPath: '/v1/accounts/origins',
234
+ },
235
+ {
236
+ clientCallName: 'client.accounts.origins.update',
237
+ fullyQualifiedName: 'accounts.origins.update',
238
+ httpMethod: 'put',
239
+ httpPath: '/v1/accounts/origins/{id}',
240
+ },
241
+ {
242
+ clientCallName: 'client.accounts.origins.list',
243
+ fullyQualifiedName: 'accounts.origins.list',
244
+ httpMethod: 'get',
245
+ httpPath: '/v1/accounts/origins',
246
+ },
247
+ {
248
+ clientCallName: 'client.accounts.origins.delete',
249
+ fullyQualifiedName: 'accounts.origins.delete',
250
+ httpMethod: 'delete',
251
+ httpPath: '/v1/accounts/origins/{id}',
252
+ },
253
+ {
254
+ clientCallName: 'client.accounts.origins.get',
255
+ fullyQualifiedName: 'accounts.origins.get',
256
+ httpMethod: 'get',
257
+ httpPath: '/v1/accounts/origins/{id}',
258
+ },
259
+ {
260
+ clientCallName: 'client.accounts.urlEndpoints.create',
261
+ fullyQualifiedName: 'accounts.urlEndpoints.create',
262
+ httpMethod: 'post',
263
+ httpPath: '/v1/accounts/url-endpoints',
264
+ },
265
+ {
266
+ clientCallName: 'client.accounts.urlEndpoints.update',
267
+ fullyQualifiedName: 'accounts.urlEndpoints.update',
268
+ httpMethod: 'put',
269
+ httpPath: '/v1/accounts/url-endpoints/{id}',
270
+ },
271
+ {
272
+ clientCallName: 'client.accounts.urlEndpoints.list',
273
+ fullyQualifiedName: 'accounts.urlEndpoints.list',
274
+ httpMethod: 'get',
275
+ httpPath: '/v1/accounts/url-endpoints',
276
+ },
277
+ {
278
+ clientCallName: 'client.accounts.urlEndpoints.delete',
279
+ fullyQualifiedName: 'accounts.urlEndpoints.delete',
280
+ httpMethod: 'delete',
281
+ httpPath: '/v1/accounts/url-endpoints/{id}',
282
+ },
283
+ {
284
+ clientCallName: 'client.accounts.urlEndpoints.get',
285
+ fullyQualifiedName: 'accounts.urlEndpoints.get',
286
+ httpMethod: 'get',
287
+ httpPath: '/v1/accounts/url-endpoints/{id}',
288
+ },
289
+ {
290
+ clientCallName: 'client.beta.v2.files.upload',
291
+ fullyQualifiedName: 'beta.v2.files.upload',
292
+ httpMethod: 'post',
293
+ httpPath: '/api/v2/files/upload',
294
+ },
295
+ { clientCallName: 'client.webhooks.unsafeUnwrap', fullyQualifiedName: 'webhooks.unsafeUnwrap' },
296
+ { clientCallName: 'client.webhooks.unwrap', fullyQualifiedName: 'webhooks.unwrap' },
297
+ ];
298
+
299
+ function allowedMethodsForCodeTool(options: McpOptions | undefined): SdkMethod[] | undefined {
300
+ if (!options) {
301
+ return undefined;
302
+ }
303
+
304
+ let allowedMethods: SdkMethod[];
305
+
306
+ if (options.codeAllowHttpGets || options.codeAllowedMethods) {
307
+ // Start with nothing allowed and then add into it from options
308
+ let allowedMethodsSet = new Set<SdkMethod>();
309
+
310
+ if (options.codeAllowHttpGets) {
311
+ // Add all methods that map to an HTTP GET
312
+ sdkMethods
313
+ .filter((method) => method.httpMethod === 'get')
314
+ .forEach((method) => allowedMethodsSet.add(method));
315
+ }
316
+
317
+ if (options.codeAllowedMethods) {
318
+ // Add all methods that match any of the allowed regexps
319
+ const allowedRegexps = options.codeAllowedMethods.map((pattern) => {
320
+ try {
321
+ return new RegExp(pattern);
322
+ } catch (e) {
323
+ throw new Error(
324
+ `Invalid regex pattern for allowed method: "${pattern}": ${e instanceof Error ? e.message : e}`,
325
+ );
326
+ }
327
+ });
328
+
329
+ sdkMethods
330
+ .filter((method) => allowedRegexps.some((regexp) => regexp.test(method.fullyQualifiedName)))
331
+ .forEach((method) => allowedMethodsSet.add(method));
332
+ }
333
+
334
+ allowedMethods = Array.from(allowedMethodsSet);
335
+ } else {
336
+ // Start with everything allowed
337
+ allowedMethods = [...sdkMethods];
338
+ }
339
+
340
+ if (options.codeBlockedMethods) {
341
+ // Filter down based on blocked regexps
342
+ const blockedRegexps = options.codeBlockedMethods.map((pattern) => {
343
+ try {
344
+ return new RegExp(pattern);
345
+ } catch (e) {
346
+ throw new Error(
347
+ `Invalid regex pattern for blocked method: "${pattern}": ${e instanceof Error ? e.message : e}`,
348
+ );
349
+ }
350
+ });
351
+
352
+ allowedMethods = allowedMethods.filter(
353
+ (method) => !blockedRegexps.some((regexp) => regexp.test(method.fullyQualifiedName)),
354
+ );
355
+ }
356
+
357
+ return allowedMethods;
358
+ }
359
+
360
+ export function blockedMethodsForCodeTool(options: McpOptions | undefined): SdkMethod[] | undefined {
361
+ const allowedMethods = allowedMethodsForCodeTool(options);
362
+ if (!allowedMethods) {
363
+ return undefined;
364
+ }
365
+
366
+ const allowedSet = new Set(allowedMethods.map((method) => method.fullyQualifiedName));
367
+
368
+ // Return any methods that are not explicitly allowed
369
+ return sdkMethods.filter((method) => !allowedSet.has(method.fullyQualifiedName));
370
+ }
package/src/options.ts CHANGED
@@ -1,46 +1,114 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
1
3
  import qs from 'qs';
2
4
  import yargs from 'yargs';
3
5
  import { hideBin } from 'yargs/helpers';
4
6
  import z from 'zod';
7
+ import { readEnv } from './util';
5
8
 
6
9
  export type CLIOptions = McpOptions & {
10
+ debug: boolean;
11
+ logFormat: 'json' | 'pretty';
7
12
  transport: 'stdio' | 'http';
8
13
  port: number | undefined;
9
14
  socket: string | undefined;
10
15
  };
11
16
 
12
17
  export type McpOptions = {
18
+ includeCodeTool?: boolean | undefined;
13
19
  includeDocsTools?: boolean | undefined;
20
+ stainlessApiKey?: string | undefined;
21
+ docsSearchMode?: 'stainless-api' | 'local' | undefined;
22
+ docsDir?: string | undefined;
23
+ codeAllowHttpGets?: boolean | undefined;
24
+ codeAllowedMethods?: string[] | undefined;
25
+ codeBlockedMethods?: string[] | undefined;
26
+ codeExecutionMode: McpCodeExecutionMode;
27
+ customInstructionsPath?: string | undefined;
14
28
  };
15
29
 
30
+ export type McpCodeExecutionMode = 'stainless-sandbox' | 'local';
31
+
16
32
  export function parseCLIOptions(): CLIOptions {
17
33
  const opts = yargs(hideBin(process.argv))
18
- .option('tools', {
34
+ .option('code-allow-http-gets', {
35
+ type: 'boolean',
36
+ description:
37
+ 'Allow all code tool methods that map to HTTP GET operations. If all code-allow-* flags are unset, then everything is allowed.',
38
+ })
39
+ .option('code-allowed-methods', {
19
40
  type: 'string',
20
41
  array: true,
21
- choices: ['code', 'docs'],
22
- description: 'Use dynamic tools or all tools',
42
+ description:
43
+ 'Methods to explicitly allow for code tool. Evaluated as regular expressions against method fully qualified names. If all code-allow-* flags are unset, then everything is allowed.',
23
44
  })
24
- .option('no-tools', {
45
+ .option('code-blocked-methods', {
25
46
  type: 'string',
26
47
  array: true,
27
- choices: ['code', 'docs'],
28
- description: 'Do not use any dynamic or all tools',
48
+ description:
49
+ 'Methods to explicitly block for code tool. Evaluated as regular expressions against method fully qualified names. If all code-allow-* flags are unset, then everything is allowed.',
29
50
  })
30
- .option('transport', {
51
+ .option('code-execution-mode', {
31
52
  type: 'string',
32
- choices: ['stdio', 'http'],
33
- default: 'stdio',
34
- description: 'What transport to use; stdio for local servers or http for remote servers',
53
+ choices: ['stainless-sandbox', 'local'],
54
+ default: 'stainless-sandbox',
55
+ description:
56
+ "Where to run code execution in code tool; 'stainless-sandbox' will execute code in Stainless-hosted sandboxes whereas 'local' will execute code locally on the MCP server machine.",
57
+ })
58
+ .option('custom-instructions-path', {
59
+ type: 'string',
60
+ description: 'Path to custom instructions for the MCP server',
61
+ })
62
+ .option('debug', { type: 'boolean', description: 'Enable debug logging' })
63
+ .option('docs-dir', {
64
+ type: 'string',
65
+ description:
66
+ 'Path to a directory of local documentation files (markdown/JSON) to include in local docs search.',
67
+ })
68
+ .option('docs-search-mode', {
69
+ type: 'string',
70
+ choices: ['stainless-api', 'local'],
71
+ default: 'stainless-api',
72
+ description:
73
+ "Where to search documentation; 'stainless-api' uses the Stainless-hosted search API whereas 'local' uses an in-memory search index built from embedded SDK method data and optional local docs files.",
74
+ })
75
+ .option('log-format', {
76
+ type: 'string',
77
+ choices: ['json', 'pretty'],
78
+ description: 'Format for log output; defaults to json unless tty is detected',
79
+ })
80
+ .option('no-tools', {
81
+ type: 'string',
82
+ array: true,
83
+ choices: ['code', 'docs'],
84
+ description: 'Tools to explicitly disable',
35
85
  })
36
86
  .option('port', {
37
87
  type: 'number',
88
+ default: 3000,
38
89
  description: 'Port to serve on if using http transport',
39
90
  })
40
- .option('socket', {
91
+ .option('socket', { type: 'string', description: 'Unix socket to serve on if using http transport' })
92
+ .option('stainless-api-key', {
93
+ type: 'string',
94
+ default: readEnv('STAINLESS_API_KEY'),
95
+ description:
96
+ 'API key for Stainless. Used to authenticate requests to Stainless-hosted tools endpoints.',
97
+ })
98
+ .option('tools', {
99
+ type: 'string',
100
+ array: true,
101
+ choices: ['code', 'docs'],
102
+ description: 'Tools to explicitly enable',
103
+ })
104
+ .option('transport', {
41
105
  type: 'string',
42
- description: 'Unix socket to serve on if using http transport',
106
+ choices: ['stdio', 'http'],
107
+ default: 'stdio',
108
+ description: 'What transport to use; stdio for local servers or http for remote servers',
43
109
  })
110
+ .env('MCP_SERVER')
111
+ .version(true)
44
112
  .help();
45
113
 
46
114
  const argv = opts.parseSync();
@@ -50,13 +118,29 @@ export function parseCLIOptions(): CLIOptions {
50
118
  : argv.tools?.includes(toolType) ? true
51
119
  : undefined;
52
120
 
121
+ const includeCodeTool = shouldIncludeToolType('code');
53
122
  const includeDocsTools = shouldIncludeToolType('docs');
54
123
 
55
124
  const transport = argv.transport as 'stdio' | 'http';
125
+ const logFormat =
126
+ argv.logFormat ? (argv.logFormat as 'json' | 'pretty')
127
+ : process.stderr.isTTY ? 'pretty'
128
+ : 'json';
56
129
 
57
130
  return {
131
+ ...(includeCodeTool !== undefined && { includeCodeTool }),
58
132
  ...(includeDocsTools !== undefined && { includeDocsTools }),
133
+ debug: !!argv.debug,
134
+ stainlessApiKey: argv.stainlessApiKey,
135
+ docsSearchMode: argv.docsSearchMode as 'stainless-api' | 'local' | undefined,
136
+ docsDir: argv.docsDir,
137
+ codeAllowHttpGets: argv.codeAllowHttpGets,
138
+ codeAllowedMethods: argv.codeAllowedMethods,
139
+ codeBlockedMethods: argv.codeBlockedMethods,
140
+ codeExecutionMode: argv.codeExecutionMode as McpCodeExecutionMode,
141
+ customInstructionsPath: argv.customInstructionsPath,
59
142
  transport,
143
+ logFormat,
60
144
  port: argv.port,
61
145
  socket: argv.socket,
62
146
  };
@@ -81,12 +165,21 @@ export function parseQueryOptions(defaultOptions: McpOptions, query: unknown): M
81
165
  const queryObject = typeof query === 'string' ? qs.parse(query) : query;
82
166
  const queryOptions = QueryOptions.parse(queryObject);
83
167
 
168
+ let codeTool: boolean | undefined =
169
+ queryOptions.no_tools && queryOptions.no_tools?.includes('code') ? false
170
+ : queryOptions.tools?.includes('code') ? true
171
+ : defaultOptions.includeCodeTool;
172
+
84
173
  let docsTools: boolean | undefined =
85
174
  queryOptions.no_tools && queryOptions.no_tools?.includes('docs') ? false
86
175
  : queryOptions.tools?.includes('docs') ? true
87
176
  : defaultOptions.includeDocsTools;
88
177
 
89
178
  return {
179
+ ...(codeTool !== undefined && { includeCodeTool: codeTool }),
90
180
  ...(docsTools !== undefined && { includeDocsTools: docsTools }),
181
+ codeExecutionMode: defaultOptions.codeExecutionMode,
182
+ docsSearchMode: defaultOptions.docsSearchMode,
183
+ docsDir: defaultOptions.docsDir,
91
184
  };
92
185
  }