Skip to main content
Glama

run-script

Run any npm script from your package.json. Specify the package directory, choose a script, and pass arguments. Omit script name to view available scripts.

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 handler function for the run-script tool. It builds npm run arguments (optionally with a script name and extra args), appends --json if listing scripts, executes via the `run` helper, and returns the output or an error.
      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,
          };
        }
      },
    );
  • Input schema for run-script: path (required), script (optional), and args (optional array of strings).
    {
      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"),
    },
  • src/index.ts:865-890 (registration)
    Registration of the run-script tool via server.tool() on the MCP server instance.
    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,
          };
        }
      },
    );
  • The `run` helper function that executes npm commands via child_process.execFile with timeout, maxBuffer, and environment settings.
    async function run(
      args: string[],
      cwd?: string,
    ): Promise<{ stdout: string; stderr: string }> {
      const fullArgs = [...args, ...npmrcArgs];
      const opts: { cwd?: string; timeout: number; env: NodeJS.ProcessEnv; maxBuffer: number } = {
        timeout: 120_000,
        maxBuffer: 10 * 1024 * 1024, // 10MB buffer for large outputs
        env: { ...process.env, NO_COLOR: "1" },
      };
      if (cwd) opts.cwd = cwd;
      return exec(NPM, fullArgs, opts);
    }
  • src/index.ts:1383-1387 (registration)
    Sandbox registration of run-script tool (noop handler for sandbox mode).
    sandbox.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"),
      args: z.array(z.string()).optional().describe("Arguments to pass to the script"),
    }, noop);
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries full burden for behavioral disclosure. It only states it runs a script but does not describe side effects, execution context, permission requirements, or whether it is synchronous. This is insufficient for a tool that executes code.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, concise sentence. It is front-loaded and efficient, but could include more critical information without being overly verbose.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The tool has 3 parameters and no output schema, yet the description is minimal. It does not explain the return value (e.g., exit code, output), error handling, or behavior when the script fails. More context is needed for safe usage.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, so the description does not need to add much. It mentions 'script defined in package.json' which aligns with the schema but adds no new meaning beyond the parameter descriptions.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: to run a script defined in package.json. The verb 'run' and resource 'script defined in package.json' are specific, and it distinguishes itself from sibling npm commands like install or publish.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool over alternatives (e.g., npm run). It does not mention when to list scripts vs. run one, nor does it explain prerequisites or limitations.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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