@openmrp/sdk-mcp 0.19.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 (135) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +103 -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 +37 -0
  8. package/auth.js.map +1 -0
  9. package/auth.mjs +32 -0
  10. package/auth.mjs.map +1 -0
  11. package/code-tool-paths.cjs +8 -0
  12. package/code-tool-paths.cjs.map +1 -0
  13. package/code-tool-paths.d.cts +2 -0
  14. package/code-tool-paths.d.cts.map +1 -0
  15. package/code-tool-types.d.mts +14 -0
  16. package/code-tool-types.d.mts.map +1 -0
  17. package/code-tool-types.d.ts +14 -0
  18. package/code-tool-types.d.ts.map +1 -0
  19. package/code-tool-types.js +4 -0
  20. package/code-tool-types.js.map +1 -0
  21. package/code-tool-types.mjs +3 -0
  22. package/code-tool-types.mjs.map +1 -0
  23. package/code-tool-worker.d.mts +5 -0
  24. package/code-tool-worker.d.mts.map +1 -0
  25. package/code-tool-worker.d.ts +5 -0
  26. package/code-tool-worker.d.ts.map +1 -0
  27. package/code-tool-worker.js +636 -0
  28. package/code-tool-worker.js.map +1 -0
  29. package/code-tool-worker.mjs +598 -0
  30. package/code-tool-worker.mjs.map +1 -0
  31. package/code-tool.d.mts +21 -0
  32. package/code-tool.d.mts.map +1 -0
  33. package/code-tool.d.ts +21 -0
  34. package/code-tool.d.ts.map +1 -0
  35. package/code-tool.js +287 -0
  36. package/code-tool.js.map +1 -0
  37. package/code-tool.mjs +251 -0
  38. package/code-tool.mjs.map +1 -0
  39. package/http.d.mts +12 -0
  40. package/http.d.mts.map +1 -0
  41. package/http.d.ts +12 -0
  42. package/http.d.ts.map +1 -0
  43. package/http.js +190 -0
  44. package/http.js.map +1 -0
  45. package/http.mjs +182 -0
  46. package/http.mjs.map +1 -0
  47. package/index.d.mts +3 -0
  48. package/index.d.mts.map +1 -0
  49. package/index.d.ts +3 -0
  50. package/index.d.ts.map +1 -0
  51. package/index.js +60 -0
  52. package/index.js.map +1 -0
  53. package/index.mjs +58 -0
  54. package/index.mjs.map +1 -0
  55. package/instructions.d.mts +5 -0
  56. package/instructions.d.mts.map +1 -0
  57. package/instructions.d.ts +5 -0
  58. package/instructions.d.ts.map +1 -0
  59. package/instructions.js +47 -0
  60. package/instructions.js.map +1 -0
  61. package/instructions.mjs +41 -0
  62. package/instructions.mjs.map +1 -0
  63. package/logger.d.mts +7 -0
  64. package/logger.d.mts.map +1 -0
  65. package/logger.d.ts +7 -0
  66. package/logger.d.ts.map +1 -0
  67. package/logger.js +29 -0
  68. package/logger.js.map +1 -0
  69. package/logger.mjs +22 -0
  70. package/logger.mjs.map +1 -0
  71. package/methods.d.mts +10 -0
  72. package/methods.d.mts.map +1 -0
  73. package/methods.d.ts +10 -0
  74. package/methods.d.ts.map +1 -0
  75. package/methods.js +2285 -0
  76. package/methods.js.map +1 -0
  77. package/methods.mjs +2281 -0
  78. package/methods.mjs.map +1 -0
  79. package/options.d.mts +20 -0
  80. package/options.d.mts.map +1 -0
  81. package/options.d.ts +20 -0
  82. package/options.d.ts.map +1 -0
  83. package/options.js +121 -0
  84. package/options.js.map +1 -0
  85. package/options.mjs +114 -0
  86. package/options.mjs.map +1 -0
  87. package/package.json +216 -0
  88. package/server.d.mts +38 -0
  89. package/server.d.mts.map +1 -0
  90. package/server.d.ts +38 -0
  91. package/server.d.ts.map +1 -0
  92. package/server.js +162 -0
  93. package/server.js.map +1 -0
  94. package/server.mjs +152 -0
  95. package/server.mjs.map +1 -0
  96. package/src/auth.ts +42 -0
  97. package/src/code-tool-paths.cts +5 -0
  98. package/src/code-tool-types.ts +17 -0
  99. package/src/code-tool-worker.ts +649 -0
  100. package/src/code-tool.ts +316 -0
  101. package/src/http.ts +227 -0
  102. package/src/index.ts +67 -0
  103. package/src/instructions.ts +59 -0
  104. package/src/logger.ts +28 -0
  105. package/src/methods.ts +2306 -0
  106. package/src/options.ts +159 -0
  107. package/src/server.ts +202 -0
  108. package/src/stdio.ts +17 -0
  109. package/src/tsconfig.json +11 -0
  110. package/src/types.ts +126 -0
  111. package/src/util.ts +25 -0
  112. package/stdio.d.mts +3 -0
  113. package/stdio.d.mts.map +1 -0
  114. package/stdio.d.ts +3 -0
  115. package/stdio.d.ts.map +1 -0
  116. package/stdio.js +18 -0
  117. package/stdio.js.map +1 -0
  118. package/stdio.mjs +14 -0
  119. package/stdio.mjs.map +1 -0
  120. package/types.d.mts +65 -0
  121. package/types.d.mts.map +1 -0
  122. package/types.d.ts +65 -0
  123. package/types.d.ts.map +1 -0
  124. package/types.js +58 -0
  125. package/types.js.map +1 -0
  126. package/types.mjs +53 -0
  127. package/types.mjs.map +1 -0
  128. package/util.d.mts +4 -0
  129. package/util.d.mts.map +1 -0
  130. package/util.d.ts +4 -0
  131. package/util.d.ts.map +1 -0
  132. package/util.js +30 -0
  133. package/util.js.map +1 -0
  134. package/util.mjs +24 -0
  135. package/util.mjs.map +1 -0
