@stigg/typescript-mcp 0.1.0-alpha.8

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 (112) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +99 -0
  3. package/auth.d.mts +6 -0
  4. package/auth.d.mts.map +1 -0
  5. package/auth.d.ts +6 -0
  6. package/auth.d.ts.map +1 -0
  7. package/auth.js +22 -0
  8. package/auth.js.map +1 -0
  9. package/auth.mjs +17 -0
  10. package/auth.mjs.map +1 -0
  11. package/code-tool-types.d.mts +14 -0
  12. package/code-tool-types.d.mts.map +1 -0
  13. package/code-tool-types.d.ts +14 -0
  14. package/code-tool-types.d.ts.map +1 -0
  15. package/code-tool-types.js +4 -0
  16. package/code-tool-types.js.map +1 -0
  17. package/code-tool-types.mjs +3 -0
  18. package/code-tool-types.mjs.map +1 -0
  19. package/code-tool.d.mts +15 -0
  20. package/code-tool.d.mts.map +1 -0
  21. package/code-tool.d.ts +15 -0
  22. package/code-tool.d.ts.map +1 -0
  23. package/code-tool.js +108 -0
  24. package/code-tool.js.map +1 -0
  25. package/code-tool.mjs +105 -0
  26. package/code-tool.mjs.map +1 -0
  27. package/docs-search-tool.d.mts +57 -0
  28. package/docs-search-tool.d.mts.map +1 -0
  29. package/docs-search-tool.d.ts +57 -0
  30. package/docs-search-tool.d.ts.map +1 -0
  31. package/docs-search-tool.js +55 -0
  32. package/docs-search-tool.js.map +1 -0
  33. package/docs-search-tool.mjs +51 -0
  34. package/docs-search-tool.mjs.map +1 -0
  35. package/http.d.mts +14 -0
  36. package/http.d.mts.map +1 -0
  37. package/http.d.ts +14 -0
  38. package/http.d.ts.map +1 -0
  39. package/http.js +107 -0
  40. package/http.js.map +1 -0
  41. package/http.mjs +99 -0
  42. package/http.mjs.map +1 -0
  43. package/index.d.mts +3 -0
  44. package/index.d.mts.map +1 -0
  45. package/index.d.ts +3 -0
  46. package/index.d.ts.map +1 -0
  47. package/index.js +59 -0
  48. package/index.js.map +1 -0
  49. package/index.mjs +57 -0
  50. package/index.mjs.map +1 -0
  51. package/methods.d.mts +10 -0
  52. package/methods.d.mts.map +1 -0
  53. package/methods.d.ts +10 -0
  54. package/methods.d.ts.map +1 -0
  55. package/methods.js +419 -0
  56. package/methods.js.map +1 -0
  57. package/methods.mjs +415 -0
  58. package/methods.mjs.map +1 -0
  59. package/options.d.mts +16 -0
  60. package/options.d.mts.map +1 -0
  61. package/options.d.ts +16 -0
  62. package/options.d.ts.map +1 -0
  63. package/options.js +99 -0
  64. package/options.js.map +1 -0
  65. package/options.mjs +92 -0
  66. package/options.mjs.map +1 -0
  67. package/package.json +185 -0
  68. package/server.d.mts +29 -0
  69. package/server.d.mts.map +1 -0
  70. package/server.d.ts +29 -0
  71. package/server.d.ts.map +1 -0
  72. package/server.js +143 -0
  73. package/server.js.map +1 -0
  74. package/server.mjs +133 -0
  75. package/server.mjs.map +1 -0
  76. package/src/auth.ts +25 -0
  77. package/src/code-tool-types.ts +16 -0
  78. package/src/code-tool.ts +139 -0
  79. package/src/docs-search-tool.ts +68 -0
  80. package/src/http.ts +138 -0
  81. package/src/index.ts +65 -0
  82. package/src/methods.ts +440 -0
  83. package/src/options.ts +129 -0
  84. package/src/server.ts +181 -0
  85. package/src/stdio.ts +13 -0
  86. package/src/tsconfig.json +11 -0
  87. package/src/types.ts +123 -0
  88. package/src/util.ts +25 -0
  89. package/stdio.d.mts +3 -0
  90. package/stdio.d.mts.map +1 -0
  91. package/stdio.d.ts +3 -0
  92. package/stdio.d.ts.map +1 -0
  93. package/stdio.js +14 -0
  94. package/stdio.js.map +1 -0
  95. package/stdio.mjs +10 -0
  96. package/stdio.mjs.map +1 -0
  97. package/types.d.mts +59 -0
  98. package/types.d.mts.map +1 -0
  99. package/types.d.ts +59 -0
  100. package/types.d.ts.map +1 -0
  101. package/types.js +58 -0
  102. package/types.js.map +1 -0
  103. package/types.mjs +53 -0
  104. package/types.mjs.map +1 -0
  105. package/util.d.mts +4 -0
  106. package/util.d.mts.map +1 -0
  107. package/util.d.ts +4 -0
  108. package/util.d.ts.map +1 -0
  109. package/util.js +30 -0
  110. package/util.js.map +1 -0
  111. package/util.mjs +24 -0
  112. package/util.mjs.map +1 -0
