run-js-code
Execute JavaScript code securely in a sandbox environment, with options for NPM commands, JSON parsing, and configurable timeouts. Ideal for testing and automation tasks on the Dumpling AI MCP Server.
Instructions
Execute JavaScript code in a sandbox.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | JavaScript code | |
| commands | No | NPM install commands | |
| memory | No | Memory allocation in MB | |
| parseJson | No | Parse output as JSON | |
| timeout | No | Execution timeout in ms |
Implementation Reference
- src/index.ts:999-1014 (handler)The main handler function for the "run-js-code" tool. It retrieves the API key, makes a POST request to the external Dumpling API endpoint for executing JS code in a sandbox, handles errors, and returns the response as MCP content.async ({ code, commands, parseJson, timeout, memory }) => { const apiKey = process.env.DUMPLING_API_KEY; if (!apiKey) throw new Error("DUMPLING_API_KEY not set"); const response = await fetch(`${NWS_API_BASE}/api/v1/run-js-code`, { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${apiKey}`, }, body: JSON.stringify({ code, commands, parseJson, timeout, memory }), }); if (!response.ok) throw new Error(`Failed: ${response.status} ${await response.text()}`); const data = await response.json(); return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] }; }
- src/index.ts:992-998 (schema)Zod schema defining the input parameters for the "run-js-code" tool.{ code: z.string().describe("JavaScript code"), commands: z.string().optional().describe("NPM install commands"), parseJson: z.boolean().optional().describe("Parse output as JSON"), timeout: z.number().optional().describe("Execution timeout in ms"), memory: z.number().optional().describe("Memory allocation in MB"), },
- src/index.ts:989-1015 (registration)Registration of the "run-js-code" tool using server.tool(), specifying name, description, input schema, and handler function.server.tool( "run-js-code", "Execute JavaScript code in a sandbox.", { code: z.string().describe("JavaScript code"), commands: z.string().optional().describe("NPM install commands"), parseJson: z.boolean().optional().describe("Parse output as JSON"), timeout: z.number().optional().describe("Execution timeout in ms"), memory: z.number().optional().describe("Memory allocation in MB"), }, async ({ code, commands, parseJson, timeout, memory }) => { const apiKey = process.env.DUMPLING_API_KEY; if (!apiKey) throw new Error("DUMPLING_API_KEY not set"); const response = await fetch(`${NWS_API_BASE}/api/v1/run-js-code`, { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${apiKey}`, }, body: JSON.stringify({ code, commands, parseJson, timeout, memory }), }); if (!response.ok) throw new Error(`Failed: ${response.status} ${await response.text()}`); const data = await response.json(); return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] }; } );