Skip to main content
Glama

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
NameRequiredDescriptionDefault
pathYesAbsolute path to the package directory
scriptNoScript name to run (omit to list available scripts)
argsNoArguments to pass to the script

Implementation Reference

  • 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,
          };
        }
      },
    );

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mikusnuz/npm-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server