token
Manage npm access tokens to list existing tokens or revoke specific ones for security control.
Instructions
Manage npm access tokens (list or revoke)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| action | Yes | Action to perform | |
| token | No | Token ID to revoke (required for revoke) | |
| otp | No | One-time password for 2FA |
Implementation Reference
- src/index.ts:545-577 (handler)The tool named 'token' is implemented in src/index.ts. It handles 'list' and 'revoke' actions by running 'npm token ...' via the 'run' helper function.
server.tool( "token", "Manage npm access tokens (list or revoke)", { action: z.enum(["list", "revoke"]).describe("Action to perform"), token: z.string().optional().describe("Token ID to revoke (required for revoke)"), otp: z.string().optional().describe("One-time password for 2FA"), }, async ({ action, token, otp }) => { const args = ["token"]; if (action === "list") { args.push("list", "--json"); } else if (action === "revoke") { if (!token) { return { content: [{ type: "text", text: "Error: token ID is required for revoke action" }], isError: true, }; } args.push("revoke", token); } if (otp) args.push("--otp", otp); try { const { stdout, stderr } = await run(args); return { content: [{ type: "text", text: stdout + stderr || "Done" }] }; } catch (e: any) { return { content: [{ type: "text", text: `Error: ${e.stderr || e.message}` }], isError: true, }; } }, );