dist-tag
List, add, or remove distribution tags for npm packages to control release channels and manage version visibility.
Instructions
Manage distribution tags
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| action | Yes | Action to perform | |
| package | Yes | Package name (for add: pkg@version) | |
| tag | No | Tag name (required for add/rm) |
Implementation Reference
- src/index.ts:233-254 (registration)Both the registration (using server.tool) and the handler (the async callback) for the 'dist-tag' tool are defined here. The registration uses server.tool with name 'dist-tag', description 'Manage distribution tags', and a schema with action (ls/add/rm), package, and tag fields. The handler executes 'npm dist-tag <action> <package> [tag]' via the run helper.
server.tool( "dist-tag", "Manage distribution tags", { action: z.enum(["ls", "add", "rm"]).describe("Action to perform"), package: z.string().describe("Package name (for add: pkg@version)"), tag: z.string().optional().describe("Tag name (required for add/rm)"), }, async ({ action, package: pkg, tag }) => { const args = ["dist-tag", action, pkg]; if (tag && (action === "add" || action === "rm")) args.push(tag); try { const { stdout } = await run(args); return { content: [{ type: "text", text: stdout }] }; } catch (e: any) { return { content: [{ type: "text", text: `Error: ${e.stderr || e.message}` }], isError: true, }; } }, ); - src/index.ts:236-240 (schema)Input schema for the dist-tag tool, defining action (enum: ls/add/rm), package (string), and optional tag (string) using Zod validations.
{ action: z.enum(["ls", "add", "rm"]).describe("Action to perform"), package: z.string().describe("Package name (for add: pkg@version)"), tag: z.string().optional().describe("Tag name (required for add/rm)"), }, - src/index.ts:26-43 (helper)The run helper function that executes npm commands (used by the dist-tag handler). It merges npmrcArgs for authentication and calls child_process.execFile with the npm binary.
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); } const server = new McpServer({ name: "npm-mcp", version: "1.2.0", });