package/src/methods.ts ADDED
@@ -0,0 +1,440 @@
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.v1.customers.retrieve',
15
+ fullyQualifiedName: 'v1.customers.retrieve',
16
+ httpMethod: 'get',
17
+ httpPath: '/api/v1/customers/{id}',
18
+ },
19
+ {
20
+ clientCallName: 'client.v1.customers.update',
21
+ fullyQualifiedName: 'v1.customers.update',
22
+ httpMethod: 'patch',
23
+ httpPath: '/api/v1/customers/{id}',
24
+ },
25
+ {
26
+ clientCallName: 'client.v1.customers.list',
27
+ fullyQualifiedName: 'v1.customers.list',
28
+ httpMethod: 'get',
29
+ httpPath: '/api/v1/customers',
30
+ },
31
+ {
32
+ clientCallName: 'client.v1.customers.archive',
33
+ fullyQualifiedName: 'v1.customers.archive',
34
+ httpMethod: 'post',
35
+ httpPath: '/api/v1/customers/{id}/archive',
36
+ },
37
+ {
38
+ clientCallName: 'client.v1.customers.import',
39
+ fullyQualifiedName: 'v1.customers.import',
40
+ httpMethod: 'post',
41
+ httpPath: '/api/v1/customers/import',
42
+ },
43
+ {
44
+ clientCallName: 'client.v1.customers.listResources',
45
+ fullyQualifiedName: 'v1.customers.listResources',
46
+ httpMethod: 'get',
47
+ httpPath: '/api/v1/customers/{id}/resources',
48
+ },
49
+ {
50
+ clientCallName: 'client.v1.customers.provision',
51
+ fullyQualifiedName: 'v1.customers.provision',
52
+ httpMethod: 'post',
53
+ httpPath: '/api/v1/customers',
54
+ },
55
+ {
56
+ clientCallName: 'client.v1.customers.unarchive',
57
+ fullyQualifiedName: 'v1.customers.unarchive',
58
+ httpMethod: 'post',
59
+ httpPath: '/api/v1/customers/{id}/unarchive',
60
+ },
61
+ {
62
+ clientCallName: 'client.v1.customers.paymentMethod.attach',
63
+ fullyQualifiedName: 'v1.customers.paymentMethod.attach',
64
+ httpMethod: 'post',
65
+ httpPath: '/api/v1/customers/{id}/payment-method',
66
+ },
67
+ {
68
+ clientCallName: 'client.v1.customers.paymentMethod.detach',
69
+ fullyQualifiedName: 'v1.customers.paymentMethod.detach',
70
+ httpMethod: 'delete',
71
+ httpPath: '/api/v1/customers/{id}/payment-method',
72
+ },
73
+ {
74
+ clientCallName: 'client.v1.customers.promotionalEntitlements.create',
75
+ fullyQualifiedName: 'v1.customers.promotionalEntitlements.create',
76
+ httpMethod: 'post',
77
+ httpPath: '/api/v1/customers/{id}/promotional-entitlements',
78
+ },
79
+ {
80
+ clientCallName: 'client.v1.customers.promotionalEntitlements.list',
81
+ fullyQualifiedName: 'v1.customers.promotionalEntitlements.list',
82
+ httpMethod: 'get',
83
+ httpPath: '/api/v1/customers/{id}/promotional-entitlements',
84
+ },
85
+ {
86
+ clientCallName: 'client.v1.customers.promotionalEntitlements.revoke',
87
+ fullyQualifiedName: 'v1.customers.promotionalEntitlements.revoke',
88
+ httpMethod: 'delete',
89
+ httpPath: '/api/v1/customers/{id}/promotional-entitlements/{featureId}',
90
+ },
91
+ {
92
+ clientCallName: 'client.v1.subscriptions.retrieve',
93
+ fullyQualifiedName: 'v1.subscriptions.retrieve',
94
+ httpMethod: 'get',
95
+ httpPath: '/api/v1/subscriptions/{id}',
96
+ },
97
+ {
98
+ clientCallName: 'client.v1.subscriptions.update',
99
+ fullyQualifiedName: 'v1.subscriptions.update',
100
+ httpMethod: 'patch',
101
+ httpPath: '/api/v1/subscriptions/{id}',
102
+ },
103
+ {
104
+ clientCallName: 'client.v1.subscriptions.list',
105
+ fullyQualifiedName: 'v1.subscriptions.list',
106
+ httpMethod: 'get',
107
+ httpPath: '/api/v1/subscriptions',
108
+ },
109
+ {
110
+ clientCallName: 'client.v1.subscriptions.cancel',
111
+ fullyQualifiedName: 'v1.subscriptions.cancel',
112
+ httpMethod: 'post',
113
+ httpPath: '/api/v1/subscriptions/{id}/cancel',
114
+ },
115
+ {
116
+ clientCallName: 'client.v1.subscriptions.delegate',
117
+ fullyQualifiedName: 'v1.subscriptions.delegate',
118
+ httpMethod: 'post',
119
+ httpPath: '/api/v1/subscriptions/{id}/delegate',
120
+ },
121
+ {
122
+ clientCallName: 'client.v1.subscriptions.import',
123
+ fullyQualifiedName: 'v1.subscriptions.import',
124
+ httpMethod: 'post',
125
+ httpPath: '/api/v1/subscriptions/import',
126
+ },
127
+ {
128
+ clientCallName: 'client.v1.subscriptions.migrate',
129
+ fullyQualifiedName: 'v1.subscriptions.migrate',
130
+ httpMethod: 'post',
131
+ httpPath: '/api/v1/subscriptions/{id}/migrate',
132
+ },
133
+ {
134
+ clientCallName: 'client.v1.subscriptions.preview',
135
+ fullyQualifiedName: 'v1.subscriptions.preview',
136
+ httpMethod: 'post',
137
+ httpPath: '/api/v1/subscriptions/preview',
138
+ },
139
+ {
140
+ clientCallName: 'client.v1.subscriptions.provision',
141
+ fullyQualifiedName: 'v1.subscriptions.provision',
142
+ httpMethod: 'post',
143
+ httpPath: '/api/v1/subscriptions',
144
+ },
145
+ {
146
+ clientCallName: 'client.v1.subscriptions.transfer',
147
+ fullyQualifiedName: 'v1.subscriptions.transfer',
148
+ httpMethod: 'post',
149
+ httpPath: '/api/v1/subscriptions/{id}/transfer',
150
+ },
151
+ {
152
+ clientCallName: 'client.v1.subscriptions.futureUpdate.cancelPendingPayment',
153
+ fullyQualifiedName: 'v1.subscriptions.futureUpdate.cancelPendingPayment',
154
+ httpMethod: 'delete',
155
+ httpPath: '/api/v1/subscriptions/{id}/future-update/pending-payment',
156
+ },
157
+ {
158
+ clientCallName: 'client.v1.subscriptions.futureUpdate.cancelSchedule',
159
+ fullyQualifiedName: 'v1.subscriptions.futureUpdate.cancelSchedule',
160
+ httpMethod: 'delete',
161
+ httpPath: '/api/v1/subscriptions/{id}/future-update/schedule',
162
+ },
163
+ {
164
+ clientCallName: 'client.v1.subscriptions.usage.chargeUsage',
165
+ fullyQualifiedName: 'v1.subscriptions.usage.chargeUsage',
166
+ httpMethod: 'post',
167
+ httpPath: '/api/v1/subscriptions/{id}/usage/charge',
168
+ },
169
+ {
170
+ clientCallName: 'client.v1.subscriptions.usage.sync',
171
+ fullyQualifiedName: 'v1.subscriptions.usage.sync',
172
+ httpMethod: 'post',
173
+ httpPath: '/api/v1/subscriptions/{id}/usage/sync',
174
+ },
175
+ {
176
+ clientCallName: 'client.v1.subscriptions.invoice.markAsPaid',
177
+ fullyQualifiedName: 'v1.subscriptions.invoice.markAsPaid',
178
+ httpMethod: 'post',
179
+ httpPath: '/api/v1/subscriptions/{id}/invoice/paid',
180
+ },
181
+ {
182
+ clientCallName: 'client.v1.coupons.create',
183
+ fullyQualifiedName: 'v1.coupons.create',
184
+ httpMethod: 'post',
185
+ httpPath: '/api/v1/coupons',
186
+ },
187
+ {
188
+ clientCallName: 'client.v1.coupons.retrieve',
189
+ fullyQualifiedName: 'v1.coupons.retrieve',
190
+ httpMethod: 'get',
191
+ httpPath: '/api/v1/coupons/{id}',
192
+ },
193
+ {
194
+ clientCallName: 'client.v1.coupons.list',
195
+ fullyQualifiedName: 'v1.coupons.list',
196
+ httpMethod: 'get',
197
+ httpPath: '/api/v1/coupons',
198
+ },
199
+ {
200
+ clientCallName: 'client.v1.coupons.archiveCoupon',
201
+ fullyQualifiedName: 'v1.coupons.archiveCoupon',
202
+ httpMethod: 'post',
203
+ httpPath: '/api/v1/coupons/{id}/archive',
204
+ },
205
+ {
206
+ clientCallName: 'client.v1.coupons.updateCoupon',
207
+ fullyQualifiedName: 'v1.coupons.updateCoupon',
208
+ httpMethod: 'patch',
209
+ httpPath: '/api/v1/coupons/{id}',
210
+ },
211
+ {
212
+ clientCallName: 'client.v1.events.report',
213
+ fullyQualifiedName: 'v1.events.report',
214
+ httpMethod: 'post',
215
+ httpPath: '/api/v1/events',
216
+ },
217
+ {
218
+ clientCallName: 'client.v1.events.features.archiveFeature',
219
+ fullyQualifiedName: 'v1.events.features.archiveFeature',
220
+ httpMethod: 'post',
221
+ httpPath: '/api/v1/features/{id}/archive',
222
+ },
223
+ {
224
+ clientCallName: 'client.v1.events.features.createFeature',
225
+ fullyQualifiedName: 'v1.events.features.createFeature',
226
+ httpMethod: 'post',
227
+ httpPath: '/api/v1/features',
228
+ },
229
+ {
230
+ clientCallName: 'client.v1.events.features.listFeatures',
231
+ fullyQualifiedName: 'v1.events.features.listFeatures',
232
+ httpMethod: 'get',
233
+ httpPath: '/api/v1/features',
234
+ },
235
+ {
236
+ clientCallName: 'client.v1.events.features.retrieveFeature',
237
+ fullyQualifiedName: 'v1.events.features.retrieveFeature',
238
+ httpMethod: 'get',
239
+ httpPath: '/api/v1/features/{id}',
240
+ },
241
+ {
242
+ clientCallName: 'client.v1.events.features.unarchiveFeature',
243
+ fullyQualifiedName: 'v1.events.features.unarchiveFeature',
244
+ httpMethod: 'post',
245
+ httpPath: '/api/v1/features/{id}/unarchive',
246
+ },
247
+ {
248
+ clientCallName: 'client.v1.events.features.updateFeature',
249
+ fullyQualifiedName: 'v1.events.features.updateFeature',
250
+ httpMethod: 'patch',
251
+ httpPath: '/api/v1/features/{id}',
252
+ },
253
+ {
254
+ clientCallName: 'client.v1.events.addons.archiveAddon',
255
+ fullyQualifiedName: 'v1.events.addons.archiveAddon',
256
+ httpMethod: 'post',
257
+ httpPath: '/api/v1/addons/{id}/archive',
258
+ },
259
+ {
260
+ clientCallName: 'client.v1.events.addons.createAddon',
261
+ fullyQualifiedName: 'v1.events.addons.createAddon',
262
+ httpMethod: 'post',
263
+ httpPath: '/api/v1/addons',
264
+ },
265
+ {
266
+ clientCallName: 'client.v1.events.addons.listAddons',
267
+ fullyQualifiedName: 'v1.events.addons.listAddons',
268
+ httpMethod: 'get',
269
+ httpPath: '/api/v1/addons',
270
+ },
271
+ {
272
+ clientCallName: 'client.v1.events.addons.publishAddon',
273
+ fullyQualifiedName: 'v1.events.addons.publishAddon',
274
+ httpMethod: 'post',
275
+ httpPath: '/api/v1/addons/{id}/publish',
276
+ },
277
+ {
278
+ clientCallName: 'client.v1.events.addons.retrieveAddon',
279
+ fullyQualifiedName: 'v1.events.addons.retrieveAddon',
280
+ httpMethod: 'get',
281
+ httpPath: '/api/v1/addons/{id}',
282
+ },
283
+ {
284
+ clientCallName: 'client.v1.events.addons.updateAddon',
285
+ fullyQualifiedName: 'v1.events.addons.updateAddon',
286
+ httpMethod: 'patch',
287
+ httpPath: '/api/v1/addons/{id}',
288
+ },
289
+ {
290
+ clientCallName: 'client.v1.events.addons.draft.createAddonDraft',
291
+ fullyQualifiedName: 'v1.events.addons.draft.createAddonDraft',
292
+ httpMethod: 'post',
293
+ httpPath: '/api/v1/addons/{id}/draft',
294
+ },
295
+ {
296
+ clientCallName: 'client.v1.events.addons.draft.removeAddonDraft',
297
+ fullyQualifiedName: 'v1.events.addons.draft.removeAddonDraft',
298
+ httpMethod: 'delete',
299
+ httpPath: '/api/v1/addons/{id}/draft',
300
+ },
301
+ {
302
+ clientCallName: 'client.v1.events.plans.create',
303
+ fullyQualifiedName: 'v1.events.plans.create',
304
+ httpMethod: 'post',
305
+ httpPath: '/api/v1/plans',
306
+ },
307
+ {
308
+ clientCallName: 'client.v1.events.plans.retrieve',
309
+ fullyQualifiedName: 'v1.events.plans.retrieve',
310
+ httpMethod: 'get',
311
+ httpPath: '/api/v1/plans/{id}',
312
+ },
313
+ {
314
+ clientCallName: 'client.v1.events.plans.list',
315
+ fullyQualifiedName: 'v1.events.plans.list',
316
+ httpMethod: 'get',
317
+ httpPath: '/api/v1/plans',
318
+ },
319
+ {
320
+ clientCallName: 'client.v1.usage.history',
321
+ fullyQualifiedName: 'v1.usage.history',
322
+ httpMethod: 'get',
323
+ httpPath: '/api/v1/usage/{customerId}/history/{featureId}',
324
+ },
325
+ {
326
+ clientCallName: 'client.v1.usage.report',
327
+ fullyQualifiedName: 'v1.usage.report',
328
+ httpMethod: 'post',
329
+ httpPath: '/api/v1/usage',
330
+ },
331
+ {
332
+ clientCallName: 'client.v1.products.archiveProduct',
333
+ fullyQualifiedName: 'v1.products.archiveProduct',
334
+ httpMethod: 'post',
335
+ httpPath: '/api/v1/products/{id}/archive',
336
+ },
337
+ {
338
+ clientCallName: 'client.v1.products.createProduct',
339
+ fullyQualifiedName: 'v1.products.createProduct',
340
+ httpMethod: 'post',
341
+ httpPath: '/api/v1/products',
342
+ },
343
+ {
344
+ clientCallName: 'client.v1.products.duplicateProduct',
345
+ fullyQualifiedName: 'v1.products.duplicateProduct',
346
+ httpMethod: 'post',
347
+ httpPath: '/api/v1/products/{id}/duplicate',
348
+ },
349
+ {
350
+ clientCallName: 'client.v1.products.listProducts',
351
+ fullyQualifiedName: 'v1.products.listProducts',
352
+ httpMethod: 'get',
353
+ httpPath: '/api/v1/products',
354
+ },
355
+ {
356
+ clientCallName: 'client.v1.products.unarchiveProduct',
357
+ fullyQualifiedName: 'v1.products.unarchiveProduct',
358
+ httpMethod: 'post',
359
+ httpPath: '/api/v1/products/{id}/unarchive',
360
+ },
361
+ {
362
+ clientCallName: 'client.v1.products.updateProduct',
363
+ fullyQualifiedName: 'v1.products.updateProduct',
364
+ httpMethod: 'patch',
365
+ httpPath: '/api/v1/products/{id}',
366
+ },
367
+ ];
368
+
369
+ function allowedMethodsForCodeTool(options: McpOptions | undefined): SdkMethod[] | undefined {
370
+ if (!options) {
371
+ return undefined;
372
+ }
373
+
374
+ let allowedMethods: SdkMethod[];
375
+
376
+ if (options.codeAllowHttpGets || options.codeAllowedMethods) {
377
+ // Start with nothing allowed and then add into it from options
378
+ let allowedMethodsSet = new Set<SdkMethod>();
379
+
380
+ if (options.codeAllowHttpGets) {
381
+ // Add all methods that map to an HTTP GET
382
+ sdkMethods
383
+ .filter((method) => method.httpMethod === 'get')
384
+ .forEach((method) => allowedMethodsSet.add(method));
385
+ }
386
+
387
+ if (options.codeAllowedMethods) {
388
+ // Add all methods that match any of the allowed regexps
389
+ const allowedRegexps = options.codeAllowedMethods.map((pattern) => {
390
+ try {
391
+ return new RegExp(pattern);
392
+ } catch (e) {
393
+ throw new Error(
394
+ `Invalid regex pattern for allowed method: "${pattern}": ${e instanceof Error ? e.message : e}`,
395
+ );
396
+ }
397
+ });
398
+
399
+ sdkMethods
400
+ .filter((method) => allowedRegexps.some((regexp) => regexp.test(method.fullyQualifiedName)))
401
+ .forEach((method) => allowedMethodsSet.add(method));
402
+ }
403
+
404
+ allowedMethods = Array.from(allowedMethodsSet);
405
+ } else {
406
+ // Start with everything allowed
407
+ allowedMethods = [...sdkMethods];
408
+ }
409
+
410
+ if (options.codeBlockedMethods) {
411
+ // Filter down based on blocked regexps
412
+ const blockedRegexps = options.codeBlockedMethods.map((pattern) => {
413
+ try {
414
+ return new RegExp(pattern);
415
+ } catch (e) {
416
+ throw new Error(
417
+ `Invalid regex pattern for blocked method: "${pattern}": ${e instanceof Error ? e.message : e}`,
418
+ );
419
+ }
420
+ });
421
+
422
+ allowedMethods = allowedMethods.filter(
423
+ (method) => !blockedRegexps.some((regexp) => regexp.test(method.fullyQualifiedName)),
424
+ );
425
+ }
426
+
427
+ return allowedMethods;
428
+ }
429
+
430
+ export function blockedMethodsForCodeTool(options: McpOptions | undefined): SdkMethod[] | undefined {
431
+ const allowedMethods = allowedMethodsForCodeTool(options);
432
+ if (!allowedMethods) {
433
+ return undefined;
434
+ }
435
+
436
+ const allowedSet = new Set(allowedMethods.map((method) => method.fullyQualifiedName));
437
+
438
+ // Return any methods that are not explicitly allowed
439
+ return sdkMethods.filter((method) => !allowedSet.has(method.fullyQualifiedName));
440
+ }
package/src/options.ts ADDED
@@ -0,0 +1,129 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import qs from 'qs';
4
+ import yargs from 'yargs';
5
+ import { hideBin } from 'yargs/helpers';
6
+ import z from 'zod';
7
+ import { readEnv } from './util';
8
+
9
+ export type CLIOptions = McpOptions & {
10
+ debug: boolean;
11
+ transport: 'stdio' | 'http';
12
+ port: number | undefined;
13
+ socket: string | undefined;
14
+ };
15
+
16
+ export type McpOptions = {
17
+ includeDocsTools?: boolean | undefined;
18
+ stainlessApiKey?: string | undefined;
19
+ codeAllowHttpGets?: boolean | undefined;
20
+ codeAllowedMethods?: string[] | undefined;
21
+ codeBlockedMethods?: string[] | undefined;
22
+ };
23
+
24
+ export function parseCLIOptions(): CLIOptions {
25
+ const opts = yargs(hideBin(process.argv))
26
+ .option('code-allow-http-gets', {
27
+ type: 'boolean',
28
+ description:
29
+ 'Allow all code tool methods that map to HTTP GET operations. If all code-allow-* flags are unset, then everything is allowed.',
30
+ })
31
+ .option('code-allowed-methods', {
32
+ type: 'string',
33
+ array: true,
34
+ description:
35
+ '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.',
36
+ })
37
+ .option('code-blocked-methods', {
38
+ type: 'string',
39
+ array: true,
40
+ description:
41
+ '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.',
42
+ })
43
+ .option('debug', { type: 'boolean', description: 'Enable debug logging' })
44
+ .option('no-tools', {
45
+ type: 'string',
46
+ array: true,
47
+ choices: ['code', 'docs'],
48
+ description: 'Tools to explicitly disable',
49
+ })
50
+ .option('port', {
51
+ type: 'number',
52
+ default: 3000,
53
+ description: 'Port to serve on if using http transport',
54
+ })
55
+ .option('socket', { type: 'string', description: 'Unix socket to serve on if using http transport' })
56
+ .option('stainless-api-key', {
57
+ type: 'string',
58
+ default: readEnv('STAINLESS_API_KEY'),
59
+ description:
60
+ 'API key for Stainless. Used to authenticate requests to Stainless-hosted tools endpoints.',
61
+ })
62
+ .option('tools', {
63
+ type: 'string',
64
+ array: true,
65
+ choices: ['code', 'docs'],
66
+ description: 'Tools to explicitly enable',
67
+ })
68
+ .option('transport', {
69
+ type: 'string',
70
+ choices: ['stdio', 'http'],
71
+ default: 'stdio',
72
+ description: 'What transport to use; stdio for local servers or http for remote servers',
73
+ })
74
+ .env('MCP_SERVER')
75
+ .version(true)
76
+ .help();
77
+
78
+ const argv = opts.parseSync();
79
+
80
+ const shouldIncludeToolType = (toolType: 'code' | 'docs') =>
81
+ argv.noTools?.includes(toolType) ? false
82
+ : argv.tools?.includes(toolType) ? true
83
+ : undefined;
84
+
85
+ const includeDocsTools = shouldIncludeToolType('docs');
86
+
87
+ const transport = argv.transport as 'stdio' | 'http';
88
+
89
+ return {
90
+ ...(includeDocsTools !== undefined && { includeDocsTools }),
91
+ debug: !!argv.debug,
92
+ stainlessApiKey: argv.stainlessApiKey,
93
+ codeAllowHttpGets: argv.codeAllowHttpGets,
94
+ codeAllowedMethods: argv.codeAllowedMethods,
95
+ codeBlockedMethods: argv.codeBlockedMethods,
96
+ transport,
97
+ port: argv.port,
98
+ socket: argv.socket,
99
+ };
100
+ }
101
+
102
+ const coerceArray = <T extends z.ZodTypeAny>(zodType: T) =>
103
+ z.preprocess(
104
+ (val) =>
105
+ Array.isArray(val) ? val
106
+ : val ? [val]
107
+ : val,
108
+ z.array(zodType).optional(),
109
+ );
110
+
111
+ const QueryOptions = z.object({
112
+ tools: coerceArray(z.enum(['code', 'docs'])).describe('Specify which MCP tools to use'),
113
+ no_tools: coerceArray(z.enum(['code', 'docs'])).describe('Specify which MCP tools to not use.'),
114
+ tool: coerceArray(z.string()).describe('Include tools matching the specified names'),
115
+ });
116
+
117
+ export function parseQueryOptions(defaultOptions: McpOptions, query: unknown): McpOptions {
118
+ const queryObject = typeof query === 'string' ? qs.parse(query) : query;
119
+ const queryOptions = QueryOptions.parse(queryObject);
120
+
121
+ let docsTools: boolean | undefined =
122
+ queryOptions.no_tools && queryOptions.no_tools?.includes('docs') ? false
123
+ : queryOptions.tools?.includes('docs') ? true
124
+ : defaultOptions.includeDocsTools;
125
+
126
+ return {
127
+ ...(docsTools !== undefined && { includeDocsTools: docsTools }),
128
+ };
129
+ }