Skip to main content
Glama

publish

Publish a package to the npm registry with options for dist-tag, access level, dry-run, and one-time password for two-factor authentication.

Instructions

Publish a package to the npm registry

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesAbsolute path to the package directory
tagNoDist-tag (default: latest)
accessNoAccess level for scoped packages
dryRunNoRun publish without actually publishing
otpNoOne-time password for 2FA

Implementation Reference

  • The handler function for the 'publish' tool. It builds npm publish CLI args (tag, access, dryRun, otp), executes the npm publish command via the run() helper, and returns stdout/stderr or an error.
    async ({ path, tag, access, dryRun, otp }) => {
      const args = ["publish"];
      if (tag) args.push("--tag", tag);
      if (access) args.push("--access", access);
      if (dryRun) args.push("--dry-run");
      if (otp) args.push("--otp", otp);
      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,
        };
      }
    },
  • src/index.ts:46-78 (registration)
    Registration of the 'publish' tool on the MCP server via server.tool('publish', ...). Defines the tool name, description, and Zod schema for input parameters.
    server.tool(
      "publish",
      "Publish a package to the npm registry",
      {
        path: z.string().describe("Absolute path to the package directory"),
        tag: z.string().optional().describe("Dist-tag (default: latest)"),
        access: z
          .enum(["public", "restricted"])
          .optional()
          .describe("Access level for scoped packages"),
        dryRun: z
          .boolean()
          .optional()
          .describe("Run publish without actually publishing"),
        otp: z.string().optional().describe("One-time password for 2FA"),
      },
      async ({ path, tag, access, dryRun, otp }) => {
        const args = ["publish"];
        if (tag) args.push("--tag", tag);
        if (access) args.push("--access", access);
        if (dryRun) args.push("--dry-run");
        if (otp) args.push("--otp", otp);
        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,
          };
        }
      },
    );
  • Input schema for the 'publish' tool: path (required string), tag (optional string), access (optional enum public/restricted), dryRun (optional boolean), otp (optional string).
    {
      path: z.string().describe("Absolute path to the package directory"),
      tag: z.string().optional().describe("Dist-tag (default: latest)"),
      access: z
        .enum(["public", "restricted"])
        .optional()
        .describe("Access level for scoped packages"),
      dryRun: z
        .boolean()
        .optional()
        .describe("Run publish without actually publishing"),
      otp: z.string().optional().describe("One-time password for 2FA"),
  • The run() helper function used by the publish handler. Executes npm with the given args using execFile, with a 120s timeout and 10MB buffer. Injects NPM_TOKEN via --userconfig if configured.
    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:1202-1208 (registration)
    Registration of the 'publish' tool in the sandbox server (createSandboxServer export). Uses a noop handler that always returns 'sandbox'.
    sandbox.tool("publish", "Publish a package to the npm registry", {
      path: z.string().describe("Absolute path to the package directory"),
      tag: z.string().optional().describe("Dist-tag (default: latest)"),
      access: z.enum(["public", "restricted"]).optional().describe("Access level for scoped packages"),
      dryRun: z.boolean().optional().describe("Run publish without actually publishing"),
      otp: z.string().optional().describe("One-time password for 2FA"),
    }, noop);
Behavior2/5

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

No annotations are provided, and the description fails to disclose behavioral traits like destructive action, authentication needs, or registry modifications. The single sentence offers no behavioral context beyond the verb 'publish'.

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

Conciseness3/5

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

The description is very concise (6 words) but lacks important context. It is not verbose but would benefit from more detail to be fully useful.

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 5 parameters, no output schema, and no annotations, the description is incomplete. It does not cover workflow, error states, or success conditions, leaving significant gaps for an AI agent.

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?

Schema coverage is 100% with parameter descriptions. The tool description adds no additional meaning beyond what the schema already provides, so it meets the baseline but does not enhance understanding.

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

Purpose4/5

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

The description clearly states 'Publish a package to the npm registry' with a specific verb and resource. However, it does not differentiate from sibling tools like 'unpublish' or 'pack', which have related but distinct purposes.

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 versus alternatives, nor does it mention necessary prerequisites such as authentication or package.json requirements.

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