@yawlabs/npmjs-mcp 0.7.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +241 -127
  2. package/dist/index.js +164 -111
  3. package/package.json +5 -1
package/README.md CHANGED
@@ -1,29 +1,42 @@
1
1
  # @yawlabs/npmjs-mcp
2
2
 
3
- MCP server for the [npm](https://www.npmjs.com) registry. Package intelligence, security audits, dependency analysis, and org management from any MCP-compatible AI assistant.
3
+ [![npm version](https://img.shields.io/npm/v/@yawlabs/npmjs-mcp)](https://www.npmjs.com/package/@yawlabs/npmjs-mcp)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
5
+ [![GitHub stars](https://img.shields.io/github/stars/YawLabs/npmjs-mcp)](https://github.com/YawLabs/npmjs-mcp/stargazers)
6
+ [![CI](https://github.com/YawLabs/npmjs-mcp/actions/workflows/ci.yml/badge.svg)](https://github.com/YawLabs/npmjs-mcp/actions/workflows/ci.yml) [![Release](https://github.com/YawLabs/npmjs-mcp/actions/workflows/release.yml/badge.svg)](https://github.com/YawLabs/npmjs-mcp/actions/workflows/release.yml)
4
7
 
5
- ## Quick start
8
+ **Run npm registry operations from Claude Code, Cursor, and any MCP client.** 63 tools covering the full registry surface: package intelligence, security audits, dependency analysis, org/team management, and the write ops that normally fight you locally (`npm deprecate`, `npm dist-tag`, `npm owner`, `npm unpublish`).
6
9
 
7
- ```bash
8
- npx @yawlabs/npmjs-mcp
9
- ```
10
+ Built and maintained by [Yaw Labs](https://yaw.sh).
10
11
 
11
- ## Setup
12
+ [![Add to mcp.hosting](https://mcp.hosting/install-button.svg)](https://mcp.hosting/install?name=npm&command=npx&args=-y%2C%40yawlabs%2Fnpmjs-mcp&env=NPM_TOKEN&description=npm%20registry%20-%20package%20intel%2C%20security%2C%20dependency%20analysis%2C%20write%20ops&source=https%3A%2F%2Fgithub.com%2FYawLabs%2Fnpmjs-mcp)
12
13
 
13
- No API key is required for read-only tools (search, packages, downloads, security, analysis). For authenticated tools (auth, access, orgs, hooks), set your npm token:
14
+ One click adds this to your [mcp.hosting](https://mcp.hosting) account so it syncs to every MCP client you use. Or install manually below.
14
15
 
15
- ```bash
16
- export NPM_TOKEN="your-token"
17
- ```
16
+ ## Why this one?
17
+
18
+ Other npm MCP servers wrap `npm search` and call it done. This one doesn't.
18
19
 
19
- ### Claude Code
20
+ - **Full registry HTTP surface** — 63 tools across reads, writes, orgs, teams, hooks, provenance, trusted publishers, and ops health. Not just `npm view`.
21
+ - **Write ops that actually work in agents** — `npm_deprecate`, `npm_dist_tag_set`, `npm_owner_add`, `npm_unpublish_version` go directly to the HTTP API with your token. No 2FA prompts, no `--otp` hunts, no `ENEEDAUTH` from a session-bound `.npmrc`.
22
+ - **Agent-aware failure surfacing** — write tools detect non-interactive context and return specific human-runnable commands (`npm login --auth-type=web`) instead of looping on unrecoverable errors.
23
+ - **Safety by default** — `npm_unpublish_*` requires `confirm: true`. `npm_owner_remove` blocks you from locking yourself out. `npm_deprecate` validates the message format (em-dash, no trailing period) that npmjs.com's API actually accepts.
24
+ - **Ops playbook built in** — `npm_ops_playbook` returns the canonical tool-vs-CLI-vs-CI decision matrix so your agent picks the right path on the first try.
25
+ - **Tool annotations** — every tool declares `readOnlyHint`, `destructiveHint`, `idempotentHint`, and `openWorldHint`, so MCP clients can skip confirmation on safe ops.
26
+ - **No API key required for reads** — search, packages, downloads, security, dep tree, licenses all work anonymously. Auth is opt-in via `NPM_TOKEN`.
27
+ - **Instant startup** — ships as a single bundled file with zero runtime dependencies. No 5-minute `node_modules` install.
28
+ - **Input hardening** — package names, scopes, versions, dist-tags, and team names are all regex-validated against npm's actual constraints. Defends against CRLF and path-traversal in URL construction.
29
+
30
+ ## Quick start
20
31
 
21
- Add to your MCP config:
32
+ **1. Create `.mcp.json` in your project root**
33
+
34
+ macOS / Linux / WSL:
22
35
 
23
36
  ```json
24
37
  {
25
38
  "mcpServers": {
26
- "npmjs": {
39
+ "npm": {
27
40
  "command": "npx",
28
41
  "args": ["-y", "@yawlabs/npmjs-mcp"]
29
42
  }
@@ -31,153 +44,254 @@ Add to your MCP config:
31
44
  }
32
45
  ```
33
46
 
34
- With authentication:
47
+ Windows:
35
48
 
36
49
  ```json
37
50
  {
38
51
  "mcpServers": {
39
- "npmjs": {
40
- "command": "npx",
41
- "args": ["-y", "@yawlabs/npmjs-mcp"],
42
- "env": {
43
- "NPM_TOKEN": "your-token"
44
- }
52
+ "npm": {
53
+ "command": "cmd",
54
+ "args": ["/c", "npx", "-y", "@yawlabs/npmjs-mcp"]
45
55
  }
46
56
  }
47
57
  }
48
58
  ```
49
59
 
50
- ### Claude Desktop
60
+ > **Why the extra step on Windows?** Since Node 20, `child_process.spawn` cannot directly execute `.cmd` files (that's what `npx` is on Windows). Wrapping with `cmd /c` is the standard workaround.
61
+
62
+ **2. Restart and approve**
63
+
64
+ Restart Claude Code (or your MCP client) and approve the npm MCP server when prompted.
51
65
 
52
- Add to `claude_desktop_config.json`:
66
+ **3. (Optional) Add your npm token for write operations**
67
+
68
+ Read-only tools work without any setup. For write tools (`deprecate`, `dist-tag`, `owner`, `team_*`, `org_member_*`, `unpublish`, `hook_*`, `access_set*`, `token_revoke`), add `NPM_TOKEN` to the `env` block:
53
69
 
54
70
  ```json
55
71
  {
56
72
  "mcpServers": {
57
- "npmjs": {
73
+ "npm": {
58
74
  "command": "npx",
59
75
  "args": ["-y", "@yawlabs/npmjs-mcp"],
60
76
  "env": {
61
- "NPM_TOKEN": "your-token"
77
+ "NPM_TOKEN": "npm_xxxxxxxxxxxx"
62
78
  }
63
79
  }
64
80
  }
65
81
  }
66
82
  ```
67
83
 
84
+ Use a [Granular Access Token](https://docs.npmjs.com/creating-and-viewing-access-tokens#creating-granular-access-tokens) scoped to just the packages and orgs you want your agent to manage.
85
+
86
+ That's it. Now ask your AI assistant:
87
+
88
+ > "Deprecate my-old-pkg 1.x with a pointer to v2"
89
+ >
90
+ > "What's the dep tree for fastify look like three levels deep?"
91
+ >
92
+ > "Audit express for known CVEs and tell me the fix"
93
+ >
94
+ > "Who are the maintainers of next.js and when did each one last publish?"
95
+
96
+ ## Configuration
97
+
98
+ | Environment variable | Default | Description |
99
+ |---|---|---|
100
+ | `NPM_TOKEN` | (none) | npm access token. Required only for write/auth/org/access/hooks tools. A Granular Access Token is strongly preferred over a Classic Automation token. |
101
+ | `NPM_REGISTRY` | `https://registry.npmjs.org` | Alternate registry (enterprise/private). Must support the npm HTTP API shape. |
102
+
103
+ **Alternate MCP clients:**
104
+
105
+ | Client | Config file |
106
+ |---|---|
107
+ | Claude Code | `.mcp.json` (project root) or `~/.claude.json` (global) |
108
+ | Claude Desktop | `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) |
109
+ | Cursor | `~/.cursor/mcp.json` |
110
+ | Windsurf | `~/.codeium/windsurf/mcp_config.json` |
111
+ | VS Code | `.vscode/mcp.json` |
112
+
113
+ Use the same JSON block shown above in any of these.
114
+
68
115
  ## Tools (63)
69
116
 
70
- ### Search
71
- - `npm_search` — Search the npm registry with qualifiers (keywords, author, scope)
72
-
73
- ### Packages
74
- - `npm_package`Get package metadata (description, dist-tags, maintainers, license)
75
- - `npm_version`Get detailed metadata for a specific version
76
- - `npm_versions`List all published versions with dates
77
- - `npm_readme`Get README content
78
- - `npm_dist_tags`Get dist-tags (latest, next, beta, etc)
79
- - `npm_types`Check TypeScript type support (built-in types or @types/*)
80
-
81
- ### Dependencies
82
- - `npm_dependencies`Get dependency lists (prod, dev, peer, optional)
83
- - `npm_dep_tree`Resolve transitive dependency tree (configurable depth)
84
- - `npm_license_check`Check licenses of a package and its direct deps
85
-
86
- ### Downloads
87
- - `npm_downloads`Get total download count for a period
88
- - `npm_downloads_range`Get daily download breakdown
89
- - `npm_downloads_bulk` — Compare downloads for up to 128 packages
90
- - `npm_version_downloads` — Per-version download counts
91
-
92
- ### Security
93
- - `npm_audit` — Check packages for known vulnerabilities
94
- - `npm_audit_deep` — Full audit with CVSS scores, CWEs, fix recommendations
95
- - `npm_signing_keys`Get registry ECDSA signing keys
96
-
97
- ### Analysis
98
- - `npm_compare` — Compare 2-5 packages side-by-side
99
- - `npm_health`Assess maintenance, downloads, security, deprecation status
100
- - `npm_maintainers`Get maintainers and their publish history
101
- - `npm_release_frequency`Analyze release cadence and gaps
102
-
103
- ### Registry
104
- - `npm_registry_stats` — Total npm-wide download counts
105
- - `npm_recent_changes` — Recent package publishes from the CouchDB changes feed
106
- - `npm_ops_playbook` — Canonical recipes for npm operations (call this FIRST when unsure which tool to use)
107
-
108
- ### Provenance
109
- - `npm_provenance`Get Sigstore provenance attestations (SLSA, publish)
110
-
111
- ### Trusted Publishers (requires NPM_TOKEN)
112
- - `npm_trusted_publishers` List OIDC trust relationships with CI/CD providers
113
-
114
- ### Auth (requires NPM_TOKEN)
115
- - `npm_whoami`Check authenticated user
116
- - `npm_profile`Get profile, email, 2FA status
117
- - `npm_tokens`List access tokens
118
- - `npm_verify_token` — One-call capability check (call this FIRST when debugging write failures)
119
- - `npm_user_packages` List packages published by a user
120
-
121
- ### Access (requires NPM_TOKEN)
122
- - `npm_collaborators`List package collaborators and permissions
123
- - `npm_package_access`Get package access settings
124
-
125
- ### Organizations (requires NPM_TOKEN)
126
- - `npm_org_members` — List org members and roles
127
- - `npm_org_packages` — List org packages
128
- - `npm_org_teams`List org teams
129
- - `npm_team_packages`List team package permissions
130
-
131
- ### Workflows
132
- - `npm_check_auth` — Auth health check with headless publish feasibility
133
- - `npm_publish_preflight` Pre-publish validation checklist
134
-
135
- ### Write Operations (requires NPM_TOKEN with write scope)
136
-
137
- These bypass the CLI/2FA friction that causes `npm deprecate` and similar commands to 422 locally. All use the HTTP API with your `NPM_TOKEN`.
138
-
139
- - `npm_deprecate`Deprecate a package or specific versions (validates message format)
140
- - `npm_undeprecate`Clear deprecation
141
- - `npm_unpublish_version`Unpublish a specific version (requires `confirm: true`)
142
- - `npm_unpublish_package`Unpublish an entire package (requires `confirm: true`)
143
- - `npm_dist_tag_set`Point a dist-tag at a version
144
- - `npm_dist_tag_remove`Remove a dist-tag (except `latest`)
145
- - `npm_owner_add`Add a maintainer (resolves user via `/-/user/`)
146
- - `npm_owner_remove`Remove a maintainer (prevents lockout)
147
- - `npm_access_set`Set public/private/restricted access
148
- - `npm_access_set_mfa`Configure 2FA requirement for publish (none/publish/automation)
149
- - `npm_team_grant` / `npm_team_revoke` Grant/revoke team permissions on a package
150
- - `npm_team_create` / `npm_team_delete` — Create/delete a team in an org
151
- - `npm_team_member_add` / `npm_team_member_remove` — Manage team members
152
- - `npm_org_member_set` / `npm_org_member_remove` Add/remove org members, set roles
153
- - `npm_token_revoke`Revoke an access token by key (creation requires a password and isn't exposed)
154
-
155
- ### Webhooks (requires NPM_TOKEN)
156
- - `npm_hook_add`Register a webhook on a package, scope, or user
157
- - `npm_hook_list` — List webhooks (optional package filter)
158
- - `npm_hook_get` Fetch a single webhook
159
- - `npm_hook_update` — Update endpoint/secret of a webhook
160
- - `npm_hook_remove` — Delete a webhook
161
-
162
- ### Operation Decision Matrix
117
+ ### Search (1)
118
+ - **npm_search** — Search the npm registry with qualifiers (keywords, author, scope).
119
+
120
+ ### Packages (6)
121
+ - **npm_package**Metadata: description, dist-tags, maintainers, license, repository.
122
+ - **npm_version**Detailed metadata for a specific version.
123
+ - **npm_versions**All published versions with dates.
124
+ - **npm_readme** — README content.
125
+ - **npm_dist_tags**Dist-tags (latest, next, beta, etc).
126
+ - **npm_types** — TypeScript type support (built-in types or `@types/*`).
127
+
128
+ ### Dependencies (3)
129
+ - **npm_dependencies**Dependency lists (prod, dev, peer, optional).
130
+ - **npm_dep_tree**Transitive dependency tree (configurable depth).
131
+ - **npm_license_check**License audit of a package and its direct deps.
132
+
133
+ ### Downloads (4)
134
+ - **npm_downloads**Total download count for a period.
135
+ - **npm_downloads_range**Daily download breakdown.
136
+ - **npm_downloads_bulk** — Compare downloads for up to 128 packages.
137
+ - **npm_version_downloads** — Per-version download counts.
138
+
139
+ ### Security (3)
140
+ - **npm_audit** — Check packages for known vulnerabilities.
141
+ - **npm_audit_deep** — Full audit with CVSS scores, CWEs, fix recommendations.
142
+ - **npm_signing_keys**Registry ECDSA signing keys.
143
+
144
+ ### Analysis (4)
145
+ - **npm_compare** — Compare 25 packages side-by-side.
146
+ - **npm_health**Maintenance, downloads, security, deprecation summary.
147
+ - **npm_maintainers**Maintainers and publish history.
148
+ - **npm_release_frequency**Release cadence and gaps.
149
+
150
+ ### Registry (3)
151
+ - **npm_registry_stats** — Total npm-wide download counts.
152
+ - **npm_recent_changes** — Recent publishes from the CouchDB changes feed.
153
+ - **npm_ops_playbook** — Canonical recipes for npm operations. **Call this first** when unsure which tool to use.
154
+
155
+ ### Provenance & trust (2)
156
+ - **npm_provenance** — Sigstore attestations (SLSA, publish).
157
+ - **npm_trusted_publishers** — OIDC trust relationships with CI/CD providers.
158
+
159
+ ### Auth (5, requires NPM_TOKEN)
160
+ - **npm_whoami** — Authenticated user.
161
+ - **npm_profile** Profile, email, 2FA status.
162
+ - **npm_tokens**List access tokens.
163
+ - **npm_verify_token**One-call capability check. **Call this first** when debugging write failures.
164
+ - **npm_user_packages**Packages published by a user.
165
+
166
+ ### Access & orgs (6, requires NPM_TOKEN)
167
+ - **npm_collaborators** — Package collaborators and permissions.
168
+ - **npm_package_access** Package access settings.
169
+ - **npm_org_members**Org members and roles.
170
+ - **npm_org_packages**Org packages.
171
+ - **npm_org_teams** — Org teams.
172
+ - **npm_team_packages** Team package permissions.
173
+
174
+ ### Workflows (2)
175
+ - **npm_check_auth**Auth health check with headless publish feasibility.
176
+ - **npm_publish_preflight**Pre-publish validation checklist.
177
+
178
+ ### Write operations (19, requires NPM_TOKEN with write scope)
179
+
180
+ These bypass the CLI/2FA friction that makes `npm deprecate` and friends fail locally. All use the HTTP API with your `NPM_TOKEN`.
181
+
182
+ - **npm_deprecate** Deprecate a package or specific versions (validates message format).
183
+ - **npm_undeprecate** — Clear deprecation.
184
+ - **npm_unpublish_version** Unpublish a version. Requires `confirm: true`.
185
+ - **npm_unpublish_package** — Unpublish an entire package. Requires `confirm: true`.
186
+ - **npm_dist_tag_set**Point a dist-tag at a version.
187
+ - **npm_dist_tag_remove**Remove a dist-tag (refuses `latest`).
188
+ - **npm_owner_add**Add a maintainer (resolves user via `/-/user/`).
189
+ - **npm_owner_remove**Remove a maintainer (prevents self-lockout).
190
+ - **npm_access_set**Set public/private/restricted access.
191
+ - **npm_access_set_mfa**Configure 2FA requirement (none/publish/automation).
192
+ - **npm_team_grant** / **npm_team_revoke** Grant/revoke team permissions on a package.
193
+ - **npm_team_create** / **npm_team_delete** Create/delete a team in an org.
194
+ - **npm_team_member_add** / **npm_team_member_remove** Manage team members.
195
+ - **npm_org_member_set** / **npm_org_member_remove** Manage org membership and roles.
196
+ - **npm_token_revoke**Revoke an access token by key.
197
+
198
+ ### Webhooks (5, requires NPM_TOKEN)
199
+ - **npm_hook_add** Register a webhook on a package, scope, or user.
200
+ - **npm_hook_list**List webhooks (optional package filter).
201
+ - **npm_hook_get** — Fetch a single webhook.
202
+ - **npm_hook_update** Update endpoint/secret.
203
+ - **npm_hook_remove**Delete a webhook.
204
+
205
+ ## Operation decision matrix
163
206
 
164
207
  | Operation | Preferred path | Why |
165
208
  |---|---|---|
166
- | Read (search/view/stats) | These MCP tools, no auth required | Fast, zero friction |
167
- | Deprecate / dist-tag / owner | `npm_deprecate`, `npm_dist_tag_*`, `npm_owner_*` | HTTP API, no CLI auth issues |
209
+ | Read (search/view/stats) | These MCP tools, no auth | Fast, zero friction |
210
+ | Deprecate / dist-tag / owner / team / hook | `npm_deprecate`, `npm_dist_tag_*`, etc. | HTTP API, no CLI 2FA friction |
168
211
  | Publish | CI tag-push workflow | Version discipline, provenance, org token |
169
212
  | Unpublish | `npm_unpublish_version` (with `confirm: true`) | Safer than CLI; irreversible within 72h |
170
- | CLI fallback (only if MCP returns 422) | `npm login --auth-type=web` then `npm <op>` | End-user interactive path |
213
+ | CLI fallback (rare) | `npm login --auth-type=web` then `npm <op>` | Only if MCP returns 422 |
214
+
215
+ Call `npm_ops_playbook` at the start of any session to get the up-to-date matrix.
216
+
217
+ ## Examples
218
+
219
+ ### Audit a dependency
220
+
221
+ ```
222
+ > "What vulnerabilities does lodash 4.17.20 have and what's the fix?"
223
+ → npm_audit_deep({ name: "lodash", version: "4.17.20" })
224
+ ```
225
+
226
+ ### Deprecate a package
227
+
228
+ ```
229
+ > "Deprecate @myorg/legacy-sdk with a pointer to @myorg/sdk"
230
+ → npm_deprecate({ name: "@myorg/legacy-sdk", message: "Renamed to @myorg/sdk — install that instead" })
231
+ ```
232
+
233
+ ### Compare package health
234
+
235
+ ```
236
+ > "Compare fastify vs express vs koa for maintenance health"
237
+ → npm_compare({ names: ["fastify", "express", "koa"] })
238
+ → npm_health({ name: "fastify" }) // ...etc
239
+ ```
240
+
241
+ ### Rotate a dist-tag
242
+
243
+ ```
244
+ > "Point @myorg/pkg@latest at 3.2.1"
245
+ → npm_dist_tag_set({ name: "@myorg/pkg", tag: "latest", version: "3.2.1" })
246
+ ```
247
+
248
+ ### Debug a write failure
249
+
250
+ ```
251
+ > "My deprecate keeps returning 422 — what's wrong?"
252
+ → npm_verify_token() // Confirms token scope, packages, 2FA state
253
+ → npm_ops_playbook() // Returns the canonical retry sequence
254
+ ```
255
+
256
+ ## Troubleshooting
257
+
258
+ **"Error: NPM_TOKEN is required"**
259
+
260
+ - The tool you called needs auth. Add `NPM_TOKEN` to the `env` block of your MCP config and restart the client.
261
+ - Prefer a [Granular Access Token](https://docs.npmjs.com/creating-and-viewing-access-tokens#creating-granular-access-tokens) scoped to just the packages and orgs you want touched.
262
+
263
+ **"HTTP 401 Unauthorized" or "HTTP 403 Forbidden"**
264
+
265
+ - Your token lacks scope on the target package. Call `npm_verify_token` — it reports which packages and orgs the token can actually write.
266
+ - If the package requires 2FA for writes, your token must be an automation token or come from an OIDC trusted publisher. A user token will 403.
267
+
268
+ **"HTTP 422 Unprocessable" on deprecate**
171
269
 
172
- Call `npm_ops_playbook` at the start of any session for the up-to-date matrix.
270
+ - Common cause: message format. Use an em-dash and no trailing period: `"Renamed to @x/y install that instead"`, not `"Renamed to @x/y. Install that instead."`
271
+ - Another: specifying a `versions` range that doesn't match any published version. Call `npm_versions` to confirm.
173
272
 
174
- ## Features
273
+ **Windows: MCP server doesn't start**
274
+
275
+ - Use the `cmd /c npx ...` pattern from the Quick start section. Node 20+ can't spawn `.cmd` files directly.
276
+
277
+ ## Requirements
278
+
279
+ - Node.js 18+
280
+ - (Optional) npm access token for write operations
281
+
282
+ ## Contributing
283
+
284
+ ```bash
285
+ git clone https://github.com/YawLabs/npmjs-mcp.git
286
+ cd npmjs-mcp
287
+ npm install
288
+ npm run lint # Biome check
289
+ npm run lint:fix # Auto-fix
290
+ npm run build # tsc + esbuild bundle
291
+ npm test # node --test
292
+ ```
175
293
 
176
- - **63 tools** covering search, packages, deps, downloads, security, analysis, auth, orgs, access, provenance, trust, publish workflows, write operations, and registry webhooks
177
- - **No API key required** for read-only tools — authenticated tools opt-in via NPM_TOKEN
178
- - **Zero runtime dependencies** — Single bundled file for instant `npx` startup
179
- - **Agent-aware publish tools** — Detects non-interactive context, provides human hand-off actions instead of unworkable retries
180
- - **MCP annotations** — Every tool declares read-only, destructive, and idempotent hints
294
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for the full workflow, including release process.
181
295
 
182
296
  ## License
183
297
 
package/dist/index.js CHANGED
@@ -21015,8 +21015,21 @@ var REGISTRY_URL = "https://registry.npmjs.org";
21015
21015
  var DOWNLOADS_URL = "https://api.npmjs.org";
21016
21016
  var REPLICATE_URL = "https://replicate.npmjs.com";
21017
21017
  var REQUEST_TIMEOUT_MS = 3e4;
21018
+ var PACKAGE_NAME_MAX_LENGTH = 214;
21019
+ var PACKAGE_NAME_PATTERN = /^(?:@[a-zA-Z0-9][a-zA-Z0-9\-_.]*\/)?[a-zA-Z0-9][a-zA-Z0-9\-_.]*$/;
21020
+ function validatePackageName(name) {
21021
+ if (typeof name !== "string" || name.length === 0) return "Package name is empty";
21022
+ if (name.length > PACKAGE_NAME_MAX_LENGTH) {
21023
+ return `Package name exceeds ${PACKAGE_NAME_MAX_LENGTH} characters (got ${name.length}).`;
21024
+ }
21025
+ if (!PACKAGE_NAME_PATTERN.test(name)) {
21026
+ return `Invalid package name '${name}'. Names must start with an alphanumeric character and contain only [a-zA-Z0-9-_.], optionally prefixed with '@scope/' for scoped packages.`;
21027
+ }
21028
+ return null;
21029
+ }
21018
21030
  function encPkg(name) {
21019
- if (!name || name === "@") throw new Error("Invalid package name");
21031
+ const err = validatePackageName(name);
21032
+ if (err) throw new Error(err);
21020
21033
  return name.startsWith("@") ? `@${encodeURIComponent(name.slice(1))}` : encodeURIComponent(name);
21021
21034
  }
21022
21035
  function isAuthenticated() {
@@ -21232,6 +21245,61 @@ function maxSatisfying(versions, range) {
21232
21245
  return best;
21233
21246
  }
21234
21247
 
21248
+ // src/errors.ts
21249
+ function translateError(res, context) {
21250
+ if (res.ok) return res;
21251
+ const pkgPart = context.pkg ? ` for ${context.pkg}` : "";
21252
+ const opPart = context.op ? ` during ${context.op}` : "";
21253
+ switch (res.status) {
21254
+ case 401:
21255
+ return {
21256
+ ...res,
21257
+ error: `Authentication failed${pkgPart}${opPart}. Your NPM_TOKEN may be invalid, expired, or lack write scope. Create a Granular Access Token with 'Read and write' permission at https://www.npmjs.com/settings/~/tokens, or use a classic Automation token (which bypasses 2FA). Raw: ${res.error}`
21258
+ };
21259
+ case 403:
21260
+ return {
21261
+ ...res,
21262
+ error: `Not authorized${pkgPart}${opPart}. You may not be a maintainer of this package, or the token's scope doesn't include it. Check current maintainers with npm_collaborators or npm_package_access. Raw: ${res.error}`
21263
+ };
21264
+ case 404:
21265
+ return {
21266
+ ...res,
21267
+ error: `Not found${pkgPart}${opPart}. Check the exact package name (scoped packages require the @scope/ prefix). If the version is specified, verify it exists with npm_package. Raw: ${res.error}`
21268
+ };
21269
+ case 422:
21270
+ return {
21271
+ ...res,
21272
+ error: `Registry rejected the request payload${pkgPart}${opPart} (422 Unprocessable Entity). Most common causes: (1) invalid semver range \u2014 validate with npm_package versions first; (2) deprecation message format \u2014 em-dash form works, period-capital form sometimes 422s; (3) account-level 2FA policy requires interactive CLI session. If #3, CLI fallback: \`npm login --auth-type=web\` followed by the npm CLI command. Raw: ${res.error}`
21273
+ };
21274
+ case 429:
21275
+ return {
21276
+ ...res,
21277
+ error: `Rate limited${opPart}. Wait 60 seconds and retry. Raw: ${res.error}`
21278
+ };
21279
+ case 0:
21280
+ return {
21281
+ ...res,
21282
+ error: `Network error${opPart}. Could not reach the registry. Raw: ${res.error}`
21283
+ };
21284
+ default:
21285
+ return res;
21286
+ }
21287
+ }
21288
+ function validateDeprecationMessage(msg) {
21289
+ if (msg.length > 1024) {
21290
+ return "Deprecation message exceeds 1024 characters (registry limit).";
21291
+ }
21292
+ if (msg.length === 0) return null;
21293
+ if (/\.\s+[A-Z]/.test(msg)) {
21294
+ return `Deprecation message contains the "period + space + capital letter" pattern that has triggered 422 Unprocessable Entity on at least one scoped package. The working form uses em-dash and lowercase continuation: e.g. "Renamed to @yawlabs/spend \u2014 install that instead". Pass force: true to bypass this validation.`;
21295
+ }
21296
+ return null;
21297
+ }
21298
+ function versionsMatchingRange(versions, range, maxSatisfying2) {
21299
+ if (range === "*" || range === "") return [...versions];
21300
+ return versions.filter((v) => maxSatisfying2([v], range) === v);
21301
+ }
21302
+
21235
21303
  // src/tools/access.ts
21236
21304
  var accessTools = [
21237
21305
  {
@@ -21251,7 +21319,7 @@ var accessTools = [
21251
21319
  const authErr = requireAuth();
21252
21320
  if (authErr) return authErr;
21253
21321
  const res = await registryGetAuth(`/-/package/${encPkg(input.name)}/collaborators`);
21254
- if (!res.ok) return res;
21322
+ if (!res.ok) return translateError(res, { pkg: input.name, op: "collaborators" });
21255
21323
  const collaborators = Object.entries(res.data).map(([username, permissions]) => ({
21256
21324
  username,
21257
21325
  permissions
@@ -21287,7 +21355,7 @@ var accessTools = [
21287
21355
  registryGetAuth(`/-/package/${encPkg(input.name)}/access`),
21288
21356
  registryGetAuth(`/-/package/${encPkg(input.name)}/collaborators`)
21289
21357
  ]);
21290
- if (!accessRes.ok && !collabRes.ok) return collabRes;
21358
+ if (!accessRes.ok && !collabRes.ok) return translateError(collabRes, { pkg: input.name, op: "package_access" });
21291
21359
  const result = {
21292
21360
  package: input.name,
21293
21361
  isScoped: input.name.startsWith("@")
@@ -21388,7 +21456,7 @@ var analysisTools = [
21388
21456
  downloadsGet(`/downloads/point/last-week/${encPkg(input.name)}`),
21389
21457
  downloadsGet(`/downloads/point/last-month/${encPkg(input.name)}`)
21390
21458
  ]);
21391
- if (!pkgRes.ok) return pkgRes;
21459
+ if (!pkgRes.ok) return translateError(pkgRes, { pkg: input.name, op: "health" });
21392
21460
  const pkg = pkgRes.data;
21393
21461
  const latest = pkg["dist-tags"]?.latest;
21394
21462
  const latestVersion = latest ? pkg.versions[latest] : void 0;
@@ -21462,7 +21530,7 @@ var analysisTools = [
21462
21530
  }),
21463
21531
  handler: async (input) => {
21464
21532
  const res = await registryGet(`/${encPkg(input.name)}`);
21465
- if (!res.ok) return res;
21533
+ if (!res.ok) return translateError(res, { pkg: input.name, op: "maintainers" });
21466
21534
  const pkg = res.data;
21467
21535
  const publishCounts = {};
21468
21536
  for (const ver of Object.values(pkg.versions)) {
@@ -21498,7 +21566,7 @@ var analysisTools = [
21498
21566
  }),
21499
21567
  handler: async (input) => {
21500
21568
  const res = await registryGet(`/${encPkg(input.name)}`);
21501
- if (!res.ok) return res;
21569
+ if (!res.ok) return translateError(res, { pkg: input.name, op: "release_frequency" });
21502
21570
  const pkg = res.data;
21503
21571
  const limit = input.limit ?? 20;
21504
21572
  const releases = Object.keys(pkg.versions).map((v) => ({ version: v, date: pkg.time[v] })).filter((r) => r.date).sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime()).slice(0, limit);
@@ -21545,7 +21613,8 @@ var authTools = [
21545
21613
  handler: async () => {
21546
21614
  const authErr = requireAuth();
21547
21615
  if (authErr) return authErr;
21548
- return registryGetAuth("/-/whoami");
21616
+ const res = await registryGetAuth("/-/whoami");
21617
+ return res.ok ? res : translateError(res, { op: "whoami" });
21549
21618
  }
21550
21619
  },
21551
21620
  {
@@ -21563,7 +21632,7 @@ var authTools = [
21563
21632
  const authErr = requireAuth();
21564
21633
  if (authErr) return authErr;
21565
21634
  const res = await registryGetAuth("/-/npm/v1/user");
21566
- if (!res.ok) return res;
21635
+ if (!res.ok) return translateError(res, { op: "profile" });
21567
21636
  const p = res.data;
21568
21637
  return {
21569
21638
  ok: true,
@@ -21607,7 +21676,7 @@ var authTools = [
21607
21676
  const qs = params.toString();
21608
21677
  const path = `/-/npm/v1/tokens${qs ? `?${qs}` : ""}`;
21609
21678
  const res = await registryGetAuth(path);
21610
- if (!res.ok) return res;
21679
+ if (!res.ok) return translateError(res, { op: "tokens" });
21611
21680
  const data = res.data;
21612
21681
  return {
21613
21682
  ok: true,
@@ -21681,7 +21750,7 @@ var authTools = [
21681
21750
  const res = await registryGetAuth(
21682
21751
  `/-/user/org.couchdb.user:${encodeURIComponent(input.username)}/package`
21683
21752
  );
21684
- if (!res.ok) return res;
21753
+ if (!res.ok) return translateError(res, { op: `user_packages ${input.username}` });
21685
21754
  const packages = Object.entries(res.data).map(([name, access]) => ({ name, access }));
21686
21755
  return {
21687
21756
  ok: true,
@@ -21715,7 +21784,7 @@ var dependencyTools = [
21715
21784
  handler: async (input) => {
21716
21785
  const ver = input.version ?? "latest";
21717
21786
  const res = await registryGet(`/${encPkg(input.name)}/${ver}`);
21718
- if (!res.ok) return res;
21787
+ if (!res.ok) return translateError(res, { pkg: input.name, op: `dependencies ${ver}` });
21719
21788
  const v = res.data;
21720
21789
  return {
21721
21790
  ok: true,
@@ -21830,7 +21899,7 @@ var dependencyTools = [
21830
21899
  handler: async (input) => {
21831
21900
  const ver = input.version ?? "latest";
21832
21901
  const res = await registryGet(`/${encPkg(input.name)}/${ver}`);
21833
- if (!res.ok) return res;
21902
+ if (!res.ok) return translateError(res, { pkg: input.name, op: `license_check ${ver}` });
21834
21903
  const pkg = res.data;
21835
21904
  const depEntries = Object.entries(pkg.dependencies ?? {});
21836
21905
  const runLimited = createLimiter(10);
@@ -21888,7 +21957,8 @@ var downloadTools = [
21888
21957
  }),
21889
21958
  handler: async (input) => {
21890
21959
  const period = input.period ?? "last-week";
21891
- return downloadsGet(`/downloads/point/${period}/${encPkg(input.name)}`);
21960
+ const res = await downloadsGet(`/downloads/point/${period}/${encPkg(input.name)}`);
21961
+ return res.ok ? res : translateError(res, { pkg: input.name, op: `downloads ${period}` });
21892
21962
  }
21893
21963
  },
21894
21964
  {
@@ -21907,7 +21977,8 @@ var downloadTools = [
21907
21977
  }),
21908
21978
  handler: async (input) => {
21909
21979
  const period = input.period ?? "last-month";
21910
- return downloadsGet(`/downloads/range/${period}/${encPkg(input.name)}`);
21980
+ const res = await downloadsGet(`/downloads/range/${period}/${encPkg(input.name)}`);
21981
+ return res.ok ? res : translateError(res, { pkg: input.name, op: `downloads_range ${period}` });
21911
21982
  }
21912
21983
  },
21913
21984
  {
@@ -21927,7 +21998,8 @@ var downloadTools = [
21927
21998
  handler: async (input) => {
21928
21999
  const period = input.period ?? "last-week";
21929
22000
  const names = input.packages.map((p) => encPkg(p)).join(",");
21930
- return downloadsGet(`/downloads/point/${period}/${names}`);
22001
+ const res = await downloadsGet(`/downloads/point/${period}/${names}`);
22002
+ return res.ok ? res : translateError(res, { op: `downloads_bulk ${period}` });
21931
22003
  }
21932
22004
  },
21933
22005
  {
@@ -21946,66 +22018,12 @@ var downloadTools = [
21946
22018
  }),
21947
22019
  handler: async (input) => {
21948
22020
  const period = input.period ?? "last-week";
21949
- return downloadsGet(`/versions/${encPkg(input.name)}/${period}`);
22021
+ const res = await downloadsGet(`/versions/${encPkg(input.name)}/${period}`);
22022
+ return res.ok ? res : translateError(res, { pkg: input.name, op: `version_downloads ${period}` });
21950
22023
  }
21951
22024
  }
21952
22025
  ];
21953
22026
 
21954
- // src/errors.ts
21955
- function translateError(res, context) {
21956
- if (res.ok) return res;
21957
- const pkgPart = context.pkg ? ` for ${context.pkg}` : "";
21958
- const opPart = context.op ? ` during ${context.op}` : "";
21959
- switch (res.status) {
21960
- case 401:
21961
- return {
21962
- ...res,
21963
- error: `Authentication failed${pkgPart}${opPart}. Your NPM_TOKEN may be invalid, expired, or lack write scope. Create a Granular Access Token with 'Read and write' permission at https://www.npmjs.com/settings/~/tokens, or use a classic Automation token (which bypasses 2FA). Raw: ${res.error}`
21964
- };
21965
- case 403:
21966
- return {
21967
- ...res,
21968
- error: `Not authorized${pkgPart}${opPart}. You may not be a maintainer of this package, or the token's scope doesn't include it. Check current maintainers with npm_collaborators or npm_package_access. Raw: ${res.error}`
21969
- };
21970
- case 404:
21971
- return {
21972
- ...res,
21973
- error: `Not found${pkgPart}${opPart}. Check the exact package name (scoped packages require the @scope/ prefix). If the version is specified, verify it exists with npm_package. Raw: ${res.error}`
21974
- };
21975
- case 422:
21976
- return {
21977
- ...res,
21978
- error: `Registry rejected the request payload${pkgPart}${opPart} (422 Unprocessable Entity). Most common causes: (1) invalid semver range \u2014 validate with npm_package versions first; (2) deprecation message format \u2014 em-dash form works, period-capital form sometimes 422s; (3) account-level 2FA policy requires interactive CLI session. If #3, CLI fallback: \`npm login --auth-type=web\` followed by the npm CLI command. Raw: ${res.error}`
21979
- };
21980
- case 429:
21981
- return {
21982
- ...res,
21983
- error: `Rate limited${opPart}. Wait 60 seconds and retry. Raw: ${res.error}`
21984
- };
21985
- case 0:
21986
- return {
21987
- ...res,
21988
- error: `Network error${opPart}. Could not reach the registry. Raw: ${res.error}`
21989
- };
21990
- default:
21991
- return res;
21992
- }
21993
- }
21994
- function validateDeprecationMessage(msg) {
21995
- if (msg.length > 1024) {
21996
- return "Deprecation message exceeds 1024 characters (registry limit).";
21997
- }
21998
- if (msg.length === 0) return null;
21999
- if (/\.\s+[A-Z]/.test(msg)) {
22000
- return `Deprecation message contains the "period + space + capital letter" pattern that has triggered 422 Unprocessable Entity on at least one scoped package. The working form uses em-dash and lowercase continuation: e.g. "Renamed to @yawlabs/spend \u2014 install that instead". Pass force: true to bypass this validation.`;
22001
- }
22002
- return null;
22003
- }
22004
- function versionsMatchingRange(versions, range, maxSatisfying2) {
22005
- if (range === "*" || range === "") return [...versions];
22006
- return versions.filter((v) => maxSatisfying2([v], range) === v);
22007
- }
22008
-
22009
22027
  // src/tools/hooks.ts
22010
22028
  function classifyHookTarget(target) {
22011
22029
  if (target.startsWith("~")) return { type: "owner", name: target.slice(1) };
@@ -22159,7 +22177,7 @@ var orgTools = [
22159
22177
  const authErr = requireAuth();
22160
22178
  if (authErr) return authErr;
22161
22179
  const res = await registryGetAuth(`/-/org/${encodeURIComponent(input.org)}/user`);
22162
- if (!res.ok) return res;
22180
+ if (!res.ok) return translateError(res, { op: `org_members ${input.org}` });
22163
22181
  const members = Object.entries(res.data).map(([username, role]) => ({ username, role }));
22164
22182
  return {
22165
22183
  ok: true,
@@ -22189,7 +22207,7 @@ var orgTools = [
22189
22207
  const authErr = requireAuth();
22190
22208
  if (authErr) return authErr;
22191
22209
  const res = await registryGetAuth(`/-/org/${encodeURIComponent(input.org)}/package`);
22192
- if (!res.ok) return res;
22210
+ if (!res.ok) return translateError(res, { op: `org_packages ${input.org}` });
22193
22211
  const packages = Object.entries(res.data).map(([name, access]) => ({ name, access }));
22194
22212
  return {
22195
22213
  ok: true,
@@ -22219,7 +22237,7 @@ var orgTools = [
22219
22237
  const authErr = requireAuth();
22220
22238
  if (authErr) return authErr;
22221
22239
  const res = await registryGetAuth(`/-/org/${encodeURIComponent(input.org)}/team`);
22222
- if (!res.ok) return res;
22240
+ if (!res.ok) return translateError(res, { op: `org_teams ${input.org}` });
22223
22241
  return {
22224
22242
  ok: true,
22225
22243
  status: 200,
@@ -22251,7 +22269,7 @@ var orgTools = [
22251
22269
  const res = await registryGetAuth(
22252
22270
  `/-/team/${encodeURIComponent(input.org)}/${encodeURIComponent(input.team)}/package`
22253
22271
  );
22254
- if (!res.ok) return res;
22272
+ if (!res.ok) return translateError(res, { op: `team_packages ${input.org}:${input.team}` });
22255
22273
  const packages = Object.entries(res.data).map(([name, permissions]) => ({ name, permissions }));
22256
22274
  return {
22257
22275
  ok: true,
@@ -22284,7 +22302,7 @@ var packageTools = [
22284
22302
  }),
22285
22303
  handler: async (input) => {
22286
22304
  const res = await registryGet(`/${encPkg(input.name)}`);
22287
- if (!res.ok) return res;
22305
+ if (!res.ok) return translateError(res, { pkg: input.name, op: "package" });
22288
22306
  const pkg = res.data;
22289
22307
  const latest = pkg["dist-tags"]?.latest;
22290
22308
  const latestVersion = latest ? pkg.versions[latest] : void 0;
@@ -22328,7 +22346,7 @@ var packageTools = [
22328
22346
  handler: async (input) => {
22329
22347
  const ver = input.version ?? "latest";
22330
22348
  const res = await registryGet(`/${encPkg(input.name)}/${ver}`);
22331
- if (!res.ok) return res;
22349
+ if (!res.ok) return translateError(res, { pkg: input.name, op: `version ${ver}` });
22332
22350
  const v = res.data;
22333
22351
  return {
22334
22352
  ok: true,
@@ -22378,7 +22396,7 @@ var packageTools = [
22378
22396
  }),
22379
22397
  handler: async (input) => {
22380
22398
  const res = await registryGet(`/${encPkg(input.name)}`);
22381
- if (!res.ok) return res;
22399
+ if (!res.ok) return translateError(res, { pkg: input.name, op: "versions" });
22382
22400
  const pkg = res.data;
22383
22401
  const limit = input.limit ?? 50;
22384
22402
  const allVersions = Object.keys(pkg.versions).map((v) => ({
@@ -22416,7 +22434,7 @@ var packageTools = [
22416
22434
  }),
22417
22435
  handler: async (input) => {
22418
22436
  const res = await registryGet(`/${encPkg(input.name)}`);
22419
- if (!res.ok) return res;
22437
+ if (!res.ok) return translateError(res, { pkg: input.name, op: "readme" });
22420
22438
  const readme = res.data.readme;
22421
22439
  if (!readme) {
22422
22440
  return { ok: true, status: 200, data: { name: input.name, readme: "(no readme available)" } };
@@ -22438,7 +22456,8 @@ var packageTools = [
22438
22456
  name: external_exports.string().describe("Package name")
22439
22457
  }),
22440
22458
  handler: async (input) => {
22441
- return registryGet(`/-/package/${encPkg(input.name)}/dist-tags`);
22459
+ const res = await registryGet(`/-/package/${encPkg(input.name)}/dist-tags`);
22460
+ return res.ok ? res : translateError(res, { pkg: input.name, op: "dist_tags" });
22442
22461
  }
22443
22462
  },
22444
22463
  {
@@ -22468,7 +22487,7 @@ var packageTools = [
22468
22487
  registryGet(`/${encPkg(input.name)}/${ver}`),
22469
22488
  registryGet(`/${encPkg(typesPackage)}`)
22470
22489
  ]);
22471
- if (!versionRes.ok) return versionRes;
22490
+ if (!versionRes.ok) return translateError(versionRes, { pkg: input.name, op: `types ${ver}` });
22472
22491
  const v = versionRes.data;
22473
22492
  const hasBuiltinTypes = !!(v.types || v.typings);
22474
22493
  const typesEntry = hasBuiltinTypes ? v.types ?? v.typings : void 0;
@@ -22516,9 +22535,9 @@ var provenanceTools = [
22516
22535
  }),
22517
22536
  handler: async (input) => {
22518
22537
  const res = await registryGet(
22519
- `/-/npm/v1/attestations/${encPkg(input.name)}@${input.version}`
22538
+ `/-/npm/v1/attestations/${encPkg(input.name)}@${encodeURIComponent(input.version)}`
22520
22539
  );
22521
- if (!res.ok) return res;
22540
+ if (!res.ok) return translateError(res, { pkg: input.name, op: `provenance ${input.version}` });
22522
22541
  const attestations = (res.data.attestations ?? []).map((a) => ({
22523
22542
  predicateType: a.predicateType,
22524
22543
  bundle: a.bundle
@@ -22556,7 +22575,8 @@ var registryTools = [
22556
22575
  }),
22557
22576
  handler: async (input) => {
22558
22577
  const period = input.period ?? "last-week";
22559
- return downloadsGet(`/downloads/point/${period}`);
22578
+ const res = await downloadsGet(`/downloads/point/${period}`);
22579
+ return res.ok ? res : translateError(res, { op: `registry_stats ${period}` });
22560
22580
  }
22561
22581
  },
22562
22582
  {
@@ -22578,7 +22598,7 @@ var registryTools = [
22578
22598
  replicateGet("/"),
22579
22599
  replicateGet(`/_changes?limit=${limit}&descending=true`)
22580
22600
  ]);
22581
- if (!changesRes.ok) return changesRes;
22601
+ if (!changesRes.ok) return translateError(changesRes, { op: "recent_changes" });
22582
22602
  const changes = changesRes.data.results.map((r) => ({
22583
22603
  package: r.id,
22584
22604
  rev: r.changes[0]?.rev
@@ -22689,7 +22709,7 @@ var searchTools = [
22689
22709
  if (input.popularity !== void 0) params.set("popularity", String(input.popularity));
22690
22710
  if (input.maintenance !== void 0) params.set("maintenance", String(input.maintenance));
22691
22711
  const res = await registryGet(`/-/v1/search?${params}`);
22692
- if (!res.ok) return res;
22712
+ if (!res.ok) return translateError(res, { op: `search "${input.query}"` });
22693
22713
  const results = res.data.objects.map((obj) => ({
22694
22714
  name: obj.package.name,
22695
22715
  version: obj.package.version,
@@ -22722,7 +22742,34 @@ var securityTools = [
22722
22742
  packages: external_exports.record(external_exports.array(external_exports.string())).describe('Object mapping package names to arrays of version strings, e.g. {"lodash": ["4.17.20"]}')
22723
22743
  }),
22724
22744
  handler: async (input) => {
22725
- return registryPost("/-/npm/v1/security/advisories/bulk", input.packages);
22745
+ const res = await registryPost("/-/npm/v1/security/advisories/bulk", input.packages);
22746
+ if (!res.ok) return translateError(res, { op: "audit" });
22747
+ const advisoriesByPackage = res.data ?? {};
22748
+ const summary = Object.entries(advisoriesByPackage).map(([name, advisories]) => {
22749
+ const list = Array.isArray(advisories) ? advisories : [];
22750
+ const severityCounts = {};
22751
+ for (const adv of list) {
22752
+ const severity = adv?.severity ?? "unknown";
22753
+ severityCounts[severity] = (severityCounts[severity] ?? 0) + 1;
22754
+ }
22755
+ return { name, advisoryCount: list.length, severityCounts };
22756
+ });
22757
+ const queried = Object.keys(input.packages);
22758
+ const vulnerable = summary.filter((s) => s.advisoryCount > 0).map((s) => s.name);
22759
+ const clean = queried.filter((n) => !vulnerable.includes(n));
22760
+ return {
22761
+ ok: true,
22762
+ status: 200,
22763
+ data: {
22764
+ queriedCount: queried.length,
22765
+ vulnerableCount: vulnerable.length,
22766
+ cleanCount: clean.length,
22767
+ vulnerable,
22768
+ clean,
22769
+ summary,
22770
+ advisories: advisoriesByPackage
22771
+ }
22772
+ };
22726
22773
  }
22727
22774
  },
22728
22775
  {
@@ -22749,7 +22796,8 @@ var securityTools = [
22749
22796
  Object.entries(input.dependencies).map(([pkg, ver]) => [pkg, { version: ver }])
22750
22797
  )
22751
22798
  };
22752
- return registryPost("/-/npm/v1/security/audits", body);
22799
+ const res = await registryPost("/-/npm/v1/security/audits", body);
22800
+ return res.ok ? res : translateError(res, { pkg: input.name, op: "audit_deep" });
22753
22801
  }
22754
22802
  },
22755
22803
  {
@@ -22764,7 +22812,8 @@ var securityTools = [
22764
22812
  },
22765
22813
  inputSchema: external_exports.object({}),
22766
22814
  handler: async () => {
22767
- return registryGet("/-/npm/v1/keys");
22815
+ const res = await registryGet("/-/npm/v1/keys");
22816
+ return res.ok ? res : translateError(res, { op: "signing_keys" });
22768
22817
  }
22769
22818
  }
22770
22819
  ];
@@ -22788,7 +22837,7 @@ var trustTools = [
22788
22837
  const authErr = requireAuth();
22789
22838
  if (authErr) return authErr;
22790
22839
  const res = await registryGetAuth(`/-/package/${encPkg(input.name)}/trust`);
22791
- if (!res.ok) return res;
22840
+ if (!res.ok) return translateError(res, { pkg: input.name, op: "trusted_publishers" });
22792
22841
  const configs = (res.data ?? []).map((c) => {
22793
22842
  const result = {
22794
22843
  id: c.id,
@@ -23100,6 +23149,10 @@ var workflowTools = [
23100
23149
  async function fetchPackument(pkg) {
23101
23150
  return registryGetAuth(`/${encPkg(pkg)}?write=true`);
23102
23151
  }
23152
+ function parseTeamTarget(target) {
23153
+ const m = target.match(/^@?([^:]+):(.+)$/);
23154
+ return m ? { scope: m[1], team: m[2] } : null;
23155
+ }
23103
23156
  function highestVersion(versions) {
23104
23157
  const parsed = [];
23105
23158
  for (const v of versions) {
@@ -23116,7 +23169,7 @@ var writeTools = [
23116
23169
  // ───────────────────────────────────────────────────────
23117
23170
  {
23118
23171
  name: "npm_deprecate",
23119
- description: "Deprecate a package or specific versions. Shows a warning message on install. Uses the HTTP API with NPM_TOKEN, bypassing the CLI auth friction that causes 422 errors on accounts with 2FA. Message format: prefer em-dash form ('Renamed to @scope/pkg \u2014 install that instead'); period-capital form sometimes triggers 422.",
23172
+ description: "Deprecate a package or specific versions. Shows a warning message on install. Uses the HTTP API with NPM_TOKEN, bypassing the CLI auth friction that causes 422 errors on accounts with 2FA. Message format tip: the period-then-capital pattern ('... install that instead. Thanks.') has 422'd on at least one scoped package; em-dash form is the known-good workaround. Pass force: true to skip the preflight check if you want the exact message as-is.",
23120
23173
  annotations: {
23121
23174
  title: "Deprecate package",
23122
23175
  readOnlyHint: false,
@@ -23125,7 +23178,7 @@ var writeTools = [
23125
23178
  openWorldHint: true
23126
23179
  },
23127
23180
  inputSchema: external_exports.object({
23128
- name: external_exports.string().describe("Package name (e.g. '@yawlabs/tokenmeter-mcp')"),
23181
+ name: external_exports.string().describe("Package name (e.g. '@yawlabs/spend')"),
23129
23182
  message: external_exports.string().describe("Deprecation message. Empty string to clear deprecation (use npm_undeprecate instead)."),
23130
23183
  versionRange: external_exports.string().optional().describe("Semver range. Omit to deprecate ALL versions. Example: '<1.0.0' or '0.3.x'."),
23131
23184
  force: external_exports.boolean().optional().describe("Bypass message format validation (default: false).")
@@ -23661,15 +23714,15 @@ var writeTools = [
23661
23714
  handler: async (input) => {
23662
23715
  const authErr = requireAuth();
23663
23716
  if (authErr) return authErr;
23664
- const m = input.team.match(/^@?([^:]+):(.+)$/);
23665
- if (!m) {
23717
+ const parsed = parseTeamTarget(input.team);
23718
+ if (!parsed) {
23666
23719
  return {
23667
23720
  ok: false,
23668
23721
  status: 400,
23669
23722
  error: `Team must be in the form '@scope:team' (got '${input.team}').`
23670
23723
  };
23671
23724
  }
23672
- const [, scope, team] = m;
23725
+ const { scope, team } = parsed;
23673
23726
  const res = await registryPutAuth(`/-/team/${encodeURIComponent(scope)}/${encodeURIComponent(team)}/package`, {
23674
23727
  package: input.package,
23675
23728
  permissions: input.permissions
@@ -23702,15 +23755,15 @@ var writeTools = [
23702
23755
  handler: async (input) => {
23703
23756
  const authErr = requireAuth();
23704
23757
  if (authErr) return authErr;
23705
- const m = input.team.match(/^@?([^:]+):(.+)$/);
23706
- if (!m) {
23758
+ const parsed = parseTeamTarget(input.team);
23759
+ if (!parsed) {
23707
23760
  return {
23708
23761
  ok: false,
23709
23762
  status: 400,
23710
23763
  error: `Team must be in the form '@scope:team' (got '${input.team}').`
23711
23764
  };
23712
23765
  }
23713
- const [, scope, team] = m;
23766
+ const { scope, team } = parsed;
23714
23767
  const res = await registryDeleteAuth(`/-/team/${encodeURIComponent(scope)}/${encodeURIComponent(team)}/package`, {
23715
23768
  package: input.package
23716
23769
  });
@@ -23742,11 +23795,11 @@ var writeTools = [
23742
23795
  handler: async (input) => {
23743
23796
  const authErr = requireAuth();
23744
23797
  if (authErr) return authErr;
23745
- const m = input.team.match(/^@?([^:]+):(.+)$/);
23746
- if (!m) {
23798
+ const parsed = parseTeamTarget(input.team);
23799
+ if (!parsed) {
23747
23800
  return { ok: false, status: 400, error: `Team must be in the form '@scope:team' (got '${input.team}').` };
23748
23801
  }
23749
- const [, scope, team] = m;
23802
+ const { scope, team } = parsed;
23750
23803
  const res = await registryPutAuth(`/-/org/${encodeURIComponent(scope)}/team`, {
23751
23804
  name: team,
23752
23805
  description: input.description
@@ -23774,11 +23827,11 @@ var writeTools = [
23774
23827
  handler: async (input) => {
23775
23828
  const authErr = requireAuth();
23776
23829
  if (authErr) return authErr;
23777
- const m = input.team.match(/^@?([^:]+):(.+)$/);
23778
- if (!m) {
23830
+ const parsed = parseTeamTarget(input.team);
23831
+ if (!parsed) {
23779
23832
  return { ok: false, status: 400, error: `Team must be in the form '@scope:team' (got '${input.team}').` };
23780
23833
  }
23781
- const [, scope, team] = m;
23834
+ const { scope, team } = parsed;
23782
23835
  const res = await registryDeleteAuth(`/-/team/${encodeURIComponent(scope)}/${encodeURIComponent(team)}`);
23783
23836
  if (!res.ok) return translateError(res, { op: `team_delete ${input.team}` });
23784
23837
  return { ok: true, status: 200, data: { team: `@${scope}:${team}`, deleted: true } };
@@ -23804,11 +23857,11 @@ var writeTools = [
23804
23857
  handler: async (input) => {
23805
23858
  const authErr = requireAuth();
23806
23859
  if (authErr) return authErr;
23807
- const m = input.team.match(/^@?([^:]+):(.+)$/);
23808
- if (!m) {
23860
+ const parsed = parseTeamTarget(input.team);
23861
+ if (!parsed) {
23809
23862
  return { ok: false, status: 400, error: `Team must be in the form '@scope:team' (got '${input.team}').` };
23810
23863
  }
23811
- const [, scope, team] = m;
23864
+ const { scope, team } = parsed;
23812
23865
  const res = await registryPutAuth(`/-/team/${encodeURIComponent(scope)}/${encodeURIComponent(team)}/user`, {
23813
23866
  user: input.user
23814
23867
  });
@@ -23836,11 +23889,11 @@ var writeTools = [
23836
23889
  handler: async (input) => {
23837
23890
  const authErr = requireAuth();
23838
23891
  if (authErr) return authErr;
23839
- const m = input.team.match(/^@?([^:]+):(.+)$/);
23840
- if (!m) {
23892
+ const parsed = parseTeamTarget(input.team);
23893
+ if (!parsed) {
23841
23894
  return { ok: false, status: 400, error: `Team must be in the form '@scope:team' (got '${input.team}').` };
23842
23895
  }
23843
- const [, scope, team] = m;
23896
+ const { scope, team } = parsed;
23844
23897
  const res = await registryDeleteAuth(`/-/team/${encodeURIComponent(scope)}/${encodeURIComponent(team)}/user`, {
23845
23898
  user: input.user
23846
23899
  });
@@ -23934,7 +23987,7 @@ var writeTools = [
23934
23987
  ];
23935
23988
 
23936
23989
  // src/index.ts
23937
- var version2 = true ? "0.7.0" : (await null).createRequire(import.meta.url)("../package.json").version;
23990
+ var version2 = true ? "0.9.0" : (await null).createRequire(import.meta.url)("../package.json").version;
23938
23991
  var subcommand = process.argv[2];
23939
23992
  if (subcommand === "version" || subcommand === "--version") {
23940
23993
  console.log(version2);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yawlabs/npmjs-mcp",
3
- "version": "0.7.0",
3
+ "version": "0.9.0",
4
4
  "description": "npm registry MCP server — package intelligence, security audits, and dependency analysis for AI assistants",
5
5
  "license": "MIT",
6
6
  "author": "YawLabs <contact@yaw.sh>",
@@ -39,6 +39,10 @@
39
39
  "prepublishOnly": "npm run build"
40
40
  },
41
41
  "dependencies": {},
42
+ "overrides": {
43
+ "hono": "^4.12.14",
44
+ "@hono/node-server": "^1.19.13"
45
+ },
42
46
  "devDependencies": {
43
47
  "@biomejs/biome": "^1.9.4",
44
48
  "@modelcontextprotocol/sdk": "^1.29.0",