@@ -0,0 +1,598 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+ import path from 'node:path';
3
+ import util from 'node:util';
4
+ import Fuse from 'fuse.js';
5
+ import ts from 'typescript';
6
+ import { OpenMRP } from '@openmrp/sdk';
7
+ async function tseval(code) {
8
+ return import('data:application/typescript;charset=utf-8;base64,' + Buffer.from(code).toString('base64'));
9
+ }
10
+ function getRunFunctionSource(code) {
11
+ const sourceFile = ts.createSourceFile('code.ts', code, ts.ScriptTarget.Latest, true);
12
+ const printer = ts.createPrinter();
13
+ for (const statement of sourceFile.statements) {
14
+ // Check for top-level function declarations
15
+ if (ts.isFunctionDeclaration(statement)) {
16
+ if (statement.name?.text === 'run') {
17
+ return {
18
+ type: 'declaration',
19
+ client: statement.parameters[0]?.name.getText(),
20
+ code: printer.printNode(ts.EmitHint.Unspecified, statement.body, sourceFile),
21
+ };
22
+ }
23
+ }
24
+ // Check for variable declarations: const run = () => {} or const run = function() {}
25
+ if (ts.isVariableStatement(statement)) {
26
+ for (const declaration of statement.declarationList.declarations) {
27
+ if (ts.isIdentifier(declaration.name) &&
28
+ declaration.name.text === 'run' &&
29
+ // Check if it's initialized with a function
30
+ declaration.initializer &&
31
+ (ts.isFunctionExpression(declaration.initializer) || ts.isArrowFunction(declaration.initializer))) {
32
+ return {
33
+ type: 'expression',
34
+ client: declaration.initializer.parameters[0]?.name.getText(),
35
+ code: printer.printNode(ts.EmitHint.Unspecified, declaration.initializer, sourceFile),
36
+ };
37
+ }
38
+ }
39
+ }
40
+ }
41
+ return null;
42
+ }
43
+ function getTSDiagnostics(code) {
44
+ const functionSource = getRunFunctionSource(code);
45
+ const codeWithImport = [
46
+ 'import { OpenMRP } from "@openmrp/sdk";',
47
+ functionSource.type === 'declaration' ?
48
+ `async function run(${functionSource.client}: OpenMRP)`
49
+ : `const run: (${functionSource.client}: OpenMRP) => Promise<unknown> =`,
50
+ functionSource.code,
51
+ ].join('\n');
52
+ const sourcePath = path.resolve('code.ts');
53
+ const ast = ts.createSourceFile(sourcePath, codeWithImport, ts.ScriptTarget.Latest, true);
54
+ const options = ts.getDefaultCompilerOptions();
55
+ options.target = ts.ScriptTarget.Latest;
56
+ options.module = ts.ModuleKind.NodeNext;
57
+ options.moduleResolution = ts.ModuleResolutionKind.NodeNext;
58
+ const host = ts.createCompilerHost(options, true);
59
+ const newHost = {
60
+ ...host,
61
+ getSourceFile: (...args) => {
62
+ if (path.resolve(args[0]) === sourcePath) {
63
+ return ast;
64
+ }
65
+ return host.getSourceFile(...args);
66
+ },
67
+ readFile: (...args) => {
68
+ if (path.resolve(args[0]) === sourcePath) {
69
+ return codeWithImport;
70
+ }
71
+ return host.readFile(...args);
72
+ },
73
+ fileExists: (...args) => {
74
+ if (path.resolve(args[0]) === sourcePath) {
75
+ return true;
76
+ }
77
+ return host.fileExists(...args);
78
+ },
79
+ };
80
+ const program = ts.createProgram({
81
+ options,
82
+ rootNames: [sourcePath],
83
+ host: newHost,
84
+ });
85
+ const diagnostics = ts.getPreEmitDiagnostics(program, ast);
86
+ return diagnostics.map((d) => {
87
+ const message = ts.flattenDiagnosticMessageText(d.messageText, '\n');
88
+ if (!d.file || !d.start)
89
+ return `- ${message}`;
90
+ const { line: lineNumber } = ts.getLineAndCharacterOfPosition(d.file, d.start);
91
+ const line = codeWithImport.split('\n').at(lineNumber)?.trim();
92
+ return line ? `- ${message}\n ${line}` : `- ${message}`;
93
+ });
94
+ }
95
+ const fuse = new Fuse([
96
+ 'client.auth.apiKeys.create',
97
+ 'client.auth.apiKeys.delete',
98
+ 'client.auth.apiKeys.list',
99
+ 'client.auth.apiKeys.retrieve',
100
+ 'client.auth.apiKeys.actions.rotate',
101
+ 'client.core.retrieveSearch',
102
+ 'client.core.sandboxes.create',
103
+ 'client.core.sandboxes.delete',
104
+ 'client.core.sandboxes.list',
105
+ 'client.core.sandboxes.retrieve',
106
+ 'client.core.requestLogs.list',
107
+ 'client.core.requestLogs.retrieve',
108
+ 'client.core.auditEvents.list',
109
+ 'client.core.auditEvents.retrieve',
110
+ 'client.core.auditEvents.retrieveResourceTypes',
111
+ 'client.core.addresses.retrieveSuggestions',
112
+ 'client.core.addresses.actions.validate',
113
+ 'client.core.emailLogs.list',
114
+ 'client.core.emailLogs.retrieve',
115
+ 'client.core.jobs.cancel',
116
+ 'client.core.jobs.retrieve',
117
+ 'client.core.analytics.updateDeliveryPerformance',
118
+ 'client.core.analytics.updateOee',
119
+ 'client.core.analytics.updateOeeTrend',
120
+ 'client.core.analytics.updateScheduleAttainment',
121
+ 'client.core.actions.emailRecord',
122
+ 'client.catalog.units.create',
123
+ 'client.catalog.units.delete',
124
+ 'client.catalog.units.list',
125
+ 'client.catalog.units.retrieve',
126
+ 'client.catalog.units.update',
127
+ 'client.catalog.units.actions.bulkUpsert',
128
+ 'client.catalog.unitGroups.create',
129
+ 'client.catalog.unitGroups.delete',
130
+ 'client.catalog.unitGroups.list',
131
+ 'client.catalog.unitGroups.retrieve',
132
+ 'client.catalog.unitGroups.update',
133
+ 'client.catalog.unitGroups.units.create',
134
+ 'client.catalog.unitGroups.units.delete',
135
+ 'client.catalog.unitGroups.units.list',
136
+ 'client.catalog.unitGroups.units.retrieve',
137
+ 'client.catalog.unitGroups.units.update',
138
+ 'client.catalog.unitGroups.actions.bulkUpsert',
139
+ 'client.catalog.properties.create',
140
+ 'client.catalog.properties.delete',
141
+ 'client.catalog.properties.list',
142
+ 'client.catalog.properties.retrieve',
143
+ 'client.catalog.properties.update',
144
+ 'client.catalog.properties.attributes.create',
145
+ 'client.catalog.properties.attributes.delete',
146
+ 'client.catalog.properties.attributes.list',
147
+ 'client.catalog.properties.attributes.retrieve',
148
+ 'client.catalog.properties.attributes.update',
149
+ 'client.catalog.properties.actions.bulkUpsert',
150
+ 'client.catalog.items.changeCategory',
151
+ 'client.catalog.items.list',
152
+ 'client.catalog.items.retrieve',
153
+ 'client.catalog.items.retrieveLotDefault',
154
+ 'client.catalog.items.inventory.list',
155
+ 'client.catalog.items.inventory.update',
156
+ 'client.catalog.items.attributes.delete',
157
+ 'client.catalog.items.attributes.update',
158
+ 'client.catalog.items.actions.bulkReconcile',
159
+ 'client.catalog.itemCategories.changeUnitGroup',
160
+ 'client.catalog.itemCategories.create',
161
+ 'client.catalog.itemCategories.delete',
162
+ 'client.catalog.itemCategories.list',
163
+ 'client.catalog.itemCategories.retrieve',
164
+ 'client.catalog.itemCategories.update',
165
+ 'client.catalog.itemCategories.properties.delete',
166
+ 'client.catalog.itemCategories.properties.update',
167
+ 'client.catalog.itemCategories.actions.bulkUpsert',
168
+ 'client.catalog.materials.create',
169
+ 'client.catalog.materials.delete',
170
+ 'client.catalog.materials.list',
171
+ 'client.catalog.materials.retrieve',
172
+ 'client.catalog.materials.update',
173
+ 'client.catalog.materials.actions.bulkUpsert',
174
+ 'client.catalog.parts.create',
175
+ 'client.catalog.parts.delete',
176
+ 'client.catalog.parts.list',
177
+ 'client.catalog.parts.retrieve',
178
+ 'client.catalog.parts.update',
179
+ 'client.catalog.parts.actions.bulkUpsert',
180
+ 'client.catalog.productLines.create',
181
+ 'client.catalog.productLines.delete',
182
+ 'client.catalog.productLines.list',
183
+ 'client.catalog.productLines.retrieve',
184
+ 'client.catalog.productLines.update',
185
+ 'client.catalog.productLines.actions.bulkUpsert',
186
+ 'client.catalog.products.changeProductLine',
187
+ 'client.catalog.products.create',
188
+ 'client.catalog.products.delete',
189
+ 'client.catalog.products.list',
190
+ 'client.catalog.products.retrieve',
191
+ 'client.catalog.products.update',
192
+ 'client.catalog.products.actions.bulkUpsert',
193
+ 'client.ai.retrieveToolGroups',
194
+ 'client.ai.retrieveTools',
195
+ 'client.ai.agents.create',
196
+ 'client.ai.agents.delete',
197
+ 'client.ai.agents.list',
198
+ 'client.ai.agents.retrieve',
199
+ 'client.ai.agents.update',
200
+ 'client.ai.agents.updateStatus',
201
+ 'client.ai.runs.create',
202
+ 'client.ai.runs.list',
203
+ 'client.ai.runs.retrieve',
204
+ 'client.ai.runs.actions.cancel',
205
+ 'client.ai.runs.actions.continue',
206
+ 'client.ai.runs.actions.retry',
207
+ 'client.ai.memories.create',
208
+ 'client.ai.memories.delete',
209
+ 'client.ai.memories.list',
210
+ 'client.ai.memories.retrieve',
211
+ 'client.ai.memories.update',
212
+ 'client.messaging.retrieveContacts',
213
+ 'client.messaging.notifications.create',
214
+ 'client.messaging.notifications.list',
215
+ 'client.messaging.notifications.retrieve',
216
+ 'client.messaging.notifications.retrieveUnreadCount',
217
+ 'client.messaging.notifications.retrieveUnreadSummary',
218
+ 'client.messaging.notifications.actions.dismiss',
219
+ 'client.messaging.notifications.actions.markAllSeen',
220
+ 'client.messaging.notifications.actions.read',
221
+ 'client.messaging.notifications.actions.seen',
222
+ 'client.messaging.announcements.list',
223
+ 'client.messaging.announcements.retrieve',
224
+ 'client.messaging.announcements.actions.dismiss',
225
+ 'client.messaging.announcements.actions.read',
226
+ 'client.messaging.announcements.actions.seen',
227
+ 'client.messaging.conversations.create',
228
+ 'client.messaging.conversations.list',
229
+ 'client.messaging.conversations.retrieve',
230
+ 'client.messaging.conversations.update',
231
+ 'client.messaging.conversations.actions.archive',
232
+ 'client.messaging.conversations.actions.assign',
233
+ 'client.messaging.conversations.actions.hide',
234
+ 'client.messaging.conversations.actions.leave',
235
+ 'client.messaging.conversations.actions.mute',
236
+ 'client.messaging.conversations.actions.read',
237
+ 'client.messaging.conversations.actions.redact',
238
+ 'client.messaging.conversations.actions.report',
239
+ 'client.messaging.conversations.actions.setLegalHold',
240
+ 'client.messaging.conversations.actions.setStatus',
241
+ 'client.messaging.conversations.actions.unarchive',
242
+ 'client.messaging.conversations.actions.unhide',
243
+ 'client.messaging.conversations.actions.unmute',
244
+ 'client.messaging.conversations.links.create',
245
+ 'client.messaging.conversations.links.delete',
246
+ 'client.messaging.conversations.links.list',
247
+ 'client.messaging.conversations.messages.create',
248
+ 'client.messaging.conversations.messages.list',
249
+ 'client.messaging.conversations.participants.create',
250
+ 'client.messaging.conversations.participants.delete',
251
+ 'client.messaging.conversations.participants.actions.setRole',
252
+ 'client.messaging.conversations.attachments.actions.uploadURL',
253
+ 'client.messaging.messages.update',
254
+ 'client.messaging.messages.actions.approveSend',
255
+ 'client.messaging.messages.actions.cancel',
256
+ 'client.messaging.messages.actions.reject',
257
+ 'client.messaging.groups.create',
258
+ 'client.messaging.groups.delete',
259
+ 'client.messaging.groups.list',
260
+ 'client.messaging.groups.retrieve',
261
+ 'client.messaging.groups.update',
262
+ 'client.messaging.groups.members.create',
263
+ 'client.messaging.groups.members.delete',
264
+ 'client.messaging.blocks.create',
265
+ 'client.messaging.blocks.delete',
266
+ 'client.messaging.blocks.list',
267
+ 'client.messaging.preferences.list',
268
+ 'client.messaging.preferences.update',
269
+ 'client.messaging.emailDomains.create',
270
+ 'client.messaging.emailDomains.delete',
271
+ 'client.messaging.emailDomains.list',
272
+ 'client.messaging.emailDomains.retrieve',
273
+ 'client.messaging.emailDomains.actions.verify',
274
+ 'client.messaging.emailInboxes.create',
275
+ 'client.messaging.emailInboxes.delete',
276
+ 'client.messaging.emailInboxes.list',
277
+ 'client.messaging.emailInboxes.retrieve',
278
+ 'client.messaging.emailInboxes.update',
279
+ 'client.sales.accountGroups.create',
280
+ 'client.sales.accountGroups.delete',
281
+ 'client.sales.accountGroups.list',
282
+ 'client.sales.accountGroups.retrieve',
283
+ 'client.sales.accountGroups.update',
284
+ 'client.sales.accountPrices.create',
285
+ 'client.sales.accountPrices.delete',
286
+ 'client.sales.accountPrices.list',
287
+ 'client.sales.accountPrices.retrieve',
288
+ 'client.sales.accountPrices.update',
289
+ 'client.sales.accountPrices.actions.exportPriceList',
290
+ 'client.sales.addresses.create',
291
+ 'client.sales.addresses.delete',
292
+ 'client.sales.addresses.list',
293
+ 'client.sales.addresses.retrieve',
294
+ 'client.sales.addresses.update',
295
+ 'client.sales.accountStatuses.list',
296
+ 'client.sales.accountStatuses.retrieve',
297
+ 'client.sales.accountUsers.salesTargets.create',
298
+ 'client.sales.accountUsers.salesTargets.list',
299
+ 'client.sales.accountUsers.salesTargets.update',
300
+ 'client.sales.priorities.list',
301
+ 'client.sales.priorities.retrieve',
302
+ 'client.sales.customers.create',
303
+ 'client.sales.customers.delete',
304
+ 'client.sales.customers.list',
305
+ 'client.sales.customers.retrieve',
306
+ 'client.sales.customers.retrieveLeadTime',
307
+ 'client.sales.customers.update',
308
+ 'client.sales.customers.actions.merge',
309
+ 'client.sales.contacts.actions.findByEmail',
310
+ 'client.sales.orderDiscounts.create',
311
+ 'client.sales.orderDiscounts.delete',
312
+ 'client.sales.orderDiscounts.list',
313
+ 'client.sales.orderDiscounts.retrieve',
314
+ 'client.sales.orderDiscounts.update',
315
+ 'client.sales.orderDiscounts.actions.findByCode',
316
+ 'client.sales.salesOrders.checkout',
317
+ 'client.sales.salesOrders.create',
318
+ 'client.sales.salesOrders.delete',
319
+ 'client.sales.salesOrders.list',
320
+ 'client.sales.salesOrders.priceQuote',
321
+ 'client.sales.salesOrders.retrieve',
322
+ 'client.sales.salesOrders.retrieveStatuses',
323
+ 'client.sales.salesOrders.update',
324
+ 'client.sales.salesOrders.actions.bulkDelete',
325
+ 'client.sales.salesOrders.actions.close',
326
+ 'client.sales.salesOrders.actions.createProductionRun',
327
+ 'client.sales.salesOrders.actions.issue',
328
+ 'client.sales.salesOrders.actions.open',
329
+ 'client.sales.salesOrders.actions.quoteCommitment',
330
+ 'client.sales.salesOrders.actions.quoteFreight',
331
+ 'client.sales.salesOrders.actions.unissue',
332
+ 'client.sales.salesOrders.lines.create',
333
+ 'client.sales.salesOrders.lines.delete',
334
+ 'client.sales.salesOrders.lines.update',
335
+ 'client.sales.salesOrders.lines.actions.reorder',
336
+ 'client.sales.volumeDiscounts.create',
337
+ 'client.sales.volumeDiscounts.delete',
338
+ 'client.sales.volumeDiscounts.list',
339
+ 'client.sales.volumeDiscounts.retrieve',
340
+ 'client.sales.volumeDiscounts.update',
341
+ 'client.finance.retrieveAdjustmentTypes',
342
+ 'client.finance.retrieveTransactionMethods',
343
+ 'client.finance.retrieveTransactionTypes',
344
+ 'client.finance.paymentTerms.create',
345
+ 'client.finance.paymentTerms.delete',
346
+ 'client.finance.paymentTerms.list',
347
+ 'client.finance.paymentTerms.retrieve',
348
+ 'client.finance.paymentTerms.update',
349
+ 'client.operations.retrieveDemandOverrideTypes',
350
+ 'client.operations.retrieveMachineDowntimeReasons',
351
+ 'client.operations.retrieveMachineStatus',
352
+ 'client.operations.retrieveScheduleDeviationTypes',
353
+ 'client.operations.shippingTerms.create',
354
+ 'client.operations.shippingTerms.delete',
355
+ 'client.operations.shippingTerms.list',
356
+ 'client.operations.shippingTerms.retrieve',
357
+ 'client.operations.shippingTerms.update',
358
+ 'client.operations.carriers.create',
359
+ 'client.operations.carriers.delete',
360
+ 'client.operations.carriers.list',
361
+ 'client.operations.carriers.retrieve',
362
+ 'client.operations.carriers.update',
363
+ 'client.operations.carriers.serviceLevels.create',
364
+ 'client.operations.carriers.serviceLevels.delete',
365
+ 'client.operations.carriers.serviceLevels.list',
366
+ 'client.operations.carriers.serviceLevels.retrieve',
367
+ 'client.operations.carriers.serviceLevels.update',
368
+ 'client.operations.departments.create',
369
+ 'client.operations.departments.delete',
370
+ 'client.operations.departments.list',
371
+ 'client.operations.departments.retrieve',
372
+ 'client.operations.departments.update',
373
+ 'client.operations.machines.create',
374
+ 'client.operations.machines.delete',
375
+ 'client.operations.machines.list',
376
+ 'client.operations.machines.retrieve',
377
+ 'client.operations.machines.update',
378
+ 'client.operations.machineDowntimeEvents.create',
379
+ 'client.operations.machineDowntimeEvents.delete',
380
+ 'client.operations.machineDowntimeEvents.list',
381
+ 'client.operations.machineDowntimeEvents.retrieve',
382
+ 'client.operations.machineDowntimeEvents.update',
383
+ 'client.operations.demandOverrides.create',
384
+ 'client.operations.demandOverrides.delete',
385
+ 'client.operations.demandOverrides.list',
386
+ 'client.operations.demandOverrides.retrieve',
387
+ 'client.operations.demandOverrides.update',
388
+ 'client.operations.productionSchedules.create',
389
+ 'client.operations.productionSchedules.delete',
390
+ 'client.operations.productionSchedules.list',
391
+ 'client.operations.productionSchedules.retrieve',
392
+ 'client.operations.productionSchedules.retrieveAtRiskOrders',
393
+ 'client.operations.productionSchedules.retrieveCurrent',
394
+ 'client.operations.productionSchedules.retrieveDerivedLines',
395
+ 'client.operations.productionSchedules.retrieveDeviations',
396
+ 'client.operations.productionSchedules.retrieveFinishedPolicies',
397
+ 'client.operations.productionSchedules.retrieveFinishingLines',
398
+ 'client.operations.productionSchedules.retrieveItemPolicies',
399
+ 'client.operations.productionSchedules.retrieveWeekReleasePreview',
400
+ 'client.operations.productionSchedules.lines.create',
401
+ 'client.operations.productionSchedules.lines.delete',
402
+ 'client.operations.productionSchedules.lines.list',
403
+ 'client.operations.productionSchedules.lines.update',
404
+ 'client.operations.productionSchedules.actions.archive',
405
+ 'client.operations.productionSchedules.actions.preview',
406
+ 'client.operations.productionSchedules.actions.previewRegenerate',
407
+ 'client.operations.productionSchedules.actions.publish',
408
+ 'client.operations.productionSchedules.actions.regenerate',
409
+ 'client.operations.productionSchedules.actions.releaseWeek',
410
+ 'client.operations.productionScheduleSettings.list',
411
+ 'client.operations.productionScheduleSettings.update',
412
+ 'client.operations.productionScheduleSettings.resources.delete',
413
+ 'client.operations.productionScheduleSettings.resources.list',
414
+ 'client.operations.productionScheduleSettings.resources.update',
415
+ 'client.operations.productionScheduleSettings.items.delete',
416
+ 'client.operations.productionScheduleSettings.items.list',
417
+ 'client.operations.productionScheduleSettings.items.retrieve',
418
+ 'client.operations.productionScheduleSettings.items.update',
419
+ 'client.operations.fulfillmentRecommendations.list',
420
+ 'client.operations.fulfillmentRecommendations.actions.apply',
421
+ 'client.operations.operatingCalendars.create',
422
+ 'client.operations.operatingCalendars.delete',
423
+ 'client.operations.operatingCalendars.list',
424
+ 'client.operations.operatingCalendars.retrieve',
425
+ 'client.operations.operatingCalendars.update',
426
+ 'client.operations.operatingCalendars.closures.create',
427
+ 'client.operations.operatingCalendars.closures.delete',
428
+ 'client.operations.operatingCalendars.closures.list',
429
+ 'client.operations.locations.create',
430
+ 'client.operations.locations.delete',
431
+ 'client.operations.locations.list',
432
+ 'client.operations.locations.retrieve',
433
+ 'client.operations.locations.update',
434
+ 'client.operations.locations.actions.bulkUpsert',
435
+ 'client.operations.locationTypes.list',
436
+ 'client.operations.locationTypes.retrieve',
437
+ 'client.operations.shipments.actions.rateShop',
438
+ 'client.operations.scanningStations.create',
439
+ 'client.operations.scanningStations.delete',
440
+ 'client.operations.scanningStations.list',
441
+ 'client.operations.scanningStations.retrieve',
442
+ 'client.operations.scanningStations.update',
443
+ 'client.identity.retrievePermissionGroups',
444
+ 'client.identity.accountUsers.create',
445
+ 'client.identity.accountUsers.list',
446
+ 'client.identity.accountUsers.retrieve',
447
+ 'client.identity.accountUsers.update',
448
+ 'client.identity.accountUsers.actions.activate',
449
+ 'client.identity.accountUsers.actions.disable',
450
+ 'client.identity.accountUsers.actions.remove',
451
+ 'client.identity.accounts.updateFavicon',
452
+ 'client.identity.roles.create',
453
+ 'client.identity.roles.delete',
454
+ 'client.identity.roles.list',
455
+ 'client.identity.roles.retrieve',
456
+ 'client.identity.roles.update',
457
+ 'client.settings.portalDomains.create',
458
+ 'client.settings.portalDomains.delete',
459
+ 'client.settings.portalDomains.list',
460
+ 'client.settings.portalDomains.retrieve',
461
+ 'client.settings.portalDomains.actions.verify',
462
+ 'client.settings.integrations.create',
463
+ 'client.settings.integrations.delete',
464
+ 'client.settings.integrations.list',
465
+ 'client.settings.integrations.update',
466
+ ], { threshold: 1, shouldSort: true });
467
+ function getMethodSuggestions(fullyQualifiedMethodName) {
468
+ return fuse
469
+ .search(fullyQualifiedMethodName)
470
+ .map(({ item }) => item)
471
+ .slice(0, 5);
472
+ }
473
+ const proxyToObj = new WeakMap();
474
+ const objToProxy = new WeakMap();
475
+ function makeSdkProxy(obj, { path, isBelievedBad = false }) {
476
+ let proxy = objToProxy.get(obj);
477
+ if (!proxy) {
478
+ proxy = new Proxy(obj, {
479
+ get(target, prop, receiver) {
480
+ const propPath = [...path, String(prop)];
481
+ const value = Reflect.get(target, prop, receiver);
482
+ if (isBelievedBad || (!(prop in target) && value === undefined)) {
483
+ // If we're accessing a path that doesn't exist, it will probably eventually error.
484
+ // Let's proxy it and mark it bad so that we can control the error message.
485
+ // We proxy an empty class so that an invocation or construction attempt is possible.
486
+ return makeSdkProxy(class {
487
+ }, { path: propPath, isBelievedBad: true });
488
+ }
489
+ if (value !== null && (typeof value === 'object' || typeof value === 'function')) {
490
+ return makeSdkProxy(value, { path: propPath, isBelievedBad });
491
+ }
492
+ return value;
493
+ },
494
+ apply(target, thisArg, args) {
495
+ if (isBelievedBad || typeof target !== 'function') {
496
+ const fullyQualifiedMethodName = path.join('.');
497
+ const suggestions = getMethodSuggestions(fullyQualifiedMethodName);
498
+ throw new Error(`${fullyQualifiedMethodName} is not a function. Did you mean: ${suggestions.join(', ')}`);
499
+ }
500
+ return Reflect.apply(target, proxyToObj.get(thisArg) ?? thisArg, args);
501
+ },
502
+ construct(target, args, newTarget) {
503
+ if (isBelievedBad || typeof target !== 'function') {
504
+ const fullyQualifiedMethodName = path.join('.');
505
+ const suggestions = getMethodSuggestions(fullyQualifiedMethodName);
506
+ throw new Error(`${fullyQualifiedMethodName} is not a constructor. Did you mean: ${suggestions.join(', ')}`);
507
+ }
508
+ return Reflect.construct(target, args, newTarget);
509
+ },
510
+ });
511
+ objToProxy.set(obj, proxy);
512
+ proxyToObj.set(proxy, obj);
513
+ }
514
+ return proxy;
515
+ }
516
+ function parseError(code, error) {
517
+ if (!(error instanceof Error))
518
+ return;
519
+ const cause = error.cause instanceof Error ? `: ${error.cause.message}` : '';
520
+ const message = error.name ? `${error.name}: ${error.message}${cause}` : `${error.message}${cause}`;
521
+ try {
522
+ // Deno uses V8; the first "<anonymous>:LINE:COLUMN" is the top of stack.
523
+ const lineNumber = error.stack?.match(/<anonymous>:([0-9]+):[0-9]+/)?.[1];
524
+ // -1 for the zero-based indexing
525
+ const line = lineNumber &&
526
+ code
527
+ .split('\n')
528
+ .at(parseInt(lineNumber, 10) - 1)
529
+ ?.trim();
530
+ return line ? `${message}\n at line ${lineNumber}\n ${line}` : message;
531
+ }
532
+ catch {
533
+ return message;
534
+ }
535
+ }
536
+ const fetch = async (req) => {
537
+ const { opts, code } = (await req.json());
538
+ const runFunctionSource = code ? getRunFunctionSource(code) : null;
539
+ if (!runFunctionSource) {
540
+ const message = code ?
541
+ 'The code is missing a top-level `run` function.'
542
+ : 'The code argument is missing. Provide one containing a top-level `run` function.';
543
+ return Response.json({
544
+ is_error: true,
545
+ result: `${message} Write code within this template:\n\n\`\`\`\nasync function run(client) {\n // Fill this out\n}\n\`\`\``,
546
+ log_lines: [],
547
+ err_lines: [],
548
+ }, { status: 400, statusText: 'Code execution error' });
549
+ }
550
+ const diagnostics = getTSDiagnostics(code);
551
+ if (diagnostics.length > 0) {
552
+ return Response.json({
553
+ is_error: true,
554
+ result: `The code contains TypeScript diagnostics:\n${diagnostics.join('\n')}`,
555
+ log_lines: [],
556
+ err_lines: [],
557
+ }, { status: 400, statusText: 'Code execution error' });
558
+ }
559
+ const client = new OpenMRP({
560
+ ...opts,
561
+ });
562
+ const log_lines = [];
563
+ const err_lines = [];
564
+ const originalConsole = globalThis.console;
565
+ globalThis.console = {
566
+ ...originalConsole,
567
+ log: (...args) => {
568
+ log_lines.push(util.format(...args));
569
+ },
570
+ error: (...args) => {
571
+ err_lines.push(util.format(...args));
572
+ },
573
+ };
574
+ try {
575
+ let run_ = async (client) => { };
576
+ run_ = (await tseval(`${code}\nexport default run;`)).default;
577
+ const result = await run_(makeSdkProxy(client, { path: ['client'] }));
578
+ return Response.json({
579
+ is_error: false,
580
+ result,
581
+ log_lines,
582
+ err_lines,
583
+ });
584
+ }
585
+ catch (e) {
586
+ return Response.json({
587
+ is_error: true,
588
+ result: parseError(code, e),
589
+ log_lines,
590
+ err_lines,
591
+ }, { status: 400, statusText: 'Code execution error' });
592
+ }
593
+ finally {
594
+ globalThis.console = originalConsole;
595
+ }
596
+ };
597
+ export default { fetch };
598
+ //# sourceMappingURL=code-tool-worker.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code-tool-worker.mjs","sourceRoot":"","sources":["src/code-tool-worker.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAE/E,IAAI,MAAM,WAAW;OACrB,IAAI,MAAM,WAAW;OACrB,IAAI,MAAM,SAAS;OACnB,EAAE,MAAM,YAAY;OAEpB,EAAE,OAAO,EAAiB,MAAM,cAAc;AAErD,KAAK,UAAU,MAAM,CAAC,IAAY;IAChC,OAAO,MAAM,CAAC,mDAAmD,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE;AAC5G,CAAC;AAED,SAAS,oBAAoB,CAAC,IAAY;IAKxC,MAAM,UAAU,GAAG,EAAE,CAAC,gBAAgB,CAAC,SA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,CAAC,CAAC;QACtE,OAAO,QAAQ,CAAC,IAAI,CAAC;YACnB,QAAQ,EAAE,KAAK;YACf,MAAM;YACN,SAAS;YACT,SAAS;SACa,CAAC,CAAC;IAC5B,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,QAAQ,CAAC,IAAI,CAClB;YACE,QAAQ,EAAE,IAAI;YACd,MAAM,EAAE,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC;YAC3B,SAAS;YACT,SAAS;SACa,EACxB,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,sBAAsB,EAAE,CACpD,CAAC;IACJ,CAAC;YAAS,CAAC;QACT,UAAU,CAAC,OAAO,GAAG,eAAe,CAAC;IACvC,CAAC;AACH,CAAC,CAAC;AAEF,eAAe,EAAE,KAAK,EAAE,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { McpTool } from "./types.mjs";
2
+ import { SdkMethod } from "./methods.mjs";
3
+ import { McpCodeExecutionMode } from "./options.mjs";
4
+ /**
5
+ * A tool that runs code against a copy of the SDK.
6
+ *
7
+ * Instead of exposing every endpoint as its own tool, which uses up too many tokens for LLMs to use at once,
8
+ * we expose a single tool that can be used to search for endpoints by name, resource, operation, or tag, and then
9
+ * a generic endpoint that can be used to invoke any endpoint with the provided arguments.
10
+ *
11
+ * @param blockedMethods - The methods to block for code execution. Blocking is done by simple string
12
+ * matching, so it is not secure against obfuscation. For stronger security, block in the downstream API
13
+ * with limited API keys.
14
+ * @param codeExecutionMode - Whether to execute code in a local Deno environment or in a remote
15
+ * sandbox environment hosted by Stainless.
16
+ */
17
+ export declare function codeTool({ blockedMethods, codeExecutionMode, }: {
18
+ blockedMethods: SdkMethod[] | undefined;
19
+ codeExecutionMode: McpCodeExecutionMode;
20
+ }): McpTool;
21
+ //# sourceMappingURL=code-tool.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code-tool.d.mts","sourceRoot":"","sources":["src/code-tool.ts"],"names":[],"mappings":"OAEO,EAAmC,OAAO,EAA2C;OAIrF,EAAE,SAAS,EAAE;OACb,EAAE,oBAAoB,EAAE;AAyB/B;;;;;;;;;;;;GAYG;AACH,wBAAgB,QAAQ,CAAC,EACvB,cAAc,EACd,iBAAiB,GAClB,EAAE;IACD,cAAc,EAAE,SAAS,EAAE,GAAG,SAAS,CAAC;IACxC,iBAAiB,EAAE,oBAAoB,CAAC;CACzC,GAAG,OAAO,CAkEV"}