@revoxai/sdk-mcp 0.1.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.
- package/LICENSE +201 -0
- package/README.md +101 -0
- package/auth.d.mts +6 -0
- package/auth.d.mts.map +1 -0
- package/auth.d.ts +6 -0
- package/auth.d.ts.map +1 -0
- package/auth.js +37 -0
- package/auth.js.map +1 -0
- package/auth.mjs +32 -0
- package/auth.mjs.map +1 -0
- package/code-tool-paths.cjs +6 -0
- package/code-tool-paths.cjs.map +1 -0
- package/code-tool-paths.d.cts +2 -0
- package/code-tool-paths.d.cts.map +1 -0
- package/code-tool-types.d.mts +14 -0
- package/code-tool-types.d.mts.map +1 -0
- package/code-tool-types.d.ts +14 -0
- package/code-tool-types.d.ts.map +1 -0
- package/code-tool-types.js +4 -0
- package/code-tool-types.js.map +1 -0
- package/code-tool-types.mjs +3 -0
- package/code-tool-types.mjs.map +1 -0
- package/code-tool-worker.d.mts +5 -0
- package/code-tool-worker.d.mts.map +1 -0
- package/code-tool-worker.d.ts +5 -0
- package/code-tool-worker.d.ts.map +1 -0
- package/code-tool-worker.js +237 -0
- package/code-tool-worker.js.map +1 -0
- package/code-tool-worker.mjs +232 -0
- package/code-tool-worker.mjs.map +1 -0
- package/code-tool.d.mts +21 -0
- package/code-tool.d.mts.map +1 -0
- package/code-tool.d.ts +21 -0
- package/code-tool.d.ts.map +1 -0
- package/code-tool.js +331 -0
- package/code-tool.js.map +1 -0
- package/code-tool.mjs +292 -0
- package/code-tool.mjs.map +1 -0
- package/docs-search-tool.d.mts +57 -0
- package/docs-search-tool.d.mts.map +1 -0
- package/docs-search-tool.d.ts +57 -0
- package/docs-search-tool.d.ts.map +1 -0
- package/docs-search-tool.js +74 -0
- package/docs-search-tool.js.map +1 -0
- package/docs-search-tool.mjs +70 -0
- package/docs-search-tool.mjs.map +1 -0
- package/http.d.mts +12 -0
- package/http.d.mts.map +1 -0
- package/http.d.ts +12 -0
- package/http.d.ts.map +1 -0
- package/http.js +128 -0
- package/http.js.map +1 -0
- package/http.mjs +120 -0
- package/http.mjs.map +1 -0
- package/index.d.mts +3 -0
- package/index.d.mts.map +1 -0
- package/index.d.ts +3 -0
- package/index.d.ts.map +1 -0
- package/index.js +60 -0
- package/index.js.map +1 -0
- package/index.mjs +58 -0
- package/index.mjs.map +1 -0
- package/instructions.d.mts +2 -0
- package/instructions.d.mts.map +1 -0
- package/instructions.d.ts +2 -0
- package/instructions.d.ts.map +1 -0
- package/instructions.js +46 -0
- package/instructions.js.map +1 -0
- package/instructions.mjs +43 -0
- package/instructions.mjs.map +1 -0
- package/logger.d.mts +7 -0
- package/logger.d.mts.map +1 -0
- package/logger.d.ts +7 -0
- package/logger.d.ts.map +1 -0
- package/logger.js +29 -0
- package/logger.js.map +1 -0
- package/logger.mjs +22 -0
- package/logger.mjs.map +1 -0
- package/methods.d.mts +10 -0
- package/methods.d.mts.map +1 -0
- package/methods.d.ts +10 -0
- package/methods.d.ts.map +1 -0
- package/methods.js +143 -0
- package/methods.js.map +1 -0
- package/methods.mjs +139 -0
- package/methods.mjs.map +1 -0
- package/options.d.mts +20 -0
- package/options.d.mts.map +1 -0
- package/options.d.ts +20 -0
- package/options.d.ts.map +1 -0
- package/options.js +122 -0
- package/options.js.map +1 -0
- package/options.mjs +115 -0
- package/options.mjs.map +1 -0
- package/package.json +224 -0
- package/server.d.mts +29 -0
- package/server.d.mts.map +1 -0
- package/server.d.ts +29 -0
- package/server.d.ts.map +1 -0
- package/server.js +158 -0
- package/server.js.map +1 -0
- package/server.mjs +148 -0
- package/server.mjs.map +1 -0
- package/src/auth.ts +42 -0
- package/src/code-tool-paths.cts +3 -0
- package/src/code-tool-types.ts +17 -0
- package/src/code-tool-worker.ts +283 -0
- package/src/code-tool.ts +383 -0
- package/src/docs-search-tool.ts +100 -0
- package/src/http.ts +159 -0
- package/src/index.ts +67 -0
- package/src/instructions.ts +65 -0
- package/src/logger.ts +28 -0
- package/src/methods.ts +164 -0
- package/src/options.ts +161 -0
- package/src/server.ts +188 -0
- package/src/stdio.ts +14 -0
- package/src/tsconfig.json +11 -0
- package/src/types.ts +123 -0
- package/src/util.ts +25 -0
- package/stdio.d.mts +3 -0
- package/stdio.d.mts.map +1 -0
- package/stdio.d.ts +3 -0
- package/stdio.d.ts.map +1 -0
- package/stdio.js +15 -0
- package/stdio.js.map +1 -0
- package/stdio.mjs +11 -0
- package/stdio.mjs.map +1 -0
- package/types.d.mts +59 -0
- package/types.d.mts.map +1 -0
- package/types.d.ts +59 -0
- package/types.d.ts.map +1 -0
- package/types.js +58 -0
- package/types.js.map +1 -0
- package/types.mjs +53 -0
- package/types.mjs.map +1 -0
- package/util.d.mts +4 -0
- package/util.d.mts.map +1 -0
- package/util.d.ts +4 -0
- package/util.d.ts.map +1 -0
- package/util.js +30 -0
- package/util.js.map +1 -0
- package/util.mjs +24 -0
- package/util.mjs.map +1 -0
package/code-tool.js
ADDED
|
@@ -0,0 +1,331 @@
|
|
|
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 logger_1 = require("./logger.js");
|
|
49
|
+
const prompt = `Runs JavaScript code to interact with the Revox API.
|
|
50
|
+
|
|
51
|
+
You are a skilled TypeScript programmer writing code to interface with the service.
|
|
52
|
+
Define an async function named "run" that takes a single parameter of an initialized SDK client and it will be run.
|
|
53
|
+
For example:
|
|
54
|
+
|
|
55
|
+
\`\`\`
|
|
56
|
+
async function run(client) {
|
|
57
|
+
const assistant = await client.assistants.create({ name: 'REPLACE_ME', prompt: 'REPLACE_ME' });
|
|
58
|
+
|
|
59
|
+
console.log(assistant.assistant);
|
|
60
|
+
}
|
|
61
|
+
\`\`\`
|
|
62
|
+
|
|
63
|
+
You will be returned anything that your function returns, plus the results of any console.log statements.
|
|
64
|
+
Do not add try-catch blocks for single API calls. The tool will handle errors for you.
|
|
65
|
+
Do not add comments unless necessary for generating better code.
|
|
66
|
+
Code will run in a container, and cannot interact with the network outside of the given SDK client.
|
|
67
|
+
Variables will not persist between calls, so make sure to return or log any data you might need later.
|
|
68
|
+
Remember that you are writing TypeScript code, so you need to be careful with your types.
|
|
69
|
+
Always type dynamic key-value stores explicitly as Record<string, YourValueType> instead of {}.`;
|
|
70
|
+
/**
|
|
71
|
+
* A tool that runs code against a copy of the SDK.
|
|
72
|
+
*
|
|
73
|
+
* Instead of exposing every endpoint as its own tool, which uses up too many tokens for LLMs to use at once,
|
|
74
|
+
* we expose a single tool that can be used to search for endpoints by name, resource, operation, or tag, and then
|
|
75
|
+
* a generic endpoint that can be used to invoke any endpoint with the provided arguments.
|
|
76
|
+
*
|
|
77
|
+
* @param blockedMethods - The methods to block for code execution. Blocking is done by simple string
|
|
78
|
+
* matching, so it is not secure against obfuscation. For stronger security, block in the downstream API
|
|
79
|
+
* with limited API keys.
|
|
80
|
+
* @param codeExecutionMode - Whether to execute code in a local Deno environment or in a remote
|
|
81
|
+
* sandbox environment hosted by Stainless.
|
|
82
|
+
*/
|
|
83
|
+
function codeTool({ blockedMethods, codeExecutionMode, }) {
|
|
84
|
+
const metadata = { resource: 'all', operation: 'write', tags: [] };
|
|
85
|
+
const tool = {
|
|
86
|
+
name: 'execute',
|
|
87
|
+
description: prompt,
|
|
88
|
+
inputSchema: {
|
|
89
|
+
type: 'object',
|
|
90
|
+
properties: {
|
|
91
|
+
code: {
|
|
92
|
+
type: 'string',
|
|
93
|
+
description: 'Code to execute.',
|
|
94
|
+
},
|
|
95
|
+
intent: {
|
|
96
|
+
type: 'string',
|
|
97
|
+
description: 'Task you are trying to perform. Used for improving the service.',
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
required: ['code'],
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
const logger = (0, logger_1.getLogger)();
|
|
104
|
+
const handler = async ({ reqContext, args, }) => {
|
|
105
|
+
const code = args.code;
|
|
106
|
+
// Do very basic blocking of code that includes forbidden method names.
|
|
107
|
+
//
|
|
108
|
+
// WARNING: This is not secure against obfuscation and other evasion methods. If
|
|
109
|
+
// stronger security blocks are required, then these should be enforced in the downstream
|
|
110
|
+
// API (e.g., by having users call the MCP server with API keys with limited permissions).
|
|
111
|
+
if (blockedMethods) {
|
|
112
|
+
const blockedMatches = blockedMethods.filter((method) => code.includes(method.fullyQualifiedName));
|
|
113
|
+
if (blockedMatches.length > 0) {
|
|
114
|
+
return (0, types_1.asErrorResult)(`The following methods have been blocked by the MCP server and cannot be used in code execution: ${blockedMatches
|
|
115
|
+
.map((m) => m.fullyQualifiedName)
|
|
116
|
+
.join(', ')}`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
let result;
|
|
120
|
+
const startTime = Date.now();
|
|
121
|
+
if (codeExecutionMode === 'local') {
|
|
122
|
+
logger.debug('Executing code in local Deno environment');
|
|
123
|
+
result = await localDenoHandler({ reqContext, args });
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
logger.debug('Executing code in remote Stainless environment');
|
|
127
|
+
result = await remoteStainlessHandler({ reqContext, args });
|
|
128
|
+
}
|
|
129
|
+
logger.info({
|
|
130
|
+
codeExecutionMode,
|
|
131
|
+
durationMs: Date.now() - startTime,
|
|
132
|
+
isError: result.isError,
|
|
133
|
+
contentRows: result.content?.length ?? 0,
|
|
134
|
+
}, 'Got code tool execution result');
|
|
135
|
+
return result;
|
|
136
|
+
};
|
|
137
|
+
return { metadata, tool, handler };
|
|
138
|
+
}
|
|
139
|
+
const remoteStainlessHandler = async ({ reqContext, args, }) => {
|
|
140
|
+
const code = args.code;
|
|
141
|
+
const intent = args.intent;
|
|
142
|
+
const client = reqContext.client;
|
|
143
|
+
const codeModeEndpoint = (0, util_1.readEnv)('CODE_MODE_ENDPOINT_URL') ?? 'https://api.stainless.com/api/ai/code-tool';
|
|
144
|
+
// Setting a Stainless API key authenticates requests to the code tool endpoint.
|
|
145
|
+
const res = await fetch(codeModeEndpoint, {
|
|
146
|
+
method: 'POST',
|
|
147
|
+
headers: {
|
|
148
|
+
...(reqContext.stainlessApiKey && { Authorization: reqContext.stainlessApiKey }),
|
|
149
|
+
'Content-Type': 'application/json',
|
|
150
|
+
'x-stainless-mcp-client-envs': JSON.stringify({
|
|
151
|
+
REVOX_API_KEY: (0, util_1.requireValue)((0, util_1.readEnv)('REVOX_API_KEY') ?? client.apiKey, 'set REVOX_API_KEY environment variable or provide apiKey client option'),
|
|
152
|
+
REVOX_BASE_URL: (0, util_1.readEnv)('REVOX_BASE_URL') ?? client.baseURL ?? undefined,
|
|
153
|
+
}),
|
|
154
|
+
},
|
|
155
|
+
body: JSON.stringify({
|
|
156
|
+
project_name: 'revox',
|
|
157
|
+
code,
|
|
158
|
+
intent,
|
|
159
|
+
client_opts: {},
|
|
160
|
+
}),
|
|
161
|
+
});
|
|
162
|
+
if (!res.ok) {
|
|
163
|
+
if (res.status === 404 && !reqContext.stainlessApiKey) {
|
|
164
|
+
throw new Error('Could not access code tool for this project. You may need to provide a Stainless API key via the STAINLESS_API_KEY environment variable, the --stainless-api-key flag, or the x-stainless-api-key HTTP header.');
|
|
165
|
+
}
|
|
166
|
+
throw new Error(`${res.status}: ${res.statusText} error when trying to contact Code Tool server. Details: ${await res.text()}`);
|
|
167
|
+
}
|
|
168
|
+
const { is_error, result, log_lines, err_lines } = (await res.json());
|
|
169
|
+
const hasLogs = log_lines.length > 0 || err_lines.length > 0;
|
|
170
|
+
const output = {
|
|
171
|
+
result,
|
|
172
|
+
...(log_lines.length > 0 && { log_lines }),
|
|
173
|
+
...(err_lines.length > 0 && { err_lines }),
|
|
174
|
+
};
|
|
175
|
+
if (is_error) {
|
|
176
|
+
return (0, types_1.asErrorResult)(typeof result === 'string' && !hasLogs ? result : JSON.stringify(output, null, 2));
|
|
177
|
+
}
|
|
178
|
+
return (0, types_1.asTextContentResult)(output);
|
|
179
|
+
};
|
|
180
|
+
const localDenoHandler = async ({ reqContext, args, }) => {
|
|
181
|
+
const client = reqContext.client;
|
|
182
|
+
const baseURLHostname = new URL(client.baseURL).hostname;
|
|
183
|
+
const { code } = args;
|
|
184
|
+
let denoPath;
|
|
185
|
+
const packageRoot = node_path_1.default.resolve(node_path_1.default.dirname(code_tool_paths_cjs_1.workerPath), '..');
|
|
186
|
+
const packageNodeModulesPath = node_path_1.default.resolve(packageRoot, 'node_modules');
|
|
187
|
+
// Check if deno is in PATH
|
|
188
|
+
const { execSync } = await Promise.resolve().then(() => __importStar(require('node:child_process')));
|
|
189
|
+
try {
|
|
190
|
+
execSync('command -v deno', { stdio: 'ignore' });
|
|
191
|
+
denoPath = 'deno';
|
|
192
|
+
}
|
|
193
|
+
catch {
|
|
194
|
+
try {
|
|
195
|
+
// Use deno binary in node_modules if it's found
|
|
196
|
+
const denoNodeModulesPath = node_path_1.default.resolve(packageNodeModulesPath, 'deno', 'bin.cjs');
|
|
197
|
+
await node_fs_1.default.promises.access(denoNodeModulesPath, node_fs_1.default.constants.X_OK);
|
|
198
|
+
denoPath = denoNodeModulesPath;
|
|
199
|
+
}
|
|
200
|
+
catch {
|
|
201
|
+
return (0, types_1.asErrorResult)('Deno is required for code execution but was not found. ' +
|
|
202
|
+
'Install it from https://deno.land or run: npm install deno');
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
const allowReadPaths = [
|
|
206
|
+
'code-tool-worker.mjs',
|
|
207
|
+
`${code_tool_paths_cjs_1.workerPath.replace(/([\/\\]node_modules)[\/\\].+$/, '$1')}/`,
|
|
208
|
+
packageRoot,
|
|
209
|
+
];
|
|
210
|
+
// Follow symlinks in node_modules to allow read access to workspace-linked packages
|
|
211
|
+
try {
|
|
212
|
+
const sdkPkgName = '@revoxai/sdk';
|
|
213
|
+
const sdkDir = node_path_1.default.resolve(packageNodeModulesPath, sdkPkgName);
|
|
214
|
+
const realSdkDir = node_fs_1.default.realpathSync(sdkDir);
|
|
215
|
+
if (realSdkDir !== sdkDir) {
|
|
216
|
+
allowReadPaths.push(realSdkDir);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
catch {
|
|
220
|
+
// Ignore if symlink resolution fails
|
|
221
|
+
}
|
|
222
|
+
const allowRead = allowReadPaths.join(',');
|
|
223
|
+
const worker = await (0, deno_http_worker_1.newDenoHTTPWorker)(node_url_1.default.pathToFileURL(code_tool_paths_cjs_1.workerPath), {
|
|
224
|
+
denoExecutable: denoPath,
|
|
225
|
+
runFlags: [
|
|
226
|
+
`--node-modules-dir=manual`,
|
|
227
|
+
`--allow-read=${allowRead}`,
|
|
228
|
+
`--allow-net=${baseURLHostname}`,
|
|
229
|
+
// Allow environment variables because instantiating the client will try to read from them,
|
|
230
|
+
// even though they are not set.
|
|
231
|
+
'--allow-env',
|
|
232
|
+
],
|
|
233
|
+
printOutput: true,
|
|
234
|
+
spawnOptions: {
|
|
235
|
+
cwd: node_path_1.default.dirname(code_tool_paths_cjs_1.workerPath),
|
|
236
|
+
},
|
|
237
|
+
});
|
|
238
|
+
try {
|
|
239
|
+
const resp = await new Promise((resolve, reject) => {
|
|
240
|
+
worker.addEventListener('exit', (exitCode) => {
|
|
241
|
+
reject(new Error(`Worker exited with code ${exitCode}`));
|
|
242
|
+
});
|
|
243
|
+
const opts = {
|
|
244
|
+
baseURL: client.baseURL,
|
|
245
|
+
apiKey: client.apiKey,
|
|
246
|
+
defaultHeaders: {
|
|
247
|
+
'X-Stainless-MCP': 'true',
|
|
248
|
+
},
|
|
249
|
+
};
|
|
250
|
+
const req = worker.request('http://localhost', {
|
|
251
|
+
headers: {
|
|
252
|
+
'content-type': 'application/json',
|
|
253
|
+
},
|
|
254
|
+
method: 'POST',
|
|
255
|
+
}, (resp) => {
|
|
256
|
+
const body = [];
|
|
257
|
+
resp.on('error', (err) => {
|
|
258
|
+
reject(err);
|
|
259
|
+
});
|
|
260
|
+
resp.on('data', (chunk) => {
|
|
261
|
+
body.push(chunk);
|
|
262
|
+
});
|
|
263
|
+
resp.on('end', () => {
|
|
264
|
+
resolve(new Response(Buffer.concat(body).toString(), {
|
|
265
|
+
status: resp.statusCode ?? 200,
|
|
266
|
+
headers: resp.headers,
|
|
267
|
+
}));
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
const body = JSON.stringify({
|
|
271
|
+
opts,
|
|
272
|
+
code,
|
|
273
|
+
});
|
|
274
|
+
req.write(body, (err) => {
|
|
275
|
+
if (err != null) {
|
|
276
|
+
reject(err);
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
req.end();
|
|
280
|
+
});
|
|
281
|
+
if (resp.status === 200) {
|
|
282
|
+
const { result, log_lines, err_lines } = (await resp.json());
|
|
283
|
+
const returnOutput = result == null ? null : ({
|
|
284
|
+
type: 'text',
|
|
285
|
+
text: typeof result === 'string' ? result : JSON.stringify(result),
|
|
286
|
+
});
|
|
287
|
+
const logOutput = log_lines.length === 0 ?
|
|
288
|
+
null
|
|
289
|
+
: {
|
|
290
|
+
type: 'text',
|
|
291
|
+
text: log_lines.join('\n'),
|
|
292
|
+
};
|
|
293
|
+
const errOutput = err_lines.length === 0 ?
|
|
294
|
+
null
|
|
295
|
+
: {
|
|
296
|
+
type: 'text',
|
|
297
|
+
text: 'Error output:\n' + err_lines.join('\n'),
|
|
298
|
+
};
|
|
299
|
+
return {
|
|
300
|
+
content: [returnOutput, logOutput, errOutput].filter((block) => block !== null),
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
const { result, log_lines, err_lines } = (await resp.json());
|
|
305
|
+
const messageOutput = result == null ? null : ({
|
|
306
|
+
type: 'text',
|
|
307
|
+
text: typeof result === 'string' ? result : JSON.stringify(result),
|
|
308
|
+
});
|
|
309
|
+
const logOutput = log_lines.length === 0 ?
|
|
310
|
+
null
|
|
311
|
+
: {
|
|
312
|
+
type: 'text',
|
|
313
|
+
text: log_lines.join('\n'),
|
|
314
|
+
};
|
|
315
|
+
const errOutput = err_lines.length === 0 ?
|
|
316
|
+
null
|
|
317
|
+
: {
|
|
318
|
+
type: 'text',
|
|
319
|
+
text: 'Error output:\n' + err_lines.join('\n'),
|
|
320
|
+
};
|
|
321
|
+
return {
|
|
322
|
+
content: [messageOutput, logOutput, errOutput].filter((block) => block !== null),
|
|
323
|
+
isError: true,
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
finally {
|
|
328
|
+
worker.terminate();
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
//# sourceMappingURL=code-tool.js.map
|
package/code-tool.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-tool.js","sourceRoot":"","sources":["src/code-tool.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2DtF,4BA6EC;AAtID,sDAAyB;AACzB,0DAA6B;AAC7B,wDAA2B;AAC3B,gEAA8D;AAC9D,+DAAmD;AACnD,sCAQiB;AAEjB,oCAA+C;AAE/C,wCAAqC;AAKrC,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;gGAoBiF,CAAC;AAEjG;;;;;;;;;;;;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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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,292 @@
|
|
|
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
|
+
import { getLogger } from "./logger.mjs";
|
|
10
|
+
const prompt = `Runs JavaScript code to interact with the Revox API.
|
|
11
|
+
|
|
12
|
+
You are a skilled TypeScript programmer writing code to interface with the service.
|
|
13
|
+
Define an async function named "run" that takes a single parameter of an initialized SDK client and it will be run.
|
|
14
|
+
For example:
|
|
15
|
+
|
|
16
|
+
\`\`\`
|
|
17
|
+
async function run(client) {
|
|
18
|
+
const assistant = await client.assistants.create({ name: 'REPLACE_ME', prompt: 'REPLACE_ME' });
|
|
19
|
+
|
|
20
|
+
console.log(assistant.assistant);
|
|
21
|
+
}
|
|
22
|
+
\`\`\`
|
|
23
|
+
|
|
24
|
+
You will be returned anything that your function returns, plus the results of any console.log statements.
|
|
25
|
+
Do not add try-catch blocks for single API calls. The tool will handle errors for you.
|
|
26
|
+
Do not add comments unless necessary for generating better code.
|
|
27
|
+
Code will run in a container, and cannot interact with the network outside of the given SDK client.
|
|
28
|
+
Variables will not persist between calls, so make sure to return or log any data you might need later.
|
|
29
|
+
Remember that you are writing TypeScript code, so you need to be careful with your types.
|
|
30
|
+
Always type dynamic key-value stores explicitly as Record<string, YourValueType> instead of {}.`;
|
|
31
|
+
/**
|
|
32
|
+
* A tool that runs code against a copy of the SDK.
|
|
33
|
+
*
|
|
34
|
+
* Instead of exposing every endpoint as its own tool, which uses up too many tokens for LLMs to use at once,
|
|
35
|
+
* we expose a single tool that can be used to search for endpoints by name, resource, operation, or tag, and then
|
|
36
|
+
* a generic endpoint that can be used to invoke any endpoint with the provided arguments.
|
|
37
|
+
*
|
|
38
|
+
* @param blockedMethods - The methods to block for code execution. Blocking is done by simple string
|
|
39
|
+
* matching, so it is not secure against obfuscation. For stronger security, block in the downstream API
|
|
40
|
+
* with limited API keys.
|
|
41
|
+
* @param codeExecutionMode - Whether to execute code in a local Deno environment or in a remote
|
|
42
|
+
* sandbox environment hosted by Stainless.
|
|
43
|
+
*/
|
|
44
|
+
export function codeTool({ blockedMethods, codeExecutionMode, }) {
|
|
45
|
+
const metadata = { resource: 'all', operation: 'write', tags: [] };
|
|
46
|
+
const tool = {
|
|
47
|
+
name: 'execute',
|
|
48
|
+
description: prompt,
|
|
49
|
+
inputSchema: {
|
|
50
|
+
type: 'object',
|
|
51
|
+
properties: {
|
|
52
|
+
code: {
|
|
53
|
+
type: 'string',
|
|
54
|
+
description: 'Code to execute.',
|
|
55
|
+
},
|
|
56
|
+
intent: {
|
|
57
|
+
type: 'string',
|
|
58
|
+
description: 'Task you are trying to perform. Used for improving the service.',
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
required: ['code'],
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
const logger = getLogger();
|
|
65
|
+
const handler = async ({ reqContext, args, }) => {
|
|
66
|
+
const code = args.code;
|
|
67
|
+
// Do very basic blocking of code that includes forbidden method names.
|
|
68
|
+
//
|
|
69
|
+
// WARNING: This is not secure against obfuscation and other evasion methods. If
|
|
70
|
+
// stronger security blocks are required, then these should be enforced in the downstream
|
|
71
|
+
// API (e.g., by having users call the MCP server with API keys with limited permissions).
|
|
72
|
+
if (blockedMethods) {
|
|
73
|
+
const blockedMatches = blockedMethods.filter((method) => code.includes(method.fullyQualifiedName));
|
|
74
|
+
if (blockedMatches.length > 0) {
|
|
75
|
+
return asErrorResult(`The following methods have been blocked by the MCP server and cannot be used in code execution: ${blockedMatches
|
|
76
|
+
.map((m) => m.fullyQualifiedName)
|
|
77
|
+
.join(', ')}`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
let result;
|
|
81
|
+
const startTime = Date.now();
|
|
82
|
+
if (codeExecutionMode === 'local') {
|
|
83
|
+
logger.debug('Executing code in local Deno environment');
|
|
84
|
+
result = await localDenoHandler({ reqContext, args });
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
logger.debug('Executing code in remote Stainless environment');
|
|
88
|
+
result = await remoteStainlessHandler({ reqContext, args });
|
|
89
|
+
}
|
|
90
|
+
logger.info({
|
|
91
|
+
codeExecutionMode,
|
|
92
|
+
durationMs: Date.now() - startTime,
|
|
93
|
+
isError: result.isError,
|
|
94
|
+
contentRows: result.content?.length ?? 0,
|
|
95
|
+
}, 'Got code tool execution result');
|
|
96
|
+
return result;
|
|
97
|
+
};
|
|
98
|
+
return { metadata, tool, handler };
|
|
99
|
+
}
|
|
100
|
+
const remoteStainlessHandler = async ({ reqContext, args, }) => {
|
|
101
|
+
const code = args.code;
|
|
102
|
+
const intent = args.intent;
|
|
103
|
+
const client = reqContext.client;
|
|
104
|
+
const codeModeEndpoint = readEnv('CODE_MODE_ENDPOINT_URL') ?? 'https://api.stainless.com/api/ai/code-tool';
|
|
105
|
+
// Setting a Stainless API key authenticates requests to the code tool endpoint.
|
|
106
|
+
const res = await fetch(codeModeEndpoint, {
|
|
107
|
+
method: 'POST',
|
|
108
|
+
headers: {
|
|
109
|
+
...(reqContext.stainlessApiKey && { Authorization: reqContext.stainlessApiKey }),
|
|
110
|
+
'Content-Type': 'application/json',
|
|
111
|
+
'x-stainless-mcp-client-envs': JSON.stringify({
|
|
112
|
+
REVOX_API_KEY: requireValue(readEnv('REVOX_API_KEY') ?? client.apiKey, 'set REVOX_API_KEY environment variable or provide apiKey client option'),
|
|
113
|
+
REVOX_BASE_URL: readEnv('REVOX_BASE_URL') ?? client.baseURL ?? undefined,
|
|
114
|
+
}),
|
|
115
|
+
},
|
|
116
|
+
body: JSON.stringify({
|
|
117
|
+
project_name: 'revox',
|
|
118
|
+
code,
|
|
119
|
+
intent,
|
|
120
|
+
client_opts: {},
|
|
121
|
+
}),
|
|
122
|
+
});
|
|
123
|
+
if (!res.ok) {
|
|
124
|
+
if (res.status === 404 && !reqContext.stainlessApiKey) {
|
|
125
|
+
throw new Error('Could not access code tool for this project. You may need to provide a Stainless API key via the STAINLESS_API_KEY environment variable, the --stainless-api-key flag, or the x-stainless-api-key HTTP header.');
|
|
126
|
+
}
|
|
127
|
+
throw new Error(`${res.status}: ${res.statusText} error when trying to contact Code Tool server. Details: ${await res.text()}`);
|
|
128
|
+
}
|
|
129
|
+
const { is_error, result, log_lines, err_lines } = (await res.json());
|
|
130
|
+
const hasLogs = log_lines.length > 0 || err_lines.length > 0;
|
|
131
|
+
const output = {
|
|
132
|
+
result,
|
|
133
|
+
...(log_lines.length > 0 && { log_lines }),
|
|
134
|
+
...(err_lines.length > 0 && { err_lines }),
|
|
135
|
+
};
|
|
136
|
+
if (is_error) {
|
|
137
|
+
return asErrorResult(typeof result === 'string' && !hasLogs ? result : JSON.stringify(output, null, 2));
|
|
138
|
+
}
|
|
139
|
+
return asTextContentResult(output);
|
|
140
|
+
};
|
|
141
|
+
const localDenoHandler = async ({ reqContext, args, }) => {
|
|
142
|
+
const client = reqContext.client;
|
|
143
|
+
const baseURLHostname = new URL(client.baseURL).hostname;
|
|
144
|
+
const { code } = args;
|
|
145
|
+
let denoPath;
|
|
146
|
+
const packageRoot = path.resolve(path.dirname(workerPath), '..');
|
|
147
|
+
const packageNodeModulesPath = path.resolve(packageRoot, 'node_modules');
|
|
148
|
+
// Check if deno is in PATH
|
|
149
|
+
const { execSync } = await import('node:child_process');
|
|
150
|
+
try {
|
|
151
|
+
execSync('command -v deno', { stdio: 'ignore' });
|
|
152
|
+
denoPath = 'deno';
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
try {
|
|
156
|
+
// Use deno binary in node_modules if it's found
|
|
157
|
+
const denoNodeModulesPath = path.resolve(packageNodeModulesPath, 'deno', 'bin.cjs');
|
|
158
|
+
await fs.promises.access(denoNodeModulesPath, fs.constants.X_OK);
|
|
159
|
+
denoPath = denoNodeModulesPath;
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
return asErrorResult('Deno is required for code execution but was not found. ' +
|
|
163
|
+
'Install it from https://deno.land or run: npm install deno');
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
const allowReadPaths = [
|
|
167
|
+
'code-tool-worker.mjs',
|
|
168
|
+
`${workerPath.replace(/([\/\\]node_modules)[\/\\].+$/, '$1')}/`,
|
|
169
|
+
packageRoot,
|
|
170
|
+
];
|
|
171
|
+
// Follow symlinks in node_modules to allow read access to workspace-linked packages
|
|
172
|
+
try {
|
|
173
|
+
const sdkPkgName = '@revoxai/sdk';
|
|
174
|
+
const sdkDir = path.resolve(packageNodeModulesPath, sdkPkgName);
|
|
175
|
+
const realSdkDir = fs.realpathSync(sdkDir);
|
|
176
|
+
if (realSdkDir !== sdkDir) {
|
|
177
|
+
allowReadPaths.push(realSdkDir);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
catch {
|
|
181
|
+
// Ignore if symlink resolution fails
|
|
182
|
+
}
|
|
183
|
+
const allowRead = allowReadPaths.join(',');
|
|
184
|
+
const worker = await newDenoHTTPWorker(url.pathToFileURL(workerPath), {
|
|
185
|
+
denoExecutable: denoPath,
|
|
186
|
+
runFlags: [
|
|
187
|
+
`--node-modules-dir=manual`,
|
|
188
|
+
`--allow-read=${allowRead}`,
|
|
189
|
+
`--allow-net=${baseURLHostname}`,
|
|
190
|
+
// Allow environment variables because instantiating the client will try to read from them,
|
|
191
|
+
// even though they are not set.
|
|
192
|
+
'--allow-env',
|
|
193
|
+
],
|
|
194
|
+
printOutput: true,
|
|
195
|
+
spawnOptions: {
|
|
196
|
+
cwd: path.dirname(workerPath),
|
|
197
|
+
},
|
|
198
|
+
});
|
|
199
|
+
try {
|
|
200
|
+
const resp = await new Promise((resolve, reject) => {
|
|
201
|
+
worker.addEventListener('exit', (exitCode) => {
|
|
202
|
+
reject(new Error(`Worker exited with code ${exitCode}`));
|
|
203
|
+
});
|
|
204
|
+
const opts = {
|
|
205
|
+
baseURL: client.baseURL,
|
|
206
|
+
apiKey: client.apiKey,
|
|
207
|
+
defaultHeaders: {
|
|
208
|
+
'X-Stainless-MCP': 'true',
|
|
209
|
+
},
|
|
210
|
+
};
|
|
211
|
+
const req = worker.request('http://localhost', {
|
|
212
|
+
headers: {
|
|
213
|
+
'content-type': 'application/json',
|
|
214
|
+
},
|
|
215
|
+
method: 'POST',
|
|
216
|
+
}, (resp) => {
|
|
217
|
+
const body = [];
|
|
218
|
+
resp.on('error', (err) => {
|
|
219
|
+
reject(err);
|
|
220
|
+
});
|
|
221
|
+
resp.on('data', (chunk) => {
|
|
222
|
+
body.push(chunk);
|
|
223
|
+
});
|
|
224
|
+
resp.on('end', () => {
|
|
225
|
+
resolve(new Response(Buffer.concat(body).toString(), {
|
|
226
|
+
status: resp.statusCode ?? 200,
|
|
227
|
+
headers: resp.headers,
|
|
228
|
+
}));
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
const body = JSON.stringify({
|
|
232
|
+
opts,
|
|
233
|
+
code,
|
|
234
|
+
});
|
|
235
|
+
req.write(body, (err) => {
|
|
236
|
+
if (err != null) {
|
|
237
|
+
reject(err);
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
req.end();
|
|
241
|
+
});
|
|
242
|
+
if (resp.status === 200) {
|
|
243
|
+
const { result, log_lines, err_lines } = (await resp.json());
|
|
244
|
+
const returnOutput = result == null ? null : ({
|
|
245
|
+
type: 'text',
|
|
246
|
+
text: typeof result === 'string' ? result : JSON.stringify(result),
|
|
247
|
+
});
|
|
248
|
+
const logOutput = log_lines.length === 0 ?
|
|
249
|
+
null
|
|
250
|
+
: {
|
|
251
|
+
type: 'text',
|
|
252
|
+
text: log_lines.join('\n'),
|
|
253
|
+
};
|
|
254
|
+
const errOutput = err_lines.length === 0 ?
|
|
255
|
+
null
|
|
256
|
+
: {
|
|
257
|
+
type: 'text',
|
|
258
|
+
text: 'Error output:\n' + err_lines.join('\n'),
|
|
259
|
+
};
|
|
260
|
+
return {
|
|
261
|
+
content: [returnOutput, logOutput, errOutput].filter((block) => block !== null),
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
const { result, log_lines, err_lines } = (await resp.json());
|
|
266
|
+
const messageOutput = result == null ? null : ({
|
|
267
|
+
type: 'text',
|
|
268
|
+
text: typeof result === 'string' ? result : JSON.stringify(result),
|
|
269
|
+
});
|
|
270
|
+
const logOutput = log_lines.length === 0 ?
|
|
271
|
+
null
|
|
272
|
+
: {
|
|
273
|
+
type: 'text',
|
|
274
|
+
text: log_lines.join('\n'),
|
|
275
|
+
};
|
|
276
|
+
const errOutput = err_lines.length === 0 ?
|
|
277
|
+
null
|
|
278
|
+
: {
|
|
279
|
+
type: 'text',
|
|
280
|
+
text: 'Error output:\n' + err_lines.join('\n'),
|
|
281
|
+
};
|
|
282
|
+
return {
|
|
283
|
+
content: [messageOutput, logOutput, errOutput].filter((block) => block !== null),
|
|
284
|
+
isError: true,
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
finally {
|
|
289
|
+
worker.terminate();
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
//# 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;OAEzB,EAAE,SAAS,EAAE;AAKpB,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;gGAoBiF,CAAC;AAEjG;;;;;;;;;;;;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;gBACD,MAAM,EAAE;oBACN,IAAI,EAAE,QAAQ;oBACd,WAAW,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