@stigg/typescript-mcp 0.1.0-alpha.10

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 +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-paths.cjs +6 -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 +283 -0
  28. package/code-tool-worker.js.map +1 -0
  29. package/code-tool-worker.mjs +278 -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 +313 -0
  36. package/code-tool.js.map +1 -0
  37. package/code-tool.mjs +274 -0
  38. package/code-tool.mjs.map +1 -0
  39. package/docs-search-tool.d.mts +57 -0
  40. package/docs-search-tool.d.mts.map +1 -0
  41. package/docs-search-tool.d.ts +57 -0
  42. package/docs-search-tool.d.ts.map +1 -0
  43. package/docs-search-tool.js +55 -0
  44. package/docs-search-tool.js.map +1 -0
  45. package/docs-search-tool.mjs +51 -0
  46. package/docs-search-tool.mjs.map +1 -0
  47. package/http.d.mts +14 -0
  48. package/http.d.mts.map +1 -0
  49. package/http.d.ts +14 -0
  50. package/http.d.ts.map +1 -0
  51. package/http.js +95 -0
  52. package/http.js.map +1 -0
  53. package/http.mjs +87 -0
  54. package/http.mjs.map +1 -0
  55. package/index.d.mts +3 -0
  56. package/index.d.mts.map +1 -0
  57. package/index.d.ts +3 -0
  58. package/index.d.ts.map +1 -0
  59. package/index.js +59 -0
  60. package/index.js.map +1 -0
  61. package/index.mjs +57 -0
  62. package/index.mjs.map +1 -0
  63. package/instructions.d.mts +2 -0
  64. package/instructions.d.mts.map +1 -0
  65. package/instructions.d.ts +2 -0
  66. package/instructions.d.ts.map +1 -0
  67. package/instructions.js +55 -0
  68. package/instructions.js.map +1 -0
  69. package/instructions.mjs +52 -0
  70. package/instructions.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 +419 -0
  76. package/methods.js.map +1 -0
  77. package/methods.mjs +415 -0
  78. package/methods.mjs.map +1 -0
  79. package/options.d.mts +18 -0
  80. package/options.d.mts.map +1 -0
  81. package/options.d.ts +18 -0
  82. package/options.d.ts.map +1 -0
  83. package/options.js +107 -0
  84. package/options.js.map +1 -0
  85. package/options.mjs +100 -0
  86. package/options.mjs.map +1 -0
  87. package/package.json +211 -0
  88. package/server.d.mts +29 -0
  89. package/server.d.mts.map +1 -0
  90. package/server.d.ts +29 -0
  91. package/server.d.ts.map +1 -0
  92. package/server.js +157 -0
  93. package/server.js.map +1 -0
  94. package/server.mjs +147 -0
  95. package/server.mjs.map +1 -0
  96. package/src/auth.ts +25 -0
  97. package/src/code-tool-paths.cts +3 -0
  98. package/src/code-tool-types.ts +17 -0
  99. package/src/code-tool-worker.ts +329 -0
  100. package/src/code-tool.ts +357 -0
  101. package/src/docs-search-tool.ts +68 -0
  102. package/src/http.ts +127 -0
  103. package/src/index.ts +65 -0
  104. package/src/instructions.ts +74 -0
  105. package/src/methods.ts +440 -0
  106. package/src/options.ts +141 -0
  107. package/src/server.ts +184 -0
  108. package/src/stdio.ts +13 -0
  109. package/src/tsconfig.json +11 -0
  110. package/src/types.ts +123 -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 +14 -0
  117. package/stdio.js.map +1 -0
  118. package/stdio.mjs +10 -0
  119. package/stdio.mjs.map +1 -0
  120. package/types.d.mts +59 -0
  121. package/types.d.mts.map +1 -0
  122. package/types.d.ts +59 -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
