Skip to main content
Glama

pkg

Programmatically manage package.json fields to get, set, or delete values like scripts, dependencies, and metadata for npm package configuration.

Instructions

Manage package.json fields programmatically

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesAbsolute path to the package directory
actionYesAction to perform
fieldYesField name (e.g. 'name', 'scripts.build', 'keywords')
valueNoValue to set (required for set action, use JSON for objects/arrays)

Implementation Reference

  • The handler implementation for the "pkg" tool. It calls 'npm pkg' with arguments derived from the tool input.
    server.tool(
      "pkg",
      "Manage package.json fields programmatically",
      {
        path: z.string().describe("Absolute path to the package directory"),
        action: z.enum(["get", "set", "delete"]).describe("Action to perform"),
        field: z.string().describe("Field name (e.g. 'name', 'scripts.build', 'keywords')"),
        value: z.string().optional().describe("Value to set (required for set action, use JSON for objects/arrays)"),
      },
      async ({ path, action, field, value }) => {
        const args = ["pkg", action, field];
        if (action === "set" && value !== undefined) {
          args.push(value);
        }
        args.push("--json");
        try {
          const { stdout, stderr } = await run(args, path);
          return { content: [{ type: "text", text: stdout + stderr || "Done" }] };
        } 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