cdnjs-mcp
README.md
# cdnjs-mcp
An [MCP](https://modelcontextprotocol.io) server that gives an LLM live,
read-only package lookups: [cdnjs](https://cdnjs.com) (all ~4,600 front-end
libraries, with canonical names, version histories, exact filenames and SRI
hashes), the [npm](https://www.npmjs.com) registry, [jsDelivr](https://www.jsdelivr.com)
and [PyPI](https://pypi.org). Deploys to Cloudflare Workers.
It exists so an assistant writing a `<script>` tag can **look up** the version
instead of recalling one. A model's training data goes stale silently; a wrong
pin either 404s or quietly serves something years old.
> Unofficial. Not affiliated with, endorsed by, or operated by cdnjs,
> Cloudflare, npm, jsDelivr or the PSF. It is a third-party client for their
> public APIs.
## Tools
| Tool | Answers |
| --- | --- |
| `cdnjs_search` | What is this library actually called? |
| `cdnjs_library` | Current version, license, homepage, and a pinned URL with its SRI hash |
| `cdnjs_versions` | Which versions exist, newest first, prereleases hidden by default |
| `cdnjs_files` | Exact filenames in a version, each with its SRI hash and full URL |
| `npm_package` | One npm package as a bundler sees it: current version, license, engines, deprecation, peers (optional ones marked) |
| `npm_versions` | npm versions newest first; with `range`, the highest version under a cap |
| `npm_compat` | Do these pins work together? Peer conflicts, missing required peers, and the version that would fix each |
| `jsdelivr_files` | Pinned jsDelivr URLs + SRI for any npm file cdnjs lacks, plus the import map its bare imports need |
| `pypi_package` | One PyPI project: highest stable release, Python requirement, deps, yanked status, known vulnerabilities |
### Why npm and PyPI too
cdnjs answers "what goes in a `<script>` tag". A bundled app installs from npm,
and most of its dependencies (`zod`, `zustand`, `@react-three/*`) aren't on
cdnjs at all. The question that actually breaks those builds isn't "what's the
latest version" but "do these versions work together", and that lives in
`peerDependencies`. In one real project, the newest TypeScript (7.0.2) broke
linting because `typescript-eslint` 8.74 peers `typescript <6.1.0`. That took
several manual `npm view` calls to find. `npm_compat` reports it in one call,
with `6.0.3` as the fix.
## Quick start
Deploy your own. It takes about a minute and needs no secrets.
```bash
git clone https://github.com/jjrjvjwtvk-hue/cdnjs-mcp && cd cdnjs-mcp
```
```bash
npm install && npx wrangler login
```
```bash
npm run deploy
```
`npm run deploy` runs the tests first and refuses to deploy if they fail.
Then add the printed URL to your MCP client with `/mcp` on the end:
```
https://cdnjs-mcp.<your-subdomain>.workers.dev/mcp
```
For Claude, that goes in Settings → Connectors → Add custom connector. A plain
`GET /` returns a health check if you want to confirm it's up first.
**Please deploy your own rather than pointing at someone else's URL.** Every
call costs the operator Worker invocations and spends cdnjs's free bandwidth.
## Why a server rather than a static file
Worth stating, because "put the reference material in a file" is the obvious
first instinct and it doesn't work here:
| | Why not |
| --- | --- |
| A bundled list or prompt | 4,600 libraries don't fit, and the data is stale the moment it's written |
| A documentation page | Describes the API; doesn't answer a specific question at the moment it's asked |
| **A live proxy** | **Always current, no cache to drift, and the whole catalog is reachable** |
The general rule: **don't cache what an upstream API answers authoritatively.**
Keep in your own layer only the things the API gets wrong.
## The three traps
This is what the proxy is actually for. A plain `curl` against the cdnjs API
hits all three. Each was verified against the live API on 2026-11-01, and each
has a test that fails if the handling is removed.
### 1. Library names are case-sensitive
`GET /libraries/chart.js` returns `404 Library not found`. The canonical name
is `Chart.js`.
Every lookup here falls back to search and takes a case-insensitive **exact**
match, then tells you the name was corrected. The top search hit is not
trustworthy — searching `chart.js` returns `mermaid` above `Chart.js` — so an
exact match is required rather than first place.
### 2. `versions[0]` is not the current version
Prereleases sort in front. Of 20 popular libraries sampled, **4 lead with
one**:
| Library | `versions[0]` | Actual current release |
| --- | --- | --- |
| vue | `3.6.0-rc.14` | `3.5.44` |
| bootstrap | `6.0.0-alpha.1` | `5.3.8` |
| recharts | `3.11.0-canary.8` | `3.10.1` |
| gl-matrix | `4.0.0-beta.2` | `3.4.4` |
Take the `version` field for the current stable, never `versions[0]`. Pin from
`versions[0]` and you can ship a canary build to production.
`cdnjs_versions` hides prereleases unless you ask for them, and always marks
the current stable.
### 3. Legacy tags are not semver and must not outrank real releases
Some libraries carry historical tags that predate semver. **three.js has 217 of
them** — `r134`, `110` — sitting in the same array as modern `0.187.0`
releases.
Compared component-wise, bare `110` beats `0.187.0` on the first number. So a
plain numeric sort buries the current version under every historical tag: ask
for the 60 newest and you never see it.
Here, anything with three or more dot-separated components is treated as modern
and outranks anything with fewer. Within a tier, numeric descending, with
prereleases below the release they qualify.
**This shipped broken and was caught on the deployed Worker.** three.js's raw
array was *already* correctly newest-first; the naive sort took a correct array
and made it wrong. Worth stating because it inverts the obvious lesson — the
sort exists for consistency across libraries, not because upstream ordering is
usually bad. Ordering of the raw array was fine for 15 of 20 libraries sampled,
and the rest invert only deep in ancient history (jquery lists `1.2.3` before
`1.7`).
## The npm, jsDelivr and PyPI traps
Same rule as above: each was verified against the live API on 2026-12-02 and
has a test that fails without the handling.
1. **npm names are case-sensitive too.** `registry.npmjs.org/React` is a 404.
Lookups fall back to search and take a case-insensitive exact match.
2. **The version list is not the current version.** jsDelivr's list for vue
leads with `3.6.0-rc.17`; `dist-tags.latest` is `3.5.46`. The npm tools take
`dist-tags.latest` and hide prereleases by default.
3. **Not every declared peer is required.** `@react-three/fiber` 9.8.2 declares
six peers (expo, expo-gl, expo-asset, expo-file-system, react-native,
react-dom), all marked optional in `peerDependenciesMeta`. A naive check
reports six missing peers for an ordinary web app. `npm_compat` skips
optional peers that aren't in the set and only counts them.
4. **jsDelivr files can import other packages by bare name.**
`three/examples/jsm/controls/OrbitControls.js` imports from `'three'`, which
a browser can't resolve without an import map. `jsdelivr_files` reads small
result sets, ignores imports that only appear in doc comments (that file has
one), and maps a self-import to the **same version's** ES module build so
the page doesn't load two copies of three.js.
5. **PyPI's full project JSON is huge.** `/pypi/numpy/json` is about 3.8 MB,
enough to strain a Worker's CPU budget. `pypi_package` reads the ~10 KB
release RSS feed instead, then the ~130 KB per-version JSON, which also
carries known vulnerabilities.
6. **That RSS feed is in upload order, not version order.** Django's newest
upload is the `5.2.19` backport while the current release is `6.1.3`;
SQLAlchemy alternates 2.1.x and 2.0.x. Taking the first entry pins an old
line. The highest stable version is chosen instead.
7. **Scoped names encode differently per API.** The npm registry takes
`@scope%2Fname`; jsDelivr's data API returns 400 for that and needs the raw
slash. This one was caught in use: `npm_versions` on `@testing-library/dom`
failed, and `npm_compat` silently dropped its fix suggestion.
8. **The platform caps outbound requests per invocation** (50 on the Workers
free plan). `npm_compat` at its 25-package limit used two requests per
package, left nothing for fix lookups, and reported the failed lookups as
"No stable react satisfies it", a confident wrong answer. Now each package
costs one request (the registry resolves exact versions and dist-tags in
the manifest path, so the worst case uses 29), and a failed lookup is
reported as a failure, never as a fact. A test counts the requests on a cold
cache.
9. **PyPI names are normalised (PEP 503)**, so `camelot_py`, `Camelot.Py` and
`camelot-py` all resolve.
## Tests
```bash
npm test
```
62 checks against the **live** cdnjs, npm, jsDelivr and PyPI APIs —
protocol handshake, all nine tools, every trap above, error handling, routing
and CORS. No mocks, so an
upstream API change surfaces in the test run rather than in production. The
tradeoff is that the suite needs network and can fail for reasons that aren't
your fault.
Each trap-handler is **mutation-tested**. Remove the semver sort and the
three.js ordering check fails; drop the prerelease filter and three vue checks
fail; drop the case-insensitive resolution and five `Chart.js` checks fail.
On the npm/PyPI side: treat optional peers as required and three checks fail;
stop stripping comments before scanning imports and two fail; take the RSS
feed's first entry and the Django check fails with `ours=5.2.19 pypi=6.1.3`;
drop npm's search fallback and three fail; stop hiding npm prereleases and two
fail; map `three` to `/+esm` instead of the pinned module build and one fails;
narrow the extras filter and one fails; encode scoped names for jsDelivr
the registry's way and three fail; go back to two requests per package and the
subrequest-budget check fails (54 used).
That mattered: the first version of this suite **passed** when the sort was
deleted, because the check was reading `versions[0]` — which is newest anyway,
so it asserted nothing. A check that cannot fail is decoration. If the suite
ever goes a long stretch without catching anything, break something on purpose
and confirm it still bites.
### A gotcha in the tooling itself
`node --check src/index.js` will **not** catch a syntax error here. It parses a
`.js` file as CommonJS, and this is an ES module; during development it passed
a file with an unclosed argument list. Use:
```bash
node --input-type=module --check < src/index.js
```
## How it works
A single Worker, no bindings and no stored state. `POST /mcp` speaks JSON-RPC
2.0 over Streamable HTTP; `GET /` is a health check. Requests to cdnjs are
cached in-process for five minutes, which only collapses bursts inside one
isolate — there is no shared cache to go stale.
All four upstream APIs are public, unauthenticated and read-only, so this
server holds no credentials, needs no OAuth, and cannot write anything
anywhere. The one runtime dependency is [`semver`](https://www.npmjs.com/package/semver),
for npm range matching; wrangler bundles it.
```
src/index.js MCP transport, routing, and the cdnjs tools
src/npm.js npm registry + jsDelivr tools
src/pypi.js PyPI tool
src/http.js shared fetch with the 5-minute in-isolate cache
test/local.mjs the suite — runs the handler directly, no wrangler needed
wrangler.toml name, entrypoint, compatibility date. No bindings
```
## Contributing
Issues and pull requests welcome. Two asks: run `npm test` before opening a PR,
and if you add handling for an upstream quirk, add a test that fails without it
— this repo's whole premise is that unverified checks are worse than none.
If an upstream API changes shape, the test suite is the place it will show up
first.
## License
[MIT](LICENSE).