owner
List, add, or remove owners for an npm package. Requires package name and optional OTP for 2FA.
Instructions
Manage package owners
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| action | Yes | Action to perform | |
| package | Yes | Package name | |
| user | No | Username (required for add/rm) | |
| otp | No | One-time password for 2FA |
Implementation Reference
- src/index.ts:216-230 (handler)The handler function for the 'owner' tool. Builds npm owner arguments (ls/add/rm with optional user and otp), executes via run(), and returns stdout or an error.
async ({ action, package: pkg, user, otp }) => { const args = ["owner", action, pkg]; if (user && (action === "add" || action === "rm")) args.push(user); if (otp) args.push("--otp", otp); 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:210-215 (schema)Zod schema defining the input parameters for the 'owner' tool: action (enum ls/add/rm), package (string), optional user (string), and optional otp (string).
{ action: z.enum(["ls", "add", "rm"]).describe("Action to perform"), package: z.string().describe("Package name"), user: z.string().optional().describe("Username (required for add/rm)"), otp: z.string().optional().describe("One-time password for 2FA"), }, - src/index.ts:207-230 (registration)Registration of the 'owner' tool on the MCP server using server.tool() with its name, description, schema, and handler.
server.tool( "owner", "Manage package owners", { action: z.enum(["ls", "add", "rm"]).describe("Action to perform"), package: z.string().describe("Package name"), user: z.string().optional().describe("Username (required for add/rm)"), otp: z.string().optional().describe("One-time password for 2FA"), }, async ({ action, package: pkg, user, otp }) => { const args = ["owner", action, pkg]; if (user && (action === "add" || action === "rm")) args.push(user); if (otp) args.push("--otp", otp); 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:1239-1244 (registration)Second registration of the 'owner' tool within a sandbox context (sandbox.tool()), using a noop handler for documentation/schema purposes.
sandbox.tool("owner", "Manage package owners", { action: z.enum(["ls", "add", "rm"]).describe("Action to perform"), package: z.string().describe("Package name"), user: z.string().optional().describe("Username"), otp: z.string().optional().describe("One-time password for 2FA"), }, noop); - src/index.ts:26-38 (helper)The run() helper function that executes npm commands via execFile, used by the owner 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); }