feat(mcp): the app server as a Cloudflare Worker at an address of ours (#272)
Merged
AL
16h ago+1221+1221+0123456789012345678901234567890123456789-37-37-01234567890123456789
The app server gets a host: a Cloudflare Worker at mcp.embed-my.org. Nothing is deployed by this PR. Merging it puts the Worker in the repository; deploying is a step for someone signed in to the Cloudflare account (below).
Why a Worker
- A limit reached there stops only Workers. The free plan gives 100,000 requests a day and bills nothing. The limit is the account's: over it, every Worker of the account answers an error until midnight UTC. Nothing on another host is touched, the demo and the organisation's site among them.
- Not the demo's Vercel project. A function there was built and proven locally, then dropped: on its plan the whole account shares 4 CPU-hours a month, and over the limit the account is paused until someone acts, the demo and
/embedwith it. The endpoint has no sign-in, so anyone could bring that about. - The address is one line of config, since the domain's zone is on the same account: Cloudflare writes the DNS record and the certificate.
What changed
The MCP package (packages/mcp)
createApp()is exported as@missing-elements/h5p-mcp/app. It was a handler nobody outside the package could import.- It takes three more options, for a bundle with no package folder beside its code, where
import.metafinds nothing:version,card,references. Without them it reads what it read before. Areferencesfolder that is not the author package's is refused as the server starts, so a wrong path does not quietly thin the answers. bin/h5p-mcp.mjsis marked executable in git, asbin/h5p-mcp-app.mjsalready is. pnpm sets that bit on every install once another workspace package depends on this one, so the file would otherwise show as changed after each install.
The Worker (apps/mcp-worker, new, private)
src/worker.mjs: the same handler, started by the first call.scripts/stage.mjsgathers what the server reads as it runs intostaged/(not in git): the library pack's parts, the brief and the type files, the card.wrangler.jsoncattaches them to the Worker as modules, which its file system shows under/bundle, so the server's Node entry reads them as on a computer. 17 MB of the 64 MiB a Worker may be. They are modules, not static assets: nothing of them is served.- It writes no log of a call and has nowhere to keep one.
observability.enabledisfalse, which switches off Workers Logs: no invocation log and no trace is stored. No store is bound. One address: noworkers.devname, no preview addresses. What Cloudflare counts for any Worker and domain, requests, statuses, CPU time, is outside that setting; the privacy policy is to name it from Cloudflare's own documents. - One new development dependency,
wrangler, with the Workers runtime it starts (workerd).workerd's install script only checks its binary and stays off, as every dependency's does here; it is named inpnpm-workspace.yamlso the install says nothing.
Checked
- In the Workers runtime, by
apps/mcp-worker/tests/worker.test.ts(6 tests): wrangler bundles the Worker and starts it on this computer, and each answer is held to the Node server's, word for word: the tools, the list of types, a type's file, a type's fields from its part, a source checked, one refused, the card and its address. A path of what it carries answers 404, a body over 1 MB answers 413, and the config is held to its logs off, no store and one address. - The MCP package's tests, 31, one of them new: a host that gives its card, its version and its type files is answered from those, and a folder that is not the author package's is refused.
pnpm typecheckover the whole repository.wrangler deploy --dry-run: 181 modules attached, 17.4 MB to upload, no bindings.
Not known until it is deployed
- CPU on the free plan. It allows 10 ms a request, with leeway for an overrun now and then. A check took 14 to 22 ms a call on a laptop in the local runtime, and the first list of types 250 ms. If errors show: the paid plan ($5 a month, 30 s a request), or the parts as static assets, read by the author package's entry for a page.
- Start-up. A Worker may take 1 s to start; this one is 17 MB. A deploy says how long it took.
- No region. A Worker runs near its caller and cannot be held to one region below the Enterprise plan.
To deploy, after the merge
From the repository's root, signed in to the Cloudflare account that has the embed-my.org zone:
pnpm install
pnpm --filter @missing-elements/h5p-mcp-worker exec wrangler login
pnpm --filter @missing-elements/h5p-mcp-worker deploy:worker
The sign-in opens a browser and stays on that computer: no token of the account is in the repository or in GitHub.