@justanothermldude/mcp-exec 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.
Files changed (78) hide show
  1. package/README.md +344 -0
  2. package/dist/bridge/index.d.ts +3 -0
  3. package/dist/bridge/index.d.ts.map +1 -0
  4. package/dist/bridge/index.js +3 -0
  5. package/dist/bridge/index.js.map +1 -0
  6. package/dist/bridge/server.d.ts +84 -0
  7. package/dist/bridge/server.d.ts.map +1 -0
  8. package/dist/bridge/server.js +352 -0
  9. package/dist/bridge/server.js.map +1 -0
  10. package/dist/codegen/index.d.ts +6 -0
  11. package/dist/codegen/index.d.ts.map +1 -0
  12. package/dist/codegen/index.js +6 -0
  13. package/dist/codegen/index.js.map +1 -0
  14. package/dist/codegen/module-resolver.d.ts +95 -0
  15. package/dist/codegen/module-resolver.d.ts.map +1 -0
  16. package/dist/codegen/module-resolver.js +152 -0
  17. package/dist/codegen/module-resolver.js.map +1 -0
  18. package/dist/codegen/wrapper-generator.d.ts +22 -0
  19. package/dist/codegen/wrapper-generator.d.ts.map +1 -0
  20. package/dist/codegen/wrapper-generator.js +282 -0
  21. package/dist/codegen/wrapper-generator.js.map +1 -0
  22. package/dist/index.d.ts +27 -0
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/index.js +123 -0
  25. package/dist/index.js.map +1 -0
  26. package/dist/sandbox/config.d.ts +37 -0
  27. package/dist/sandbox/config.d.ts.map +1 -0
  28. package/dist/sandbox/config.js +36 -0
  29. package/dist/sandbox/config.js.map +1 -0
  30. package/dist/sandbox/executor.d.ts +63 -0
  31. package/dist/sandbox/executor.d.ts.map +1 -0
  32. package/dist/sandbox/executor.js +240 -0
  33. package/dist/sandbox/executor.js.map +1 -0
  34. package/dist/sandbox/index.d.ts +8 -0
  35. package/dist/sandbox/index.d.ts.map +1 -0
  36. package/dist/sandbox/index.js +9 -0
  37. package/dist/sandbox/index.js.map +1 -0
  38. package/dist/server.d.ts +110 -0
  39. package/dist/server.d.ts.map +1 -0
  40. package/dist/server.js +150 -0
  41. package/dist/server.js.map +1 -0
  42. package/dist/tools/execute-batch.d.ts +111 -0
  43. package/dist/tools/execute-batch.d.ts.map +1 -0
  44. package/dist/tools/execute-batch.js +325 -0
  45. package/dist/tools/execute-batch.js.map +1 -0
  46. package/dist/tools/execute-code.d.ts +65 -0
  47. package/dist/tools/execute-code.d.ts.map +1 -0
  48. package/dist/tools/execute-code.js +141 -0
  49. package/dist/tools/execute-code.js.map +1 -0
  50. package/dist/tools/execute-with-context.d.ts +80 -0
  51. package/dist/tools/execute-with-context.d.ts.map +1 -0
  52. package/dist/tools/execute-with-context.js +223 -0
  53. package/dist/tools/execute-with-context.js.map +1 -0
  54. package/dist/tools/execute-with-wrappers.d.ts +69 -0
  55. package/dist/tools/execute-with-wrappers.d.ts.map +1 -0
  56. package/dist/tools/execute-with-wrappers.js +219 -0
  57. package/dist/tools/execute-with-wrappers.js.map +1 -0
  58. package/dist/tools/get-tool-schema.d.ts +59 -0
  59. package/dist/tools/get-tool-schema.d.ts.map +1 -0
  60. package/dist/tools/get-tool-schema.js +101 -0
  61. package/dist/tools/get-tool-schema.js.map +1 -0
  62. package/dist/tools/index.d.ts +10 -0
  63. package/dist/tools/index.d.ts.map +1 -0
  64. package/dist/tools/index.js +16 -0
  65. package/dist/tools/index.js.map +1 -0
  66. package/dist/tools/list-servers.d.ts +48 -0
  67. package/dist/tools/list-servers.d.ts.map +1 -0
  68. package/dist/tools/list-servers.js +85 -0
  69. package/dist/tools/list-servers.js.map +1 -0
  70. package/dist/types/execution.d.ts +25 -0
  71. package/dist/types/execution.d.ts.map +1 -0
  72. package/dist/types/execution.js +5 -0
  73. package/dist/types/execution.js.map +1 -0
  74. package/dist/types/index.d.ts +2 -0
  75. package/dist/types/index.d.ts.map +1 -0
  76. package/dist/types/index.js +3 -0
  77. package/dist/types/index.js.map +1 -0
  78. package/package.json +32 -0
