publish
Publish packages to the npm registry with options for access control, distribution tags, and dry-run verification.
Instructions
Publish a package to the npm registry
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Absolute path to the package directory | |
| tag | No | Dist-tag (default: latest) | |
| access | No | Access level for scoped packages | |
| dryRun | No | Run publish without actually publishing | |
| otp | No | One-time password for 2FA |
Implementation Reference
- src/index.ts:46-78 (handler)The registration and handler logic for the 'publish' MCP tool, which executes `npm publish` via the `run` helper function.
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, }; } }, );