Skip to main content
Glama

pkg

Read, update, or delete package.json fields such as name, scripts, and keywords using get, set, and delete actions. Specify field paths and values to manage project configuration programmatically.

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

  • src/index.ts:691-717 (registration)
    Registration of the 'pkg' tool via server.tool() on the McpServer instance
    // ── npm pkg ──
    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,
          };
        }
      },
    );
  • Zod schema definitions for the 'pkg' tool inputs: path (string), action (enum: get/set/delete), field (string), value (optional string)
    {
      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)"),
    },
  • Handler function for the 'pkg' tool - runs npm pkg command with action, field, and optional value to manage package.json fields programmatically
      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,
          };
        }
      },
    );
  • The run() helper function that executes npm commands via child_process execFile, used by the pkg tool handler
    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:1344-1349 (registration)
    Sandbox registration of the 'pkg' tool (noop implementation) in createSandboxServer()
    sandbox.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"),
      value: z.string().optional().describe("Value to set"),
    }, noop);
Behavior2/5

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

With no annotations, the description should disclose behavioral details like side effects (e.g., file modification), error handling, or persistence. It simply states 'manage', which implies mutation but lacks specifics on what happens during get/set/delete operations.

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 sentence, front-loaded with the core purpose. It achieves conciseness, but could be slightly more structured (e.g., adding use examples) without losing brevity.

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?

Given the lack of annotations and output schema, the description is too minimal. It does not explain return values (e.g., what 'get' returns), error behavior, or side effects. For a general-purpose tool with multiple actions, this is incomplete.

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 covers all parameters with descriptions (100% coverage), so the schema already conveys meaning. The description adds no extra semantic value beyond the schema, meeting the baseline score of 3.

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 'Manage package.json fields programmatically' clearly states the tool's purpose: it operates on package.json files. This verb+resource combination is specific and distinguishes it from sibling tools like install, publish, etc., which handle different aspects of package management.

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?

No guidance is provided on when to use this tool versus alternatives. The description does not mention scenarios where editing package.json directly is preferred over using npm commands, nor does it indicate prerequisites or exclusions.

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