@@ -0,0 +1,325 @@
1
+ import { SandboxExecutor } from '../sandbox/index.js';
2
+ import { MCPBridge } from '../bridge/index.js';
3
+ import { DEFAULT_TIMEOUT_MS } from '../types/execution.js';
4
+ /**
5
+ * MCP Tool definition for execute_batch
6
+ */
7
+ export const executeBatchTool = {
8
+ name: 'execute_batch',
9
+ description: 'Execute multiple code snippets in sequence with dependency ordering. ' +
10
+ 'Snippets can declare dependencies on other snippets via depends_on. ' +
11
+ 'The handler performs topological sort to determine execution order.',
12
+ inputSchema: {
13
+ type: 'object',
14
+ properties: {
15
+ snippets: {
16
+ type: 'array',
17
+ items: {
18
+ type: 'object',
19
+ properties: {
20
+ id: {
21
+ type: 'string',
22
+ description: 'Unique identifier for this snippet',
23
+ },
24
+ code: {
25
+ type: 'string',
26
+ description: 'The TypeScript/JavaScript code to execute',
27
+ },
28
+ depends_on: {
29
+ type: 'array',
30
+ items: { type: 'string' },
31
+ description: 'IDs of snippets that must execute before this one',
32
+ },
33
+ },
34
+ required: ['id', 'code'],
35
+ },
36
+ description: 'Array of code snippets to execute',
37
+ },
38
+ timeout_ms: {
39
+ type: 'number',
40
+ description: `Maximum execution time in milliseconds per snippet (default: ${DEFAULT_TIMEOUT_MS})`,
41
+ },
42
+ stop_on_error: {
43
+ type: 'boolean',
44
+ description: 'Stop execution on first error (default: true)',
45
+ },
46
+ },
47
+ required: ['snippets'],
48
+ },
49
+ };
50
+ /**
51
+ * Type guard for ExecuteBatchInput
52
+ */
53
+ export function isExecuteBatchInput(args) {
54
+ if (typeof args !== 'object' || args === null) {
55
+ return false;
56
+ }
57
+ const input = args;
58
+ if (!('snippets' in input) || !Array.isArray(input.snippets)) {
59
+ return false;
60
+ }
61
+ // Validate each snippet has required id and code
62
+ for (const snippet of input.snippets) {
63
+ if (typeof snippet !== 'object' || snippet === null) {
64
+ return false;
65
+ }
66
+ if (typeof snippet.id !== 'string' || typeof snippet.code !== 'string') {
67
+ return false;
68
+ }
69
+ if (snippet.depends_on !== undefined && !Array.isArray(snippet.depends_on)) {
70
+ return false;
71
+ }
72
+ if (snippet.depends_on && !snippet.depends_on.every((d) => typeof d === 'string')) {
73
+ return false;
74
+ }
75
+ }
76
+ return true;
77
+ }
78
+ /**
79
+ * Performs topological sort using Kahn's algorithm
80
+ * Returns sorted snippet IDs or throws if circular dependency detected
81
+ */
82
+ function topologicalSort(snippets) {
83
+ // Build adjacency list and in-degree map
84
+ const snippetMap = new Map();
85
+ const inDegree = new Map();
86
+ const adjacencyList = new Map();
87
+ // Initialize maps
88
+ for (const snippet of snippets) {
89
+ snippetMap.set(snippet.id, snippet);
90
+ inDegree.set(snippet.id, 0);
91
+ adjacencyList.set(snippet.id, []);
92
+ }
93
+ // Build graph edges
94
+ for (const snippet of snippets) {
95
+ if (snippet.depends_on) {
96
+ for (const dep of snippet.depends_on) {
97
+ if (!snippetMap.has(dep)) {
98
+ throw new Error(`Snippet '${snippet.id}' depends on unknown snippet '${dep}'`);
99
+ }
100
+ // Edge from dep -> snippet.id (dep must come before snippet)
101
+ adjacencyList.get(dep).push(snippet.id);
102
+ inDegree.set(snippet.id, inDegree.get(snippet.id) + 1);
103
+ }
104
+ }
105
+ }
106
+ // Kahn's algorithm: process nodes with zero in-degree
107
+ const queue = [];
108
+ const sorted = [];
109
+ // Find all nodes with zero in-degree
110
+ for (const [id, degree] of inDegree) {
111
+ if (degree === 0) {
112
+ queue.push(id);
113
+ }
114
+ }
115
+ while (queue.length > 0) {
116
+ const current = queue.shift();
117
+ sorted.push(current);
118
+ // Reduce in-degree for all neighbors
119
+ for (const neighbor of adjacencyList.get(current)) {
120
+ const newDegree = inDegree.get(neighbor) - 1;
121
+ inDegree.set(neighbor, newDegree);
122
+ if (newDegree === 0) {
123
+ queue.push(neighbor);
124
+ }
125
+ }
126
+ }
127
+ // Check for circular dependencies
128
+ if (sorted.length !== snippets.length) {
129
+ const remaining = snippets.filter((s) => !sorted.includes(s.id)).map((s) => s.id);
130
+ throw new Error(`Circular dependency detected involving snippets: ${remaining.join(', ')}`);
131
+ }
132
+ return sorted;
133
+ }
134
+ /**
135
+ * Creates the execute_batch handler function
136
+ *
137
+ * @param pool - Server pool for MCP connections
138
+ * @param config - Optional handler configuration
139
+ * @returns Handler function for execute_batch tool
140
+ */
141
+ export function createExecuteBatchHandler(pool, config = {}) {
142
+ // Ensure bridge port matches sandbox network config
143
+ const bridgePort = config.bridgeConfig?.port ?? 3000;
144
+ const sandboxConfig = {
145
+ ...config.sandboxConfig,
146
+ mcpBridgePort: bridgePort,
147
+ };
148
+ const executor = new SandboxExecutor(sandboxConfig);
149
+ const bridge = new MCPBridge(pool, {
150
+ ...config.bridgeConfig,
151
+ port: bridgePort,
152
+ });
153
+ /**
154
+ * Execute batch handler - performs topological sort and executes snippets in order
155
+ */
156
+ return async function executeBatchHandler(args) {
157
+ const { snippets, timeout_ms = DEFAULT_TIMEOUT_MS, stop_on_error = true } = args;
158
+ // Validate input
159
+ if (!snippets || !Array.isArray(snippets)) {
160
+ return {
161
+ content: [{ type: 'text', text: 'Error: snippets parameter is required and must be an array' }],
162
+ isError: true,
163
+ };
164
+ }
165
+ if (snippets.length === 0) {
166
+ return {
167
+ content: [{ type: 'text', text: 'Error: snippets array must contain at least one snippet' }],
168
+ isError: true,
169
+ };
170
+ }
171
+ // Validate each snippet
172
+ for (const snippet of snippets) {
173
+ if (!snippet.id || typeof snippet.id !== 'string') {
174
+ return {
175
+ content: [{ type: 'text', text: 'Error: each snippet must have a string id' }],
176
+ isError: true,
177
+ };
178
+ }
179
+ if (!snippet.code || typeof snippet.code !== 'string') {
180
+ return {
181
+ content: [{ type: 'text', text: `Error: snippet '${snippet.id}' must have a string code` }],
182
+ isError: true,
183
+ };
184
+ }
185
+ }
186
+ // Check for duplicate IDs
187
+ const ids = snippets.map((s) => s.id);
188
+ const duplicates = ids.filter((id, index) => ids.indexOf(id) !== index);
189
+ if (duplicates.length > 0) {
190
+ return {
191
+ content: [{ type: 'text', text: `Error: duplicate snippet IDs: ${[...new Set(duplicates)].join(', ')}` }],
192
+ isError: true,
193
+ };
194
+ }
195
+ if (timeout_ms !== undefined && (typeof timeout_ms !== 'number' || timeout_ms <= 0)) {
196
+ return {
197
+ content: [{ type: 'text', text: 'Error: timeout_ms must be a positive number' }],
198
+ isError: true,
199
+ };
200
+ }
201
+ // Perform topological sort
202
+ let sortedIds;
203
+ try {
204
+ sortedIds = topologicalSort(snippets);
205
+ }
206
+ catch (error) {
207
+ const errorMessage = error instanceof Error ? error.message : String(error);
208
+ return {
209
+ content: [{ type: 'text', text: `Error: ${errorMessage}` }],
210
+ isError: true,
211
+ };
212
+ }
213
+ // Create snippet map for quick lookup
214
+ const snippetMap = new Map();
215
+ for (const snippet of snippets) {
216
+ snippetMap.set(snippet.id, snippet);
217
+ }
218
+ // Execute snippets in sorted order
219
+ const results = [];
220
+ let hasError = false;
221
+ try {
222
+ // Start the MCP bridge server
223
+ await bridge.start();
224
+ for (const id of sortedIds) {
225
+ const snippet = snippetMap.get(id);
226
+ try {
227
+ const result = await executor.execute(snippet.code, timeout_ms);
228
+ const snippetResult = {
229
+ id,
230
+ output: result.output,
231
+ durationMs: result.durationMs,
232
+ };
233
+ if (result.error) {
234
+ snippetResult.error = result.error;
235
+ hasError = true;
236
+ }
237
+ results.push(snippetResult);
238
+ // Stop on error if configured
239
+ if (result.error && stop_on_error) {
240
+ break;
241
+ }
242
+ }
243
+ catch (execError) {
244
+ const errorMessage = execError instanceof Error ? execError.message : String(execError);
245
+ results.push({
246
+ id,
247
+ output: [],
248
+ error: errorMessage,
249
+ durationMs: 0,
250
+ });
251
+ hasError = true;
252
+ if (stop_on_error) {
253
+ break;
254
+ }
255
+ }
256
+ }
257
+ // Stop the bridge server
258
+ await bridge.stop();
259
+ // Format and return results
260
+ return formatBatchResult(results, hasError);
261
+ }
262
+ catch (error) {
263
+ // Ensure bridge is stopped on error
264
+ try {
265
+ if (bridge.isRunning()) {
266
+ await bridge.stop();
267
+ }
268
+ }
269
+ catch {
270
+ // Ignore cleanup errors
271
+ }
272
+ const errorMessage = error instanceof Error ? error.message : String(error);
273
+ return formatBatchErrorResult(errorMessage, results);
274
+ }
275
+ };
276
+ }
277
+ /**
278
+ * Format batch execution results
279
+ */
280
+ function formatBatchResult(results, hasError) {
281
+ const lines = [];
282
+ for (const result of results) {
283
+ lines.push(`=== Snippet '${result.id}' ===`);
284
+ if (result.output.length > 0) {
285
+ lines.push(...result.output);
286
+ }
287
+ if (result.error) {
288
+ lines.push(`[stderr]: ${result.error}`);
289
+ }
290
+ lines.push(`[Completed in ${result.durationMs}ms]`);
291
+ lines.push('');
292
+ }
293
+ const totalDuration = results.reduce((sum, r) => sum + r.durationMs, 0);
294
+ lines.push(`[Batch completed: ${results.length} snippet(s) in ${totalDuration}ms]`);
295
+ return {
296
+ content: [{ type: 'text', text: lines.join('\n') }],
297
+ isError: hasError,
298
+ };
299
+ }
300
+ /**
301
+ * Format batch error result with partial results
302
+ */
303
+ function formatBatchErrorResult(errorMessage, partialResults) {
304
+ const lines = [];
305
+ if (partialResults.length > 0) {
306
+ lines.push('[Partial results]:');
307
+ for (const result of partialResults) {
308
+ lines.push(`=== Snippet '${result.id}' ===`);
309
+ if (result.output.length > 0) {
310
+ lines.push(...result.output);
311
+ }
312
+ if (result.error) {
313
+ lines.push(`[stderr]: ${result.error}`);
314
+ }
315
+ lines.push(`[Completed in ${result.durationMs}ms]`);
316
+ lines.push('');
317
+ }
318
+ }
319
+ lines.push(`Error: ${errorMessage}`);
320
+ return {
321
+ content: [{ type: 'text', text: lines.join('\n') }],
322
+ isError: true,
323
+ };
324
+ }
325
+ //# sourceMappingURL=execute-batch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execute-batch.js","sourceRoot":"","sources":["../../src/tools/execute-batch.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,eAAe,EAA8B,MAAM,qBAAqB,CAAC;AAClF,OAAO,EAAE,SAAS,EAAwB,MAAM,oBAAoB,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAwB,MAAM,uBAAuB,CAAC;AAyCjF;;GAEG;A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IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACnD,OAAO,EAAE,IAAI;KACd,CAAC;AACJ,CAAC"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * execute_code MCP tool handler
3
+ * Orchestrates sandbox execution with MCP bridge for tool access
4
+ */
5
+ import type { ServerPool } from '@justanothermldude/meta-mcp-core';
6
+ import { type SandboxExecutorConfig } from '../sandbox/index.js';
7
+ import { type MCPBridgeConfig } from '../bridge/index.js';
8
+ import { type ExecuteCodeInput } from '../types/execution.js';
9
+ /**
10
+ * MCP Tool definition for execute_code
11
+ */
12
+ export declare const executeCodeTool: {
13
+ name: string;
14
+ description: string;
15
+ inputSchema: {
16
+ type: "object";
17
+ properties: {
18
+ code: {
19
+ type: string;
20
+ description: string;
21
+ };
22
+ timeout_ms: {
23
+ type: string;
24
+ description: string;
25
+ };
26
+ };
27
+ required: string[];
28
+ };
29
+ };
30
+ /**
31
+ * CallToolResult content item
32
+ */
33
+ export interface TextContent {
34
+ type: 'text';
35
+ text: string;
36
+ }
37
+ /**
38
+ * Standard MCP CallToolResult format
39
+ */
40
+ export interface CallToolResult {
41
+ content: TextContent[];
42
+ isError?: boolean;
43
+ }
44
+ /**
45
+ * Configuration for the execute_code handler
46
+ */
47
+ export interface ExecuteCodeHandlerConfig {
48
+ /** Configuration for the sandbox executor */
49
+ sandboxConfig?: SandboxExecutorConfig;
50
+ /** Configuration for the MCP bridge */
51
+ bridgeConfig?: MCPBridgeConfig;
52
+ }
53
+ /**
54
+ * Creates the execute_code handler function
55
+ *
56
+ * @param pool - Server pool for MCP connections
57
+ * @param config - Optional handler configuration
58
+ * @returns Handler function for execute_code tool
59
+ */
60
+ export declare function createExecuteCodeHandler(pool: ServerPool, config?: ExecuteCodeHandlerConfig): (args: ExecuteCodeInput) => Promise<CallToolResult>;
61
+ /**
62
+ * Type guard for ExecuteCodeInput
63
+ */
64
+ export declare function isExecuteCodeInput(args: unknown): args is ExecuteCodeInput;
65
+ //# sourceMappingURL=execute-code.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execute-code.d.ts","sourceRoot":"","sources":["../../src/tools/execute-code.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAmB,KAAK,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAClF,OAAO,EAAa,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrE,OAAO,EAAsB,KAAK,gBAAgB,EAAwB,MAAM,uBAAuB,CAAC;AAExG;;GAEG;AACH,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;CAkB3B,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,WAAW,EAAE,CAAC;IACvB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,6CAA6C;IAC7C,aAAa,CAAC,EAAE,qBAAqB,CAAC;IACtC,uCAAuC;IACvC,YAAY,CAAC,EAAE,eAAe,CAAC;CAChC;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,UAAU,EAChB,MAAM,GAAE,wBAA6B,IAmBnC,MAAM,gBAAgB,KACrB,OAAO,CAAC,cAAc,CAAC,CA+C3B;AAwDD;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,gBAAgB,CAO1E"}
@@ -0,0 +1,141 @@
1
+ import { SandboxExecutor } from '../sandbox/index.js';
2
+ import { MCPBridge } from '../bridge/index.js';
3
+ import { DEFAULT_TIMEOUT_MS } from '../types/execution.js';
4
+ /**
5
+ * MCP Tool definition for execute_code
6
+ */
7
+ export const executeCodeTool = {
8
+ name: 'execute_code',
9
+ description: 'Execute TypeScript/JavaScript code in a sandboxed environment with access to MCP tools via HTTP bridge',
10
+ inputSchema: {
11
+ type: 'object',
12
+ properties: {
13
+ code: {
14
+ type: 'string',
15
+ description: 'The TypeScript/JavaScript code to execute',
16
+ },
17
+ timeout_ms: {
18
+ type: 'number',
19
+ description: `Maximum execution time in milliseconds (default: ${DEFAULT_TIMEOUT_MS})`,
20
+ },
21
+ },
22
+ required: ['code'],
23
+ },
24
+ };
25
+ /**
26
+ * Creates the execute_code handler function
27
+ *
28
+ * @param pool - Server pool for MCP connections
29
+ * @param config - Optional handler configuration
30
+ * @returns Handler function for execute_code tool
31
+ */
32
+ export function createExecuteCodeHandler(pool, config = {}) {
33
+ // Ensure bridge port matches sandbox network config
34
+ const bridgePort = config.bridgeConfig?.port ?? 3000;
35
+ const sandboxConfig = {
36
+ ...config.sandboxConfig,
37
+ mcpBridgePort: bridgePort,
38
+ };
39
+ const executor = new SandboxExecutor(sandboxConfig);
40
+ const bridge = new MCPBridge(pool, {
41
+ ...config.bridgeConfig,
42
+ port: bridgePort,
43
+ });
44
+ /**
45
+ * Execute code handler - orchestrates bridge, executor, and cleanup
46
+ */
47
+ return async function executeCodeHandler(args) {
48
+ const { code, timeout_ms = DEFAULT_TIMEOUT_MS } = args;
49
+ // Validate input
50
+ if (!code || typeof code !== 'string') {
51
+ return {
52
+ content: [{ type: 'text', text: 'Error: code parameter is required and must be a string' }],
53
+ isError: true,
54
+ };
55
+ }
56
+ if (timeout_ms !== undefined && (typeof timeout_ms !== 'number' || timeout_ms <= 0)) {
57
+ return {
58
+ content: [{ type: 'text', text: 'Error: timeout_ms must be a positive number' }],
59
+ isError: true,
60
+ };
61
+ }
62
+ let result = null;
63
+ try {
64
+ // Step 1: Start the MCP bridge server
65
+ await bridge.start();
66
+ // Step 2: Execute code in sandbox
67
+ result = await executor.execute(code, timeout_ms);
68
+ // Step 3: Stop the bridge server
69
+ await bridge.stop();
70
+ // Step 4: Format and return result
71
+ return formatResult(result);
72
+ }
73
+ catch (error) {
74
+ // Ensure bridge is stopped on error
75
+ try {
76
+ if (bridge.isRunning()) {
77
+ await bridge.stop();
78
+ }
79
+ }
80
+ catch {
81
+ // Ignore cleanup errors
82
+ }
83
+ // Return error with any partial output
84
+ const errorMessage = error instanceof Error ? error.message : String(error);
85
+ return formatErrorResult(errorMessage, result);
86
+ }
87
+ };
88
+ }
89
+ /**
90
+ * Format a successful execution result
91
+ */
92
+ function formatResult(result) {
93
+ const lines = [];
94
+ // Add output
95
+ if (result.output.length > 0) {
96
+ lines.push(...result.output);
97
+ }
98
+ // Add error if present (non-fatal stderr)
99
+ if (result.error) {
100
+ lines.push(`[stderr]: ${result.error}`);
101
+ }
102
+ // Add execution time
103
+ lines.push(`[Execution completed in ${result.durationMs}ms]`);
104
+ const hasError = !!result.error;
105
+ return {
106
+ content: [{ type: 'text', text: lines.join('\n') }],
107
+ isError: hasError,
108
+ };
109
+ }
110
+ /**
111
+ * Format an error result with optional partial output
112
+ */
113
+ function formatErrorResult(errorMessage, partialResult) {
114
+ const lines = [];
115
+ // Add partial output if available
116
+ if (partialResult?.output.length) {
117
+ lines.push('[Partial output]:');
118
+ lines.push(...partialResult.output);
119
+ lines.push('');
120
+ }
121
+ // Add error message
122
+ lines.push(`Error: ${errorMessage}`);
123
+ // Add duration if available
124
+ if (partialResult?.durationMs) {
125
+ lines.push(`[Execution failed after ${partialResult.durationMs}ms]`);
126
+ }
127
+ return {
128
+ content: [{ type: 'text', text: lines.join('\n') }],
129
+ isError: true,
130
+ };
131
+ }
132
+ /**
133
+ * Type guard for ExecuteCodeInput
134
+ */
135
+ export function isExecuteCodeInput(args) {
136
+ return (typeof args === 'object' &&
137
+ args !== null &&
138
+ 'code' in args &&
139
+ typeof args.code === 'string');
140
+ }
141
+ //# sourceMappingURL=execute-code.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execute-code.js","sourceRoot":"","s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AC;IAED,OAAO;QACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACnD,OAAO,EAAE,IAAI;KACd,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAa;IAC9C,OAAO,CACL,OAAO,IAAI,KAAK,QAAQ;QACxB,IAAI,KAAK,IAAI;QACb,MAAM,IAAI,IAAI;QACd,OAAQ,IAAyB,CAAC,IAAI,KAAK,QAAQ,CACpD,CAAC;AACJ,CAAC"}
@@ -0,0 +1,80 @@
1
+ /**
2
+ * execute_with_context MCP tool handler
3
+ * Executes code with pre-injected context variables
4
+ */
5
+ import type { ServerPool } from '@justanothermldude/meta-mcp-core';
6
+ import { type SandboxExecutorConfig } from '../sandbox/index.js';
7
+ import { type MCPBridgeConfig } from '../bridge/index.js';
8
+ /**
9
+ * Input for execute_with_context requests
10
+ */
11
+ export interface ExecuteWithContextInput {
12
+ /** The code to execute */
13
+ code: string;
14
+ /** Context object to inject into code execution */
15
+ context?: Record<string, unknown>;
16
+ /** Execution timeout in milliseconds (default: 30000) */
17
+ timeout_ms?: number;
18
+ }
19
+ /**
20
+ * MCP Tool definition for execute_with_context
21
+ */
22
+ export declare const executeWithContextTool: {
23
+ name: string;
24
+ description: string;
25
+ inputSchema: {
26
+ type: "object";
27
+ properties: {
28
+ code: {
29
+ type: string;
30
+ description: string;
31
+ };
32
+ context: {
33
+ type: string;
34
+ description: string;
35
+ additionalProperties: boolean;
36
+ };
37
+ timeout_ms: {
38
+ type: string;
39
+ description: string;
40
+ };
41
+ };
42
+ required: string[];
43
+ };
44
+ };
45
+ /**
46
+ * CallToolResult content item
47
+ */
48
+ export interface TextContent {
49
+ type: 'text';
50
+ text: string;
51
+ }
52
+ /**
53
+ * Standard MCP CallToolResult format
54
+ */
55
+ export interface CallToolResult {
56
+ content: TextContent[];
57
+ isError?: boolean;
58
+ }
59
+ /**
60
+ * Configuration for the execute_with_context handler
61
+ */
62
+ export interface ExecuteWithContextHandlerConfig {
63
+ /** Configuration for the sandbox executor */
64
+ sandboxConfig?: SandboxExecutorConfig;
65
+ /** Configuration for the MCP bridge */
66
+ bridgeConfig?: MCPBridgeConfig;
67
+ }
68
+ /**
69
+ * Creates the execute_with_context handler function
70
+ *
71
+ * @param pool - Server pool for MCP connections
72
+ * @param config - Optional handler configuration
73
+ * @returns Handler function for execute_with_context tool
74
+ */
75
+ export declare function createExecuteWithContextHandler(pool: ServerPool, config?: ExecuteWithContextHandlerConfig): (args: ExecuteWithContextInput) => Promise<CallToolResult>;
76
+ /**
77
+ * Type guard for ExecuteWithContextInput
78
+ */
79
+ export declare function isExecuteWithContextInput(args: unknown): args is ExecuteWithContextInput;
80
+ //# sourceMappingURL=execute-with-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execute-with-context.d.ts","sourceRoot":"","sources":["../../src/tools/execute-with-context.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAmB,KAAK,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAClF,OAAO,EAAa,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAGrE;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,0BAA0B;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,mDAAmD;IACnD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,yDAAyD;IACzD,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;CAuBlC,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,WAAW,EAAE,CAAC;IACvB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,+BAA+B;IAC9C,6CAA6C;IAC7C,aAAa,CAAC,EAAE,qBAAqB,CAAC;IACtC,uCAAuC;IACvC,YAAY,CAAC,EAAE,eAAe,CAAC;CAChC;AAsCD;;;;;;GAMG;AACH,wBAAgB,+BAA+B,CAC7C,IAAI,EAAE,UAAU,EAChB,MAAM,GAAE,+BAAoC,IAmB1C,MAAM,uBAAuB,KAC5B,OAAO,CAAC,cAAc,CAAC,CAgF3B;AAwDD;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,uBAAuB,CAoBxF"}