pack
Create a tarball from a local package directory to preview files that would be published to npm. Optionally dry-run to list files without creating a tarball.
Instructions
Create a tarball from a package (preview what would be published)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Absolute path to the package directory | |
| dryRun | No | List files without creating tarball |
Implementation Reference
- src/index.ts:257-278 (handler)The `pack` tool handler function. It takes `path` (absolute path to package directory) and optional `dryRun` (boolean to list files without creating tarball). It runs `npm pack --json` via the `run()` helper and returns the JSON output.
server.tool( "pack", "Create a tarball from a package (preview what would be published)", { path: z.string().describe("Absolute path to the package directory"), dryRun: z.boolean().optional().describe("List files without creating tarball"), }, async ({ path, dryRun }) => { const args = ["pack"]; if (dryRun) args.push("--dry-run"); args.push("--json"); try { const { stdout } = await run(args, path); return { content: [{ type: "text", text: stdout }] }; } catch (e: any) { return { content: [{ type: "text", text: `Error: ${e.stderr || e.message}` }], isError: true, }; } }, ); - src/index.ts:256-278 (registration)Registration of the `pack` tool via `server.tool('pack', ...)`. Defines the tool name as 'pack' with description 'Create a tarball from a package (preview what would be published)'.
// ── npm pack ── server.tool( "pack", "Create a tarball from a package (preview what would be published)", { path: z.string().describe("Absolute path to the package directory"), dryRun: z.boolean().optional().describe("List files without creating tarball"), }, async ({ path, dryRun }) => { const args = ["pack"]; if (dryRun) args.push("--dry-run"); args.push("--json"); try { const { stdout } = await run(args, path); return { content: [{ type: "text", text: stdout }] }; } catch (e: any) { return { content: [{ type: "text", text: `Error: ${e.stderr || e.message}` }], isError: true, }; } }, ); - src/index.ts:260-263 (schema)Input schema for the `pack` tool using Zod: `path` (required string), `dryRun` (optional boolean).
{ path: z.string().describe("Absolute path to the package directory"), dryRun: z.boolean().optional().describe("List files without creating tarball"), }, - src/index.ts:26-38 (helper)The `run()` helper function that executes npm commands. Wraps `execFile` with the configured npm binary and optional .npmrc token arguments.
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:1252-1255 (registration)Sandbox registration of the `pack` tool (noop handler for testing).
sandbox.tool("pack", "Create a tarball from a package", { path: z.string().describe("Absolute path to the package directory"), dryRun: z.boolean().optional().describe("List files without creating tarball"), }, noop);