run-script
Execute npm scripts from package.json files by specifying the directory path and script name. Use this tool to run build, test, or custom automation scripts defined in your Node.js projects.
Instructions
Run a script defined in package.json
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Absolute path to the package directory | |
| script | No | Script name to run (omit to list available scripts) | |
| args | No | Arguments to pass to the script |
Implementation Reference
- src/index.ts:865-890 (handler)The "run-script" tool is registered and implemented directly in src/index.ts using the server.tool method. It constructs the command arguments and executes them using the 'run' helper.
server.tool( "run-script", "Run a script defined in package.json", { path: z.string().describe("Absolute path to the package directory"), script: z.string().optional().describe("Script name to run (omit to list available scripts)"), args: z.array(z.string()).optional().describe("Arguments to pass to the script"), }, async ({ path, script, args: scriptArgs }) => { const cmdArgs = script ? ["run", script] : ["run"]; if (scriptArgs && scriptArgs.length > 0) { cmdArgs.push("--"); cmdArgs.push(...scriptArgs); } if (!script) cmdArgs.push("--json"); try { const { stdout, stderr } = await run(cmdArgs, path); return { content: [{ type: "text", text: stdout + stderr }] }; } catch (e: any) { return { content: [{ type: "text", text: `Error: ${e.stdout || ""}${e.stderr || e.message}` }], isError: true, }; } }, );