package/code-tool.js ADDED
@@ -0,0 +1,313 @@
1
+ "use strict";
2
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || (function () {
20
+ var ownKeys = function(o) {
21
+ ownKeys = Object.getOwnPropertyNames || function (o) {
22
+ var ar = [];
23
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
+ return ar;
25
+ };
26
+ return ownKeys(o);
27
+ };
28
+ return function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ })();
36
+ var __importDefault = (this && this.__importDefault) || function (mod) {
37
+ return (mod && mod.__esModule) ? mod : { "default": mod };
38
+ };
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ exports.codeTool = codeTool;
41
+ const node_fs_1 = __importDefault(require("node:fs"));
42
+ const node_path_1 = __importDefault(require("node:path"));
43
+ const node_url_1 = __importDefault(require("node:url"));
44
+ const deno_http_worker_1 = require("@valtown/deno-http-worker");
45
+ const code_tool_paths_cjs_1 = require("./code-tool-paths.cjs");
46
+ const types_1 = require("./types.js");
47
+ const util_1 = require("./util.js");
48
+ const prompt = `Runs JavaScript code to interact with the Stigg API.
49
+
50
+ You are a skilled programmer writing code to interface with the service.
51
+ Define an async function named "run" that takes a single parameter of an initialized SDK client and it will be run.
52
+ For example:
53
+
54
+ \`\`\`
55
+ async function run(client) {
56
+ const customerResponse = await client.v1.customers.retrieve('REPLACE_ME');
57
+
58
+ console.log(customerResponse.data);
59
+ }
60
+ \`\`\`
61
+
62
+ You will be returned anything that your function returns, plus the results of any console.log statements.
63
+ Do not add try-catch blocks for single API calls. The tool will handle errors for you.
64
+ Do not add comments unless necessary for generating better code.
65
+ Code will run in a container, and cannot interact with the network outside of the given SDK client.
66
+ Variables will not persist between calls, so make sure to return or log any data you might need later.`;
67
+ /**
68
+ * A tool that runs code against a copy of the SDK.
69
+ *
70
+ * Instead of exposing every endpoint as its own tool, which uses up too many tokens for LLMs to use at once,
71
+ * we expose a single tool that can be used to search for endpoints by name, resource, operation, or tag, and then
72
+ * a generic endpoint that can be used to invoke any endpoint with the provided arguments.
73
+ *
74
+ * @param blockedMethods - The methods to block for code execution. Blocking is done by simple string
75
+ * matching, so it is not secure against obfuscation. For stronger security, block in the downstream API
76
+ * with limited API keys.
77
+ * @param codeExecutionMode - Whether to execute code in a local Deno environment or in a remote
78
+ * sandbox environment hosted by Stainless.
79
+ */
80
+ function codeTool({ blockedMethods, codeExecutionMode, }) {
81
+ const metadata = { resource: 'all', operation: 'write', tags: [] };
82
+ const tool = {
83
+ name: 'execute',
84
+ description: prompt,
85
+ inputSchema: {
86
+ type: 'object',
87
+ properties: {
88
+ code: {
89
+ type: 'string',
90
+ description: 'Code to execute.',
91
+ },
92
+ intent: {
93
+ type: 'string',
94
+ description: 'Task you are trying to perform. Used for improving the service.',
95
+ },
96
+ },
97
+ required: ['code'],
98
+ },
99
+ };
100
+ const handler = async ({ reqContext, args, }) => {
101
+ const code = args.code;
102
+ // Do very basic blocking of code that includes forbidden method names.
103
+ //
104
+ // WARNING: This is not secure against obfuscation and other evasion methods. If
105
+ // stronger security blocks are required, then these should be enforced in the downstream
106
+ // API (e.g., by having users call the MCP server with API keys with limited permissions).
107
+ if (blockedMethods) {
108
+ const blockedMatches = blockedMethods.filter((method) => code.includes(method.fullyQualifiedName));
109
+ if (blockedMatches.length > 0) {
110
+ return (0, types_1.asErrorResult)(`The following methods have been blocked by the MCP server and cannot be used in code execution: ${blockedMatches
111
+ .map((m) => m.fullyQualifiedName)
112
+ .join(', ')}`);
113
+ }
114
+ }
115
+ if (codeExecutionMode === 'local') {
116
+ return await localDenoHandler({ reqContext, args });
117
+ }
118
+ else {
119
+ return await remoteStainlessHandler({ reqContext, args });
120
+ }
121
+ };
122
+ return { metadata, tool, handler };
123
+ }
124
+ const remoteStainlessHandler = async ({ reqContext, args, }) => {
125
+ const code = args.code;
126
+ const intent = args.intent;
127
+ const client = reqContext.client;
128
+ const codeModeEndpoint = (0, util_1.readEnv)('CODE_MODE_ENDPOINT_URL') ?? 'https://api.stainless.com/api/ai/code-tool';
129
+ // Setting a Stainless API key authenticates requests to the code tool endpoint.
130
+ const res = await fetch(codeModeEndpoint, {
131
+ method: 'POST',
132
+ headers: {
133
+ ...(reqContext.stainlessApiKey && { Authorization: reqContext.stainlessApiKey }),
134
+ 'Content-Type': 'application/json',
135
+ client_envs: JSON.stringify({
136
+ STIGG_API_KEY: (0, util_1.requireValue)((0, util_1.readEnv)('STIGG_API_KEY') ?? client.apiKey, 'set STIGG_API_KEY environment variable or provide apiKey client option'),
137
+ STIGG_BASE_URL: (0, util_1.readEnv)('STIGG_BASE_URL') ?? client.baseURL ?? undefined,
138
+ }),
139
+ },
140
+ body: JSON.stringify({
141
+ project_name: 'stigg',
142
+ code,
143
+ intent,
144
+ client_opts: {},
145
+ }),
146
+ });
147
+ if (!res.ok) {
148
+ throw new Error(`${res.status}: ${res.statusText} error when trying to contact Code Tool server. Details: ${await res.text()}`);
149
+ }
150
+ const { is_error, result, log_lines, err_lines } = (await res.json());
151
+ const hasLogs = log_lines.length > 0 || err_lines.length > 0;
152
+ const output = {
153
+ result,
154
+ ...(log_lines.length > 0 && { log_lines }),
155
+ ...(err_lines.length > 0 && { err_lines }),
156
+ };
157
+ if (is_error) {
158
+ return (0, types_1.asErrorResult)(typeof result === 'string' && !hasLogs ? result : JSON.stringify(output, null, 2));
159
+ }
160
+ return (0, types_1.asTextContentResult)(output);
161
+ };
162
+ const localDenoHandler = async ({ reqContext, args, }) => {
163
+ const client = reqContext.client;
164
+ const baseURLHostname = new URL(client.baseURL).hostname;
165
+ const { code } = args;
166
+ let denoPath;
167
+ const packageRoot = node_path_1.default.resolve(node_path_1.default.dirname(code_tool_paths_cjs_1.workerPath), '..');
168
+ const packageNodeModulesPath = node_path_1.default.resolve(packageRoot, 'node_modules');
169
+ // Check if deno is in PATH
170
+ const { execSync } = await Promise.resolve().then(() => __importStar(require('node:child_process')));
171
+ try {
172
+ execSync('command -v deno', { stdio: 'ignore' });
173
+ denoPath = 'deno';
174
+ }
175
+ catch {
176
+ try {
177
+ // Use deno binary in node_modules if it's found
178
+ const denoNodeModulesPath = node_path_1.default.resolve(packageNodeModulesPath, 'deno', 'bin.cjs');
179
+ await node_fs_1.default.promises.access(denoNodeModulesPath, node_fs_1.default.constants.X_OK);
180
+ denoPath = denoNodeModulesPath;
181
+ }
182
+ catch {
183
+ return (0, types_1.asErrorResult)('Deno is required for code execution but was not found. ' +
184
+ 'Install it from https://deno.land or run: npm install deno');
185
+ }
186
+ }
187
+ const allowReadPaths = [
188
+ 'code-tool-worker.mjs',
189
+ `${code_tool_paths_cjs_1.workerPath.replace(/([\/\\]node_modules)[\/\\].+$/, '$1')}/`,
190
+ packageRoot,
191
+ ];
192
+ // Follow symlinks in node_modules to allow read access to workspace-linked packages
193
+ try {
194
+ const sdkPkgName = '@stigg/typescript';
195
+ const sdkDir = node_path_1.default.resolve(packageNodeModulesPath, sdkPkgName);
196
+ const realSdkDir = node_fs_1.default.realpathSync(sdkDir);
197
+ if (realSdkDir !== sdkDir) {
198
+ allowReadPaths.push(realSdkDir);
199
+ }
200
+ }
201
+ catch {
202
+ // Ignore if symlink resolution fails
203
+ }
204
+ const allowRead = allowReadPaths.join(',');
205
+ const worker = await (0, deno_http_worker_1.newDenoHTTPWorker)(node_url_1.default.pathToFileURL(code_tool_paths_cjs_1.workerPath), {
206
+ denoExecutable: denoPath,
207
+ runFlags: [
208
+ `--node-modules-dir=manual`,
209
+ `--allow-read=${allowRead}`,
210
+ `--allow-net=${baseURLHostname}`,
211
+ // Allow environment variables because instantiating the client will try to read from them,
212
+ // even though they are not set.
213
+ '--allow-env',
214
+ ],
215
+ printOutput: true,
216
+ spawnOptions: {
217
+ cwd: node_path_1.default.dirname(code_tool_paths_cjs_1.workerPath),
218
+ },
219
+ });
220
+ try {
221
+ const resp = await new Promise((resolve, reject) => {
222
+ worker.addEventListener('exit', (exitCode) => {
223
+ reject(new Error(`Worker exited with code ${exitCode}`));
224
+ });
225
+ const opts = {
226
+ baseURL: client.baseURL,
227
+ apiKey: client.apiKey,
228
+ defaultHeaders: {
229
+ 'X-Stainless-MCP': 'true',
230
+ },
231
+ };
232
+ const req = worker.request('http://localhost', {
233
+ headers: {
234
+ 'content-type': 'application/json',
235
+ },
236
+ method: 'POST',
237
+ }, (resp) => {
238
+ const body = [];
239
+ resp.on('error', (err) => {
240
+ reject(err);
241
+ });
242
+ resp.on('data', (chunk) => {
243
+ body.push(chunk);
244
+ });
245
+ resp.on('end', () => {
246
+ resolve(new Response(Buffer.concat(body).toString(), {
247
+ status: resp.statusCode ?? 200,
248
+ headers: resp.headers,
249
+ }));
250
+ });
251
+ });
252
+ const body = JSON.stringify({
253
+ opts,
254
+ code,
255
+ });
256
+ req.write(body, (err) => {
257
+ if (err != null) {
258
+ reject(err);
259
+ }
260
+ });
261
+ req.end();
262
+ });
263
+ if (resp.status === 200) {
264
+ const { result, log_lines, err_lines } = (await resp.json());
265
+ const returnOutput = result == null ? null : ({
266
+ type: 'text',
267
+ text: typeof result === 'string' ? result : JSON.stringify(result),
268
+ });
269
+ const logOutput = log_lines.length === 0 ?
270
+ null
271
+ : {
272
+ type: 'text',
273
+ text: log_lines.join('\n'),
274
+ };
275
+ const errOutput = err_lines.length === 0 ?
276
+ null
277
+ : {
278
+ type: 'text',
279
+ text: 'Error output:\n' + err_lines.join('\n'),
280
+ };
281
+ return {
282
+ content: [returnOutput, logOutput, errOutput].filter((block) => block !== null),
283
+ };
284
+ }
285
+ else {
286
+ const { result, log_lines, err_lines } = (await resp.json());
287
+ const messageOutput = result == null ? null : ({
288
+ type: 'text',
289
+ text: typeof result === 'string' ? result : JSON.stringify(result),
290
+ });
291
+ const logOutput = log_lines.length === 0 ?
292
+ null
293
+ : {
294
+ type: 'text',
295
+ text: log_lines.join('\n'),
296
+ };
297
+ const errOutput = err_lines.length === 0 ?
298
+ null
299
+ : {
300
+ type: 'text',
301
+ text: 'Error output:\n' + err_lines.join('\n'),
302
+ };
303
+ return {
304
+ content: [messageOutput, logOutput, errOutput].filter((block) => block !== null),
305
+ isError: true,
306
+ };
307
+ }
308
+ }
309
+ finally {
310
+ worker.terminate();
311
+ }
312
+ };
313
+ //# sourceMappingURL=code-tool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code-tool.js","sourceRoot":"","sources":["src/code-tool.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwDtF,4BA2DC;AAjHD,sDAAyB;AACzB,0DAA6B;AAC7B,wDAA2B;AAC3B,gEAA8D;AAC9D,+DAAmD;AACnD,sCAQiB;AAEjB,oCAA+C;AAM/C,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;uGAkBwF,CAAC;AAExG;;;;;;;;;;;;GAYG;AACH,SAAgB,QAAQ,CAAC,EACvB,cAAc,EACd,iBAAiB,GAIlB;IACC,MAAM,QAAQ,GAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;IAC7E,MAAM,IAAI,GAAS;QACjB,IAAI,EAAE,SAAS;QACf,WAAW,EAAE,MAAM;QACnB,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,IAAI,EAAE;oBACJ,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,kBAAkB;iBAChC;gBACD,MAAM,EAAE;oBACN,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,iEAAiE;iBAC/E;aACF;YACD,QAAQ,EAAE,CAAC,MAAM,CAAC;SACnB;KACF,CAAC;IAEF,MAAM,OAAO,GAAG,KAAK,EAAE,EACrB,UAAU,EACV,IAAI,GAIL,EAA2B,EAAE;QAC5B,MAAM,IAAI,GAAG,IAAI,CAAC,I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CAAiB,CAAC;YAC7E,MAAM,aAAa,GACjB,MAAM,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CACtB;gBACE,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;aACnE,CACF,CAAC;YACJ,MAAM,SAAS,GACb,SAAS,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC;gBACtB,IAAI;gBACN,CAAC,CAAC;oBACE,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC;iBAC3B,CAAC;YACN,MAAM,SAAS,GACb,SAAS,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC;gBACtB,IAAI;gBACN,CAAC,CAAC;oBACE,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,iBAAiB,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC;iBAC/C,CAAC;YACN,OAAO;gBACL,OAAO,EAAE,CAAC,aAAa,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC;gBAChF,OAAO,EAAE,IAAI;aACd,CAAC;QACJ,CAAC;IACH,CAAC;YAAS,CAAC;QACT,MAAM,CAAC,SAAS,EAAE,CAAC;IACrB,CAAC;AACH,CAAC,CAAC"}
package/code-tool.mjs ADDED
@@ -0,0 +1,274 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import url from 'node:url';
5
+ import { newDenoHTTPWorker } from '@valtown/deno-http-worker';
6
+ import { workerPath } from './code-tool-paths.cjs';
7
+ import { asErrorResult, asTextContentResult, } from "./types.mjs";
8
+ import { readEnv, requireValue } from "./util.mjs";
9
+ const prompt = `Runs JavaScript code to interact with the Stigg API.
10
+
11
+ You are a skilled programmer writing code to interface with the service.
12
+ Define an async function named "run" that takes a single parameter of an initialized SDK client and it will be run.
13
+ For example:
14
+
15
+ \`\`\`
16
+ async function run(client) {
17
+ const customerResponse = await client.v1.customers.retrieve('REPLACE_ME');
18
+
19
+ console.log(customerResponse.data);
20
+ }
21
+ \`\`\`
22
+
23
+ You will be returned anything that your function returns, plus the results of any console.log statements.
24
+ Do not add try-catch blocks for single API calls. The tool will handle errors for you.
25
+ Do not add comments unless necessary for generating better code.
26
+ Code will run in a container, and cannot interact with the network outside of the given SDK client.
27
+ Variables will not persist between calls, so make sure to return or log any data you might need later.`;
28
+ /**
29
+ * A tool that runs code against a copy of the SDK.
30
+ *
31
+ * Instead of exposing every endpoint as its own tool, which uses up too many tokens for LLMs to use at once,
32
+ * we expose a single tool that can be used to search for endpoints by name, resource, operation, or tag, and then
33
+ * a generic endpoint that can be used to invoke any endpoint with the provided arguments.
34
+ *
35
+ * @param blockedMethods - The methods to block for code execution. Blocking is done by simple string
36
+ * matching, so it is not secure against obfuscation. For stronger security, block in the downstream API
37
+ * with limited API keys.
38
+ * @param codeExecutionMode - Whether to execute code in a local Deno environment or in a remote
39
+ * sandbox environment hosted by Stainless.
40
+ */
41
+ export function codeTool({ blockedMethods, codeExecutionMode, }) {
42
+ const metadata = { resource: 'all', operation: 'write', tags: [] };
43
+ const tool = {
44
+ name: 'execute',
45
+ description: prompt,
46
+ inputSchema: {
47
+ type: 'object',
48
+ properties: {
49
+ code: {
50
+ type: 'string',
51
+ description: 'Code to execute.',
52
+ },
53
+ intent: {
54
+ type: 'string',
55
+ description: 'Task you are trying to perform. Used for improving the service.',
56
+ },
57
+ },
58
+ required: ['code'],
59
+ },
60
+ };
61
+ const handler = async ({ reqContext, args, }) => {
62
+ const code = args.code;
63
+ // Do very basic blocking of code that includes forbidden method names.
64
+ //
65
+ // WARNING: This is not secure against obfuscation and other evasion methods. If
66
+ // stronger security blocks are required, then these should be enforced in the downstream
67
+ // API (e.g., by having users call the MCP server with API keys with limited permissions).
68
+ if (blockedMethods) {
69
+ const blockedMatches = blockedMethods.filter((method) => code.includes(method.fullyQualifiedName));
70
+ if (blockedMatches.length > 0) {
71
+ return asErrorResult(`The following methods have been blocked by the MCP server and cannot be used in code execution: ${blockedMatches
72
+ .map((m) => m.fullyQualifiedName)
73
+ .join(', ')}`);
74
+ }
75
+ }
76
+ if (codeExecutionMode === 'local') {
77
+ return await localDenoHandler({ reqContext, args });
78
+ }
79
+ else {
80
+ return await remoteStainlessHandler({ reqContext, args });
81
+ }
82
+ };
83
+ return { metadata, tool, handler };
84
+ }
85
+ const remoteStainlessHandler = async ({ reqContext, args, }) => {
86
+ const code = args.code;
87
+ const intent = args.intent;
88
+ const client = reqContext.client;
89
+ const codeModeEndpoint = readEnv('CODE_MODE_ENDPOINT_URL') ?? 'https://api.stainless.com/api/ai/code-tool';
90
+ // Setting a Stainless API key authenticates requests to the code tool endpoint.
91
+ const res = await fetch(codeModeEndpoint, {
92
+ method: 'POST',
93
+ headers: {
94
+ ...(reqContext.stainlessApiKey && { Authorization: reqContext.stainlessApiKey }),
95
+ 'Content-Type': 'application/json',
96
+ client_envs: JSON.stringify({
97
+ STIGG_API_KEY: requireValue(readEnv('STIGG_API_KEY') ?? client.apiKey, 'set STIGG_API_KEY environment variable or provide apiKey client option'),
98
+ STIGG_BASE_URL: readEnv('STIGG_BASE_URL') ?? client.baseURL ?? undefined,
99
+ }),
100
+ },
101
+ body: JSON.stringify({
102
+ project_name: 'stigg',
103
+ code,
104
+ intent,
105
+ client_opts: {},
106
+ }),
107
+ });
108
+ if (!res.ok) {
109
+ throw new Error(`${res.status}: ${res.statusText} error when trying to contact Code Tool server. Details: ${await res.text()}`);
110
+ }
111
+ const { is_error, result, log_lines, err_lines } = (await res.json());
112
+ const hasLogs = log_lines.length > 0 || err_lines.length > 0;
113
+ const output = {
114
+ result,
115
+ ...(log_lines.length > 0 && { log_lines }),
116
+ ...(err_lines.length > 0 && { err_lines }),
117
+ };
118
+ if (is_error) {
119
+ return asErrorResult(typeof result === 'string' && !hasLogs ? result : JSON.stringify(output, null, 2));
120
+ }
121
+ return asTextContentResult(output);
122
+ };
123
+ const localDenoHandler = async ({ reqContext, args, }) => {
124
+ const client = reqContext.client;
125
+ const baseURLHostname = new URL(client.baseURL).hostname;
126
+ const { code } = args;
127
+ let denoPath;
128
+ const packageRoot = path.resolve(path.dirname(workerPath), '..');
129
+ const packageNodeModulesPath = path.resolve(packageRoot, 'node_modules');
130
+ // Check if deno is in PATH
131
+ const { execSync } = await import('node:child_process');
132
+ try {
133
+ execSync('command -v deno', { stdio: 'ignore' });
134
+ denoPath = 'deno';
135
+ }
136
+ catch {
137
+ try {
138
+ // Use deno binary in node_modules if it's found
139
+ const denoNodeModulesPath = path.resolve(packageNodeModulesPath, 'deno', 'bin.cjs');
140
+ await fs.promises.access(denoNodeModulesPath, fs.constants.X_OK);
141
+ denoPath = denoNodeModulesPath;
142
+ }
143
+ catch {
144
+ return asErrorResult('Deno is required for code execution but was not found. ' +
145
+ 'Install it from https://deno.land or run: npm install deno');
146
+ }
147
+ }
148
+ const allowReadPaths = [
149
+ 'code-tool-worker.mjs',
150
+ `${workerPath.replace(/([\/\\]node_modules)[\/\\].+$/, '$1')}/`,
151
+ packageRoot,
152
+ ];
153
+ // Follow symlinks in node_modules to allow read access to workspace-linked packages
154
+ try {
155
+ const sdkPkgName = '@stigg/typescript';
156
+ const sdkDir = path.resolve(packageNodeModulesPath, sdkPkgName);
157
+ const realSdkDir = fs.realpathSync(sdkDir);
158
+ if (realSdkDir !== sdkDir) {
159
+ allowReadPaths.push(realSdkDir);
160
+ }
161
+ }
162
+ catch {
163
+ // Ignore if symlink resolution fails
164
+ }
165
+ const allowRead = allowReadPaths.join(',');
166
+ const worker = await newDenoHTTPWorker(url.pathToFileURL(workerPath), {
167
+ denoExecutable: denoPath,
168
+ runFlags: [
169
+ `--node-modules-dir=manual`,
170
+ `--allow-read=${allowRead}`,
171
+ `--allow-net=${baseURLHostname}`,
172
+ // Allow environment variables because instantiating the client will try to read from them,
173
+ // even though they are not set.
174
+ '--allow-env',
175
+ ],
176
+ printOutput: true,
177
+ spawnOptions: {
178
+ cwd: path.dirname(workerPath),
179
+ },
180
+ });
181
+ try {
182
+ const resp = await new Promise((resolve, reject) => {
183
+ worker.addEventListener('exit', (exitCode) => {
184
+ reject(new Error(`Worker exited with code ${exitCode}`));
185
+ });
186
+ const opts = {
187
+ baseURL: client.baseURL,
188
+ apiKey: client.apiKey,
189
+ defaultHeaders: {
190
+ 'X-Stainless-MCP': 'true',
191
+ },
192
+ };
193
+ const req = worker.request('http://localhost', {
194
+ headers: {
195
+ 'content-type': 'application/json',
196
+ },
197
+ method: 'POST',
198
+ }, (resp) => {
199
+ const body = [];
200
+ resp.on('error', (err) => {
201
+ reject(err);
202
+ });
203
+ resp.on('data', (chunk) => {
204
+ body.push(chunk);
205
+ });
206
+ resp.on('end', () => {
207
+ resolve(new Response(Buffer.concat(body).toString(), {
208
+ status: resp.statusCode ?? 200,
209
+ headers: resp.headers,
210
+ }));
211
+ });
212
+ });
213
+ const body = JSON.stringify({
214
+ opts,
215
+ code,
216
+ });
217
+ req.write(body, (err) => {
218
+ if (err != null) {
219
+ reject(err);
220
+ }
221
+ });
222
+ req.end();
223
+ });
224
+ if (resp.status === 200) {
225
+ const { result, log_lines, err_lines } = (await resp.json());
226
+ const returnOutput = result == null ? null : ({
227
+ type: 'text',
228
+ text: typeof result === 'string' ? result : JSON.stringify(result),
229
+ });
230
+ const logOutput = log_lines.length === 0 ?
231
+ null
232
+ : {
233
+ type: 'text',
234
+ text: log_lines.join('\n'),
235
+ };
236
+ const errOutput = err_lines.length === 0 ?
237
+ null
238
+ : {
239
+ type: 'text',
240
+ text: 'Error output:\n' + err_lines.join('\n'),
241
+ };
242
+ return {
243
+ content: [returnOutput, logOutput, errOutput].filter((block) => block !== null),
244
+ };
245
+ }
246
+ else {
247
+ const { result, log_lines, err_lines } = (await resp.json());
248
+ const messageOutput = result == null ? null : ({
249
+ type: 'text',
250
+ text: typeof result === 'string' ? result : JSON.stringify(result),
251
+ });
252
+ const logOutput = log_lines.length === 0 ?
253
+ null
254
+ : {
255
+ type: 'text',
256
+ text: log_lines.join('\n'),
257
+ };
258
+ const errOutput = err_lines.length === 0 ?
259
+ null
260
+ : {
261
+ type: 'text',
262
+ text: 'Error output:\n' + err_lines.join('\n'),
263
+ };
264
+ return {
265
+ content: [messageOutput, logOutput, errOutput].filter((block) => block !== null),
266
+ isError: true,
267
+ };
268
+ }
269
+ }
270
+ finally {
271
+ worker.terminate();
272
+ }
273
+ };
274
+ //# sourceMappingURL=code-tool.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code-tool.mjs","sourceRoot":"","sources":["src/code-tool.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAE/E,EAAE,MAAM,SAAS;OACjB,IAAI,MAAM,WAAW;OACrB,GAAG,MAAM,UAAU;OACnB,EAAE,iBAAiB,EAAE,MAAM,2BAA2B;OACtD,EAAE,UAAU,EAAE,MAAM,uBAAuB;OAC3C,EAML,aAAa,EACb,mBAAmB,GACpB;OAEM,EAAE,OAAO,EAAE,YAAY,EAAE;AAMhC,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;uGAkBwF,CAAC;AAExG;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,QAAQ,CAAC,EACvB,cAAc,EACd,iBAAiB,GAIlB;IACC,MAAM,QAAQ,GAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;IAC7E,MAAM,IAAI,GAAS;QACjB,IAAI,EAAE,SAAS;QACf,WAAW,EAAE,MAAM;QACnB,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,IAAI,EAAE;oBACJ,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,kBAAkB;iBAChC;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C,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC;aAChF,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,CAAC,MAAM,IAAI,CAAC,IAAI,EAAE,CAAiB,CAAC;YAC7E,MAAM,aAAa,GACjB,MAAM,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CACtB;gBACE,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;aACnE,CACF,CAAC;YACJ,MAAM,SAAS,GACb,SAAS,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC;gBACtB,IAAI;gBACN,CAAC,CAAC;oBACE,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC;iBAC3B,CAAC;YACN,MAAM,SAAS,GACb,SAAS,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC;gBACtB,IAAI;gBACN,CAAC,CAAC;oBACE,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,iBAAiB,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC;iBAC/C,CAAC;YACN,OAAO;gBACL,OAAO,EAAE,CAAC,aAAa,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC;gBAChF,OAAO,EAAE,IAAI;aACd,CAAC;QACJ,CAAC;IACH,CAAC;YAAS,CAAC;QACT,MAAM,CAAC,SAAS,EAAE,CAAC;IACrB,CAAC;AACH,CAAC,CAAC"}
@@ -0,0 +1,57 @@
1
+ import { Metadata, McpRequestContext } from "./types.mjs";
2
+ import { Tool } from '@modelcontextprotocol/sdk/types.js';
3
+ export declare const metadata: Metadata;
4
+ export declare const tool: Tool;
5
+ export declare const handler: ({ reqContext, args, }: {
6
+ reqContext: McpRequestContext;
7
+ args: Record<string, unknown> | undefined;
8
+ }) => Promise<import("./types").ToolCallResult>;
9
+ declare const _default: {
10
+ metadata: Metadata;
11
+ tool: {
12
+ inputSchema: {
13
+ [x: string]: unknown;
14
+ type: "object";
15
+ properties?: {
16
+ [x: string]: object;
17
+ } | undefined;
18
+ required?: string[] | undefined;
19
+ };
20
+ name: string;
21
+ description?: string | undefined;
22
+ outputSchema?: {
23
+ [x: string]: unknown;
24
+ type: "object";
25
+ properties?: {
26
+ [x: string]: object;
27
+ } | undefined;
28
+ required?: string[] | undefined;
29
+ } | undefined;
30
+ annotations?: {
31
+ title?: string | undefined;
32
+ readOnlyHint?: boolean | undefined;
33
+ destructiveHint?: boolean | undefined;
34
+ idempotentHint?: boolean | undefined;
35
+ openWorldHint?: boolean | undefined;
36
+ } | undefined;
37
+ execution?: {
38
+ taskSupport?: "optional" | "required" | "forbidden" | undefined;
39
+ } | undefined;
40
+ _meta?: {
41
+ [x: string]: unknown;
42
+ } | undefined;
43
+ icons?: {
44
+ src: string;
45
+ mimeType?: string | undefined;
46
+ sizes?: string[] | undefined;
47
+ theme?: "light" | "dark" | undefined;
48
+ }[] | undefined;
49
+ title?: string | undefined;
50
+ };
51
+ handler: ({ reqContext, args, }: {
52
+ reqContext: McpRequestContext;
53
+ args: Record<string, unknown> | undefined;
54
+ }) => Promise<import("./types").ToolCallResult>;
55
+ };
56
+ export default _default;
57
+ //# sourceMappingURL=docs-search-tool.d.mts.map