@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,22 @@
1
+ /**
2
+ * TypeScript wrapper generator for MCP tools.
3
+ * Generates type-safe wrapper functions that call bridge endpoint.
4
+ */
5
+ import type { ToolDefinition } from '@justanothermldude/meta-mcp-core';
6
+ /**
7
+ * Generate TypeScript wrapper code for a single MCP tool (legacy - kept for compatibility)
8
+ * @param tool - Tool definition from MCP server
9
+ * @param serverName - Name of the MCP server
10
+ * @returns TypeScript code string
11
+ * @deprecated Use generateServerModule instead for namespace-based wrappers
12
+ */
13
+ export declare function generateToolWrapper(tool: ToolDefinition, serverName: string): string;
14
+ /**
15
+ * Generate a complete TypeScript module with a namespace object for all tools
16
+ * @param tools - Array of tool definitions
17
+ * @param serverName - Name of the MCP server
18
+ * @param bridgePort - Port for the MCP bridge (default: 3000)
19
+ * @returns TypeScript code string with namespace object
20
+ */
21
+ export declare function generateServerModule(tools: ToolDefinition[], serverName: string, bridgePort?: number): string;
22
+ //# sourceMappingURL=wrapper-generator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wrapper-generator.d.ts","sourceRoot":"","sources":["../../src/codegen/wrapper-generator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAqOvE;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAqDpF;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,cAAc,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,GAAE,MAAa,GAAG,MAAM,CAiCnH"}
@@ -0,0 +1,282 @@
1
+ /**
2
+ * TypeScript wrapper generator for MCP tools.
3
+ * Generates type-safe wrapper functions that call bridge endpoint.
4
+ */
5
+ /**
6
+ * Bridge endpoint URL for tool calls
7
+ */
8
+ const BRIDGE_ENDPOINT = 'http://localhost:3000/call';
9
+ /**
10
+ * Convert a JSON Schema type to TypeScript type
11
+ * @param prop - JSON Schema property definition
12
+ * @param required - Whether the property is required
13
+ * @returns TypeScript type string
14
+ */
15
+ function jsonSchemaToTs(prop, _required = true) {
16
+ if (!prop) {
17
+ return 'unknown';
18
+ }
19
+ // Handle array of types (e.g., ["string", "null"])
20
+ if (Array.isArray(prop.type)) {
21
+ const types = prop.type.map((t) => primitiveToTs(t));
22
+ return types.join(' | ');
23
+ }
24
+ // Handle enum types
25
+ if (prop.enum) {
26
+ return prop.enum.map((v) => JSON.stringify(v)).join(' | ');
27
+ }
28
+ // Handle object types with properties
29
+ if (prop.type === 'object' && prop.properties) {
30
+ const propLines = Object.entries(prop.properties).map(([key, value]) => {
31
+ const isRequired = prop.required?.includes(key) ?? false;
32
+ const tsType = jsonSchemaToTs(value, isRequired);
33
+ const optionalMark = isRequired ? '' : '?';
34
+ return `${key}${optionalMark}: ${tsType}`;
35
+ });
36
+ return `{ ${propLines.join('; ')} }`;
37
+ }
38
+ // Handle array types
39
+ if (prop.type === 'array') {
40
+ const itemType = prop.items ? jsonSchemaToTs(prop.items, true) : 'unknown';
41
+ return `${itemType}[]`;
42
+ }
43
+ // Handle primitive types
44
+ return primitiveToTs(prop.type ?? 'unknown');
45
+ }
46
+ /**
47
+ * Convert JSON Schema primitive type to TypeScript
48
+ */
49
+ function primitiveToTs(type) {
50
+ switch (type) {
51
+ case 'string':
52
+ return 'string';
53
+ case 'number':
54
+ case 'integer':
55
+ return 'number';
56
+ case 'boolean':
57
+ return 'boolean';
58
+ case 'null':
59
+ return 'null';
60
+ case 'object':
61
+ return 'Record<string, unknown>';
62
+ case 'array':
63
+ return 'unknown[]';
64
+ default:
65
+ return 'unknown';
66
+ }
67
+ }
68
+ /**
69
+ * Generate TypeScript interface from JSON Schema
70
+ * @param name - Interface name
71
+ * @param schema - JSON Schema object
72
+ * @returns TypeScript interface definition
73
+ */
74
+ function generateInterface(name, schema) {
75
+ if (!schema.properties || Object.keys(schema.properties).length === 0) {
76
+ return `interface ${name} {}`;
77
+ }
78
+ const lines = [];
79
+ lines.push(`interface ${name} {`);
80
+ for (const [propName, propValue] of Object.entries(schema.properties)) {
81
+ const prop = propValue;
82
+ const isRequired = schema.required?.includes(propName) ?? false;
83
+ const optionalMark = isRequired ? '' : '?';
84
+ const tsType = jsonSchemaToTs(prop, isRequired);
85
+ // Add JSDoc if description exists
86
+ if (prop.description) {
87
+ lines.push(` /** ${prop.description} */`);
88
+ }
89
+ lines.push(` ${propName}${optionalMark}: ${tsType};`);
90
+ }
91
+ lines.push('}');
92
+ return lines.join('\n');
93
+ }
94
+ /**
95
+ * Sanitize tool name to valid TypeScript identifier
96
+ */
97
+ function sanitizeIdentifier(name) {
98
+ // Replace non-alphanumeric chars with underscore, ensure starts with letter
99
+ let sanitized = name.replace(/[^a-zA-Z0-9_]/g, '_');
100
+ if (/^[0-9]/.test(sanitized)) {
101
+ sanitized = '_' + sanitized;
102
+ }
103
+ return sanitized;
104
+ }
105
+ /**
106
+ * Convert tool name to camelCase for method name
107
+ */
108
+ function toCamelCase(name) {
109
+ const words = name.split(/[^a-zA-Z0-9]+/).filter(Boolean);
110
+ if (words.length === 0)
111
+ return name;
112
+ return words
113
+ .map((word, index) => index === 0
114
+ ? word.toLowerCase()
115
+ : word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
116
+ .join('');
117
+ }
118
+ /**
119
+ * Convert tool name to PascalCase for interface name
120
+ */
121
+ function toPascalCase(name) {
122
+ return name
123
+ .split(/[^a-zA-Z0-9]+/)
124
+ .filter(Boolean)
125
+ .map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
126
+ .join('');
127
+ }
128
+ /**
129
+ * Generate interface definition for a tool (if it has input properties)
130
+ * @param tool - Tool definition from MCP server
131
+ * @returns Interface definition string or empty string
132
+ */
133
+ function generateToolInterface(tool) {
134
+ const interfaceName = `${toPascalCase(tool.name)}Input`;
135
+ if (tool.inputSchema?.properties && Object.keys(tool.inputSchema.properties).length > 0) {
136
+ return generateInterface(interfaceName, tool.inputSchema);
137
+ }
138
+ return '';
139
+ }
140
+ /**
141
+ * Generate a method definition for the namespace object
142
+ * @param tool - Tool definition from MCP server
143
+ * @param serverName - Name of the MCP server
144
+ * @param bridgePort - Port for the MCP bridge
145
+ * @returns Method definition string for inclusion in namespace object
146
+ */
147
+ function generateMethodDefinition(tool, serverName, bridgePort) {
148
+ const methodName = toCamelCase(tool.name);
149
+ const interfaceName = `${toPascalCase(tool.name)}Input`;
150
+ const hasInput = tool.inputSchema?.properties && Object.keys(tool.inputSchema.properties).length > 0;
151
+ const inputParam = hasInput ? `input: ${interfaceName}` : '';
152
+ const inputArg = hasInput ? 'input' : '{}';
153
+ const lines = [];
154
+ // Add JSDoc comment
155
+ if (tool.description) {
156
+ lines.push(' /**');
157
+ lines.push(` * ${tool.description}`);
158
+ if (tool.inputSchema?.properties) {
159
+ for (const [propName, propValue] of Object.entries(tool.inputSchema.properties)) {
160
+ const prop = propValue;
161
+ if (prop.description) {
162
+ lines.push(` * @param input.${propName} - ${prop.description}`);
163
+ }
164
+ }
165
+ }
166
+ lines.push(' */');
167
+ }
168
+ // Escape server/tool names to prevent code injection via malicious names
169
+ const safeServerName = JSON.stringify(serverName);
170
+ const safeToolName = JSON.stringify(tool.name);
171
+ lines.push(` ${methodName}: async (${inputParam}): Promise<unknown> => {`);
172
+ lines.push(` const response = await fetch('http://localhost:${bridgePort}/call', {`);
173
+ lines.push(` method: 'POST',`);
174
+ lines.push(` headers: { 'Content-Type': 'application/json' },`);
175
+ lines.push(` body: JSON.stringify({`);
176
+ lines.push(` server: ${safeServerName},`);
177
+ lines.push(` tool: ${safeToolName},`);
178
+ lines.push(` args: ${inputArg},`);
179
+ lines.push(` }),`);
180
+ lines.push(` });`);
181
+ lines.push(` if (!response.ok) {`);
182
+ lines.push(' throw new Error(`Tool call failed: ${response.statusText}`);');
183
+ lines.push(` }`);
184
+ lines.push(` const data = await response.json() as { success: boolean; content?: unknown; error?: string };`);
185
+ lines.push(` if (!data.success) {`);
186
+ lines.push(` throw new Error(data.error || 'Tool call failed');`);
187
+ lines.push(` }`);
188
+ lines.push(` return data.content;`);
189
+ lines.push(` },`);
190
+ return lines.join('\n');
191
+ }
192
+ /**
193
+ * Generate TypeScript wrapper code for a single MCP tool (legacy - kept for compatibility)
194
+ * @param tool - Tool definition from MCP server
195
+ * @param serverName - Name of the MCP server
196
+ * @returns TypeScript code string
197
+ * @deprecated Use generateServerModule instead for namespace-based wrappers
198
+ */
199
+ export function generateToolWrapper(tool, serverName) {
200
+ const funcName = sanitizeIdentifier(tool.name);
201
+ const interfaceName = `${toPascalCase(tool.name)}Input`;
202
+ const lines = [];
203
+ // Generate input interface if there are properties
204
+ if (tool.inputSchema?.properties && Object.keys(tool.inputSchema.properties).length > 0) {
205
+ lines.push(generateInterface(interfaceName, tool.inputSchema));
206
+ lines.push('');
207
+ }
208
+ // Add JSDoc comment
209
+ if (tool.description) {
210
+ lines.push('/**');
211
+ lines.push(` * ${tool.description}`);
212
+ if (tool.inputSchema?.properties) {
213
+ lines.push(' *');
214
+ for (const [propName, propValue] of Object.entries(tool.inputSchema.properties)) {
215
+ const prop = propValue;
216
+ if (prop.description) {
217
+ lines.push(` * @param input.${propName} - ${prop.description}`);
218
+ }
219
+ }
220
+ }
221
+ lines.push(' * @returns Promise resolving to tool result');
222
+ lines.push(' */');
223
+ }
224
+ // Generate function signature (no export - for inline execution)
225
+ const hasInput = tool.inputSchema?.properties && Object.keys(tool.inputSchema.properties).length > 0;
226
+ const inputParam = hasInput ? `input: ${interfaceName}` : '';
227
+ const inputArg = hasInput ? 'input' : '{}';
228
+ lines.push(`async function ${funcName}(${inputParam}): Promise<unknown> {`);
229
+ lines.push(` const response = await fetch('${BRIDGE_ENDPOINT}', {`);
230
+ lines.push(` method: 'POST',`);
231
+ lines.push(` headers: { 'Content-Type': 'application/json' },`);
232
+ lines.push(` body: JSON.stringify({`);
233
+ lines.push(` server: '${serverName}',`);
234
+ lines.push(` tool: '${tool.name}',`);
235
+ lines.push(` args: ${inputArg},`);
236
+ lines.push(` }),`);
237
+ lines.push(` });`);
238
+ lines.push('');
239
+ lines.push(' if (!response.ok) {');
240
+ lines.push(' throw new Error(`Tool call failed: ${response.statusText}`);');
241
+ lines.push(' }');
242
+ lines.push('');
243
+ lines.push(' return response.json();');
244
+ lines.push('}');
245
+ return lines.join('\n');
246
+ }
247
+ /**
248
+ * Generate a complete TypeScript module with a namespace object for all tools
249
+ * @param tools - Array of tool definitions
250
+ * @param serverName - Name of the MCP server
251
+ * @param bridgePort - Port for the MCP bridge (default: 3000)
252
+ * @returns TypeScript code string with namespace object
253
+ */
254
+ export function generateServerModule(tools, serverName, bridgePort = 3000) {
255
+ const lines = [];
256
+ const namespaceName = sanitizeIdentifier(serverName);
257
+ // File header comment
258
+ lines.push('/**');
259
+ lines.push(` * Auto-generated TypeScript wrappers for ${serverName} MCP server tools.`);
260
+ lines.push(` * Access tools via: ${namespaceName}.methodName()`);
261
+ lines.push(' */');
262
+ lines.push('');
263
+ // Generate all interfaces first
264
+ for (const tool of tools) {
265
+ const interfaceCode = generateToolInterface(tool);
266
+ if (interfaceCode) {
267
+ lines.push(interfaceCode);
268
+ lines.push('');
269
+ }
270
+ }
271
+ // Generate the namespace object with all methods
272
+ lines.push(`const ${namespaceName} = {`);
273
+ for (let i = 0; i < tools.length; i++) {
274
+ const tool = tools[i];
275
+ lines.push(generateMethodDefinition(tool, serverName, bridgePort));
276
+ // No trailing comma after last method (already handled by generateMethodDefinition)
277
+ }
278
+ lines.push('};');
279
+ lines.push('');
280
+ return lines.join('\n');
281
+ }
282
+ //# sourceMappingURL=wrapper-generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wrapper-generator.js","sourceRoot":"","sources":["../../src/codegen/wrapper-generator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;GAEG;AACH,MAAM,eAAe,GAAG,4BAA4B,CAAC;AAgBrD;;;;;GAKG;AACH,SAAS,cAAc,CAAC,IAAoC,EAAE,YAAqB,IAAI;IACrF,IAAI,CAAC,IAAI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AU,CAAC,CAAC;IAErD,sBAAsB;IACtB,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClB,KAAK,CAAC,IAAI,CAAC,6CAA6C,UAAU,oBAAoB,CAAC,CAAC;IACxF,KAAK,CAAC,IAAI,CAAC,wBAAwB,aAAa,eAAe,CAAC,CAAC;IACjE,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClB,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAEf,gCAAgC;IAChC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,aAAa,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC;QAClD,IAAI,aAAa,EAAE,CAAC;YAClB,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;YAC1B,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACjB,CAAC;IACH,CAAC;IAED,iDAAiD;IACjD,KAAK,CAAC,IAAI,CAAC,SAAS,aAAa,MAAM,CAAC,CAAC;IAEzC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACtB,KAAK,CAAC,IAAI,CAAC,wBAAwB,CAAC,IAAI,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC;QACnE,oFAAoF;IACtF,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjB,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAEf,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env node
2
+ export * from './types/index.js';
3
+ export * from './sandbox/index.js';
4
+ export * from './codegen/index.js';
5
+ export * from './bridge/index.js';
6
+ export * from './tools/index.js';
7
+ export { createMcpExecServer, type McpExecServerConfig } from './server.js';
8
+ export type { ExecuteCodeInput, ExecutionResult } from './types/execution.js';
9
+ import type { ExecuteCodeInput, ExecutionResult } from './types/execution.js';
10
+ import { SandboxExecutor, type SandboxExecutorConfig } from './sandbox/index.js';
11
+ export declare const APP_NAME = "mcp-exec";
12
+ export declare const VERSION = "0.1.0";
13
+ /**
14
+ * Execute code in a sandboxed environment using @anthropic-ai/sandbox-runtime.
15
+ * Provides OS-level isolation (sandbox-exec on macOS, bubblewrap on Linux).
16
+ *
17
+ * @param input - The code execution input parameters
18
+ * @returns Promise resolving to execution result
19
+ */
20
+ export declare function executeCode(input: ExecuteCodeInput): Promise<ExecutionResult>;
21
+ /**
22
+ * Create a new SandboxExecutor with custom configuration
23
+ * @param config - Configuration options for the sandbox
24
+ * @returns New SandboxExecutor instance
25
+ */
26
+ export declare function createExecutor(config?: SandboxExecutorConfig): SandboxExecutor;
27
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAWA,cAAc,kBAAkB,CAAC;AAGjC,cAAc,oBAAoB,CAAC;AAGnC,cAAc,oBAAoB,CAAC;AAGnC,cAAc,mBAAmB,CAAC;AAGlC,cAAc,kBAAkB,CAAC;AAGjC,OAAO,EAAE,mBAAmB,EAAE,KAAK,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAG5E,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE9E,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,KAAK,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAGjF,eAAO,MAAM,QAAQ,aAAa,CAAC;AACnC,eAAO,MAAM,OAAO,UAAU,CAAC;AAe/B;;;;;;GAMG;AACH,wBAAsB,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC,CAInF;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,CAAC,EAAE,qBAAqB,GAAG,eAAe,CAE9E"}
package/dist/index.js ADDED
@@ -0,0 +1,123 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * @meta-mcp/exec - MCP execution utilities for sandboxed code execution
4
+ *
5
+ * Entry point for both the MCP server and programmatic API usage.
6
+ */
7
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
8
+ import { createMcpExecServer } from './server.js';
9
+ import { ServerPool, createConnection, getServerConfig, loadServerManifest } from '@justanothermldude/meta-mcp-core';
10
+ // Export types
11
+ export * from './types/index.js';
12
+ // Export sandbox module
13
+ export * from './sandbox/index.js';
14
+ // Export codegen module
15
+ export * from './codegen/index.js';
16
+ // Export bridge module
17
+ export * from './bridge/index.js';
18
+ // Export tools module
19
+ export * from './tools/index.js';
20
+ // Export server module
21
+ export { createMcpExecServer } from './server.js';
22
+ import { SandboxExecutor } from './sandbox/index.js';
23
+ import { DEFAULT_TIMEOUT_MS } from './types/execution.js';
24
+ export const APP_NAME = 'mcp-exec';
25
+ export const VERSION = '0.1.0';
26
+ // Default executor instance (lazily initialized)
27
+ let defaultExecutor = null;
28
+ /**
29
+ * Get or create the default SandboxExecutor instance
30
+ */
31
+ function getDefaultExecutor() {
32
+ if (!defaultExecutor) {
33
+ defaultExecutor = new SandboxExecutor();
34
+ }
35
+ return defaultExecutor;
36
+ }
37
+ /**
38
+ * Execute code in a sandboxed environment using @anthropic-ai/sandbox-runtime.
39
+ * Provides OS-level isolation (sandbox-exec on macOS, bubblewrap on Linux).
40
+ *
41
+ * @param input - The code execution input parameters
42
+ * @returns Promise resolving to execution result
43
+ */
44
+ export async function executeCode(input) {
45
+ const { code, timeout_ms = DEFAULT_TIMEOUT_MS } = input;
46
+ const executor = getDefaultExecutor();
47
+ return executor.execute(code, timeout_ms);
48
+ }
49
+ /**
50
+ * Create a new SandboxExecutor with custom configuration
51
+ * @param config - Configuration options for the sandbox
52
+ * @returns New SandboxExecutor instance
53
+ */
54
+ export function createExecutor(config) {
55
+ return new SandboxExecutor(config);
56
+ }
57
+ // Handle --version and --help flags
58
+ const args = process.argv.slice(2);
59
+ if (args.includes('--version') || args.includes('-v')) {
60
+ console.log(VERSION);
61
+ process.exit(0);
62
+ }
63
+ if (args.includes('--help') || args.includes('-h')) {
64
+ console.log(`${APP_NAME} v${VERSION}
65
+
66
+ An MCP server for executing TypeScript/JavaScript code in sandboxed environments
67
+ with access to MCP tools via HTTP bridge.
68
+
69
+ Usage:
70
+ mcp-exec Start the server (stdio transport)
71
+ mcp-exec --version Show version
72
+ mcp-exec --help Show this help
73
+
74
+ Environment:
75
+ SERVERS_CONFIG Path to servers.json config file
76
+ Default: ~/.meta-mcp/servers.json
77
+ `);
78
+ process.exit(0);
79
+ }
80
+ async function main() {
81
+ // Load config on startup
82
+ const configPath = process.env.SERVERS_CONFIG;
83
+ if (configPath) {
84
+ process.stderr.write(`Loading config from: ${configPath}\n`);
85
+ }
86
+ // Load server manifest (required before getServerConfig works)
87
+ loadServerManifest();
88
+ // Create connection factory
89
+ const connectionFactory = async (serverId) => {
90
+ const config = getServerConfig(serverId);
91
+ if (!config) {
92
+ throw new Error(`Server config not found: ${serverId}`);
93
+ }
94
+ return createConnection(config);
95
+ };
96
+ // Initialize pool
97
+ const pool = new ServerPool(connectionFactory);
98
+ // Create server
99
+ const { server, shutdown } = createMcpExecServer(pool);
100
+ // Graceful shutdown handlers
101
+ const handleShutdown = async () => {
102
+ process.stderr.write('Shutting down...\n');
103
+ await shutdown();
104
+ await pool.shutdown();
105
+ await server.close();
106
+ process.exit(0);
107
+ };
108
+ process.on('SIGINT', handleShutdown);
109
+ process.on('SIGTERM', handleShutdown);
110
+ // Connect via stdio
111
+ const transport = new StdioServerTransport();
112
+ await server.connect(transport);
113
+ process.stderr.write('mcp-exec server running on stdio\n');
114
+ }
115
+ // Only run main if this is the entry point (not when imported as a module)
116
+ const isMainModule = process.argv[1]?.endsWith('index.js') || process.argv[1]?.endsWith('mcp-exec');
117
+ if (isMainModule && !args.includes('--no-server')) {
118
+ main().catch((error) => {
119
+ console.error('Fatal error:', error);
120
+ process.exit(1);
121
+ });
122
+ }
123
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;GAIG;AACH,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAErH,eAAe;AACf,cAAc,kBAAkB,CAAC;AAEjC,wBAAwB;AACxB,cAAc,oBAAoB,CAAC;AAEnC,wBAAwB;AACxB,cAAc,oBAAoB,CAAC;AAEnC,uBAAuB;AACvB,cAAc,mBAAmB,CAAC;AAElC,sBAAsB;AACtB,cAAc,kBAAkB,CAAC;AAEjC,uBAAuB;AACvB,OAAO,EAAE,mBAAmB,EAA4B,MAAM,aAAa,CAAC;AAM5E,OAAO,EAAE,eAAe,EAA8B,MAAM,oBAAoB,CAAC;AACjF,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,MAAM,CAAC,MAAM,QAAQ,GAAG,UAAU,CAAC;AACnC,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC;AAE/B,iDAAiD;AACjD,IAAI,eAAe,GAA2B,IAAI,CAAC;AAEnD;;GAEG;AACH,SAAS,kBAAkB;IACzB,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,eAAe,GAAG,IAAI,eAAe,EAAE,CAAC;IAC1C,CAAC;IACD,OAAO,eAAe,CAAC;AACzB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,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AAC,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC;IAClD,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;QACrB,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;QACrC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Sandbox configuration for OS-level code execution isolation
3
+ * Uses @anthropic-ai/sandbox-runtime for security boundaries
4
+ */
5
+ import type { SandboxRuntimeConfig, NetworkConfig, FilesystemConfig } from '@anthropic-ai/sandbox-runtime';
6
+ /**
7
+ * Default MCP bridge port for sandbox communication
8
+ */
9
+ export declare const DEFAULT_MCP_BRIDGE_PORT = 3000;
10
+ /**
11
+ * Default network configuration - only allows localhost:3000 for MCP bridge
12
+ */
13
+ export declare function createDefaultNetworkConfig(mcpBridgePort?: number): NetworkConfig;
14
+ /**
15
+ * Default filesystem configuration - only allows writes to temp directory
16
+ */
17
+ export declare function createDefaultFilesystemConfig(additionalWritePaths?: string[]): FilesystemConfig;
18
+ /**
19
+ * Configuration options for SandboxExecutor
20
+ */
21
+ export interface SandboxExecutorConfig {
22
+ /** Port for MCP bridge communication (default: 3000) */
23
+ mcpBridgePort?: number;
24
+ /** Additional paths to allow writes to */
25
+ additionalWritePaths?: string[];
26
+ /** Enable log monitoring for sandbox violations */
27
+ enableLogMonitor?: boolean;
28
+ /** Custom network configuration (overrides default) */
29
+ networkConfig?: NetworkConfig;
30
+ /** Custom filesystem configuration (overrides default) */
31
+ filesystemConfig?: FilesystemConfig;
32
+ }
33
+ /**
34
+ * Creates a complete SandboxRuntimeConfig from executor options
35
+ */
36
+ export declare function createSandboxRuntimeConfig(options?: SandboxExecutorConfig): SandboxRuntimeConfig;
37
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/sandbox/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,oBAAoB,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAG3G;;GAEG;AACH,eAAO,MAAM,uBAAuB,OAAO,CAAC;AAE5C;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,aAAa,GAAE,MAAgC,GAAG,aAAa,CAMzG;AAED;;GAEG;AACH,wBAAgB,6BAA6B,CAAC,oBAAoB,GAAE,MAAM,EAAO,GAAG,gBAAgB,CAMnG;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,wDAAwD;IACxD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,0CAA0C;IAC1C,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;IAChC,mDAAmD;IACnD,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,uDAAuD;IACvD,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,0DAA0D;IAC1D,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;CACrC;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,GAAE,qBAA0B,GAAG,oBAAoB,CAYpG"}
@@ -0,0 +1,36 @@
1
+ import { tmpdir } from 'node:os';
2
+ /**
3
+ * Default MCP bridge port for sandbox communication
4
+ */
5
+ export const DEFAULT_MCP_BRIDGE_PORT = 3000;
6
+ /**
7
+ * Default network configuration - only allows localhost:3000 for MCP bridge
8
+ */
9
+ export function createDefaultNetworkConfig(mcpBridgePort = DEFAULT_MCP_BRIDGE_PORT) {
10
+ return {
11
+ allowedDomains: [`localhost:${mcpBridgePort}`],
12
+ deniedDomains: [],
13
+ allowLocalBinding: true,
14
+ };
15
+ }
16
+ /**
17
+ * Default filesystem configuration - only allows writes to temp directory
18
+ */
19
+ export function createDefaultFilesystemConfig(additionalWritePaths = []) {
20
+ return {
21
+ denyRead: [],
22
+ allowWrite: [tmpdir(), ...additionalWritePaths],
23
+ denyWrite: [],
24
+ };
25
+ }
26
+ /**
27
+ * Creates a complete SandboxRuntimeConfig from executor options
28
+ */
29
+ export function createSandboxRuntimeConfig(options = {}) {
30
+ const { mcpBridgePort = DEFAULT_MCP_BRIDGE_PORT, additionalWritePaths = [], networkConfig, filesystemConfig, } = options;
31
+ return {
32
+ network: networkConfig ?? createDefaultNetworkConfig(mcpBridgePort),
33
+ filesystem: filesystemConfig ?? createDefaultFilesystemConfig(additionalWritePaths),
34
+ };
35
+ }
36
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/sandbox/config.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEjC;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,IAAI,CAAC;AAE5C;;GAEG;AACH,MAAM,UAAU,0BAA0B,CAAC,gBAAwB,uBAAuB;IACxF,OAAO;QACL,cAAc,EAAE,CAAC,aAAa,aAAa,EAAE,CAAC;QAC9C,aAAa,EAAE,EAAE;QACjB,iBAAiB,EAAE,IAAI;KACxB,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,6BAA6B,CAAC,uBAAiC,EAAE;IAC/E,OAAO;QACL,QAAQ,EAAE,EAAE;QACZ,UAAU,EAAE,CAAC,MAAM,EAAE,EAAE,GAAG,oBAAoB,CAAC;QAC/C,SAAS,EAAE,EAAE;KACd,CAAC;AACJ,CAAC;AAkBD;;GAEG;AACH,MAAM,UAAU,0BAA0B,CAAC,UAAiC,EAAE;IAC5E,MAAM,EACJ,aAAa,GAAG,uBAAuB,EACvC,oBAAoB,GAAG,EAAE,EACzB,aAAa,EACb,gBAAgB,GACjB,GAAG,OAAO,CAAC;IAEZ,OAAO;QACL,OAAO,EAAE,aAAa,IAAI,0BAA0B,CAAC,aAAa,CAAC;QACnE,UAAU,EAAE,gBAAgB,IAAI,6BAA6B,CAAC,oBAAoB,CAAC;KACpF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * SandboxExecutor - Executes code in an OS-level sandbox using @anthropic-ai/sandbox-runtime
3
+ * Provides isolation for running agent-generated code safely with network and filesystem restrictions
4
+ */
5
+ import { type SandboxRuntimeConfig } from '@anthropic-ai/sandbox-runtime';
6
+ import type { ExecutionResult } from '../types/execution.js';
7
+ import { type SandboxExecutorConfig } from './config.js';
8
+ /**
9
+ * SandboxExecutor class for executing code in an isolated environment
10
+ */
11
+ export declare class SandboxExecutor {
12
+ private config;
13
+ private executorConfig;
14
+ private initialized;
15
+ private tempDir;
16
+ constructor(options?: SandboxExecutorConfig);
17
+ /**
18
+ * Initialize the sandbox manager with configured restrictions
19
+ */
20
+ initialize(): Promise<void>;
21
+ /**
22
+ * Generate the MCP helper preamble that provides the global `mcp` object
23
+ * for calling MCP tools via the HTTP bridge
24
+ */
25
+ private getMcpPreamble;
26
+ /**
27
+ * Execute TypeScript/JavaScript code in the sandbox
28
+ *
29
+ * @param code - The code to execute
30
+ * @param timeoutMs - Maximum execution time in milliseconds
31
+ * @returns ExecutionResult with output, error, and duration
32
+ */
33
+ execute(code: string, timeoutMs: number): Promise<ExecutionResult>;
34
+ /**
35
+ * Execute a command and capture its output
36
+ */
37
+ private executeCommand;
38
+ /**
39
+ * Cleanup temporary files
40
+ */
41
+ private cleanup;
42
+ /**
43
+ * Reset the sandbox manager (useful for testing)
44
+ */
45
+ reset(): Promise<void>;
46
+ /**
47
+ * Check if sandbox dependencies are available
48
+ */
49
+ checkDependencies(): boolean;
50
+ /**
51
+ * Check if sandboxing is enabled on this platform
52
+ */
53
+ isSandboxingEnabled(): boolean;
54
+ /**
55
+ * Get the current sandbox configuration
56
+ */
57
+ getConfig(): SandboxRuntimeConfig;
58
+ /**
59
+ * Update sandbox configuration (requires re-initialization)
60
+ */
61
+ updateConfig(newConfig: Partial<SandboxExecutorConfig>): void;
62
+ }
63
+ //# sourceMappingURL=executor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../src/sandbox/executor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAkB,KAAK,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAO1F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAA8B,KAAK,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAErF;;GAEG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAuB;IACrC,OAAO,CAAC,cAAc,CAAwB;IAC9C,OAAO,CAAC,WAAW,CAAkB;IACrC,OAAO,CAAC,OAAO,CAAS;gBAEZ,OAAO,GAAE,qBAA0B;IAM/C;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAkBjC;;;OAGG;IACH,OAAO,CAAC,cAAc;IA0CtB;;;;;;OAMG;IACG,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAuFxE;;OAEG;IACH,OAAO,CAAC,cAAc;IAwCtB;;OAEG;YACW,OAAO;IAYrB;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAK5B;;OAEG;IACH,iBAAiB,IAAI,OAAO;IAI5B;;OAEG;IACH,mBAAmB,IAAI,OAAO;IAI9B;;OAEG;IACH,SAAS,IAAI,oBAAoB;IAIjC;;OAEG;IACH,YAAY,CAAC,SAAS,EAAE,OAAO,CAAC,qBAAqB,CAAC,GAAG,IAAI;CAK9D"}