Skip to main content
Glama

install

Install npm packages in a project directory, manage dependencies with options for dev, exact versions, global installs, or preview changes.

Instructions

Install packages in a project

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesAbsolute path to the package directory
packagesNoPackage names to install (empty = install all from package.json)
saveDevNoSave as devDependency
saveExactNoSave exact version instead of semver range
globalNoInstall globally
dryRunNoPreview install without making changes

Implementation Reference

  • The implementation and registration of the 'install' tool. It defines the schema and executes the 'npm install' command using the 'run' helper function.
    server.tool(
      "install",
      "Install packages in a project",
      {
        path: z.string().describe("Absolute path to the package directory"),
        packages: z.array(z.string()).optional().describe("Package names to install (empty = install all from package.json)"),
        saveDev: z.boolean().optional().describe("Save as devDependency"),
        saveExact: z.boolean().optional().describe("Save exact version instead of semver range"),
        global: z.boolean().optional().describe("Install globally"),
        dryRun: z.boolean().optional().describe("Preview install without making changes"),
      },
      async ({ path, packages, saveDev, saveExact, global: isGlobal, dryRun }) => {
        const args = ["install"];
        if (packages && packages.length > 0) args.push(...packages);
        if (saveDev) args.push("--save-dev");
        if (saveExact) args.push("--save-exact");
        if (isGlobal) args.push("-g");
        if (dryRun) args.push("--dry-run");
        try {
          const { stdout, stderr } = await run(args, path);
          return { content: [{ type: "text", text: stdout + stderr }] };
        } catch (e: any) {
          return {
            content: [{ type: "text", text: `Error: ${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