Title: mcpx docs: a runnable, editable example on the home page (WASM vs hosted daemon vs local) · Issue #1876 · developing-today/code · GitHub
Open Graph Title: mcpx docs: a runnable, editable example on the home page (WASM vs hosted daemon vs local) · Issue #1876 · developing-today/code
X Title: mcpx docs: a runnable, editable example on the home page (WASM vs hosted daemon vs local) · Issue #1876 · developing-today/code
Description: Relocated from dezren39/darwin-nix#156 on 2026-10-28 (placement audit): mcpx's single source lives in developing-today/code (pkgs/mcpx); re-home tracked at #309. Original body below; issue references inside it are historical (dezren39/ni...
Open Graph Description: Relocated from dezren39/darwin-nix#156 on 2026-10-28 (placement audit): mcpx's single source lives in developing-today/code (pkgs/mcpx); re-home tracked at #309. Original body below; issue referenc...
X Description: Relocated from dezren39/darwin-nix#156 on 2026-10-28 (placement audit): mcpx's single source lives in developing-today/code (pkgs/mcpx); re-home tracked at #309. Original body below; issue refe...
Opengraph URL: https://github.com/developing-today/code/issues/1876
X: @github
Domain: github.com
IPv4 address: 140.82.113.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"mcpx docs: a runnable, editable example on the home page (WASM vs hosted daemon vs local)","articleBody":"Relocated from dezren39/nix#156 on 2026-10-28 (placement audit): mcpx's single source lives in developing-today/code (pkgs/mcpx); re-home tracked at #309. Original body below; issue references inside it are historical (dezren39/nix numbering).\n\nParent: #92\n\n## Summary\n\nThe home page's code example (#155) should be editable and runnable: change a line, press Run, see\noutput. The notes name three places the code could run (`wasm, local mcp, daemon/cli-client`) plus\n\"remote\". This issue compares four candidates -- in the browser, a hosted public daemon, the reader's own\nlocal daemon, and \"show the command to paste\" -- and recommends a staged answer: **ship the paste-the-command\nbutton and an in-browser run against a fake daemon first; add \"run on my machine\" (local daemon) later as an\nopt-in; do not host a public daemon.**\n\nKey fact that makes the in-browser option cheap: a generated mcpx client talks to the daemon over plain HTTP,\nand its hot path is one route, `POST /v1/call` (`internal/codegen/emit.go:524`; the other two are\n`/v1/resource` :1220 and `/v1/artifacts` :1305). A fake daemon in the page only has to answer that.\n\n## Original notes\n\n> - documentation\n> - make a book using whatever is the most common and simple modern choice\n> - 3 main things, not book sections jsut like levels of detail-\n> - the 30 seconds look at home page click the overview page, click the quick start page, ctrl+w should be simple enough that even this person skimming while doing 3 different things will accidentally learn\n> - how to install it\n> - home page has\n> - simple intro\n> - code block example\n> - static syntax-highlighted typescript\n> - exec real editable example click button remote\n> - wasm, local mcp, daemon/cli-client\n\n## Current state (what mcpx does today, with file refs)\n\n- **Scripts run in a real runtime subprocess** (deno, bun or node) that calls back to the daemon. Deno and\n Bun use the unix socket; Node uses the TCP endpoint because Node's `fetch` cannot address a socket\n without undici (`internal/codegen/emit.go:263-291`; `.github/workflows/mcpx.yml:52-54`).\n- **The daemon always listens on loopback TCP**, on an OS-assigned port unless `daemon.port` is set\n (`internal/daemon/server.go:206-218`; docs/dependencies.md \"Network\"). A web page cannot discover a\n random port.\n- **No CORS.** No `Access-Control-*` header anywhere in `internal/` (grep). A browser page on another origin\n cannot read any `/v1` response today.\n- **The daemon can run a script itself**: `POST /v1/exec` (docs/exec.md \"The thing that was wrong\"), so a\n caller with no runtime can send source and get the result. This is what a browser would use to run code\n on a local or remote daemon.\n- **`--address`/`--port`** exist (`daemon.address` default `127.0.0.1`, `daemon.port` default `0`,\n `internal/settings/registry.go:343-375`); binding beyond loopback prints a warning because the API is\n unauthenticated (story.md \"One daemon, many clients\", :2092).\n- **Codegen is Go** (`internal/codegen`), JSON Schema -> TypeScript. The client emitted is written to run\n under Node's strip-only TypeScript (story.md \"Runtime portability\", :757), which also makes it easy to\n type-strip in a browser.\n\n## Candidates\n\n| | Where the code runs | Real MCP servers | Works before install | Main cost |\n| --- | --- | --- | --- | --- |\n| 1 | the reader's browser (JS; WASM optional) | no, mocked | yes | fidelity: it is a simulation |\n| 2 | a hosted public daemon (\"remote\") | yes, ours | yes | running strangers' code |\n| 3 | the reader's own daemon at `127.0.0.1` | yes, theirs | no | browser local-network rules, CORS, a fixed port |\n| 4 | the reader's terminal: copy `mcpx exec '\u003ccode>'` | yes, theirs | no | a context switch |\n\n### 1. In the browser (the note's \"wasm\")\n\nThe browser is already a JavaScript engine, so no WASM is needed to run the *script*:\n\n- **Type stripping in the page.** The example is TypeScript; strip types before `import()`-ing it as a blob\n URL. Options by weight: sucrase (small, strip-only), esbuild-wasm (~10 MB wasm, fast, full TS syntax),\n the TypeScript compiler's `transpileModule` (several MB). Strip-only is enough for the same reason Node\n can run the generated client: it avoids non-erasable syntax.\n- **Editor.** CodeMirror 6 (modular, small) over Monaco (multi-megabyte, VS Code's editor). A plain\n `\u003ctextarea>` with the static highlighted block as the no-JS fallback is a legitimate v1.\n- **A fake daemon in the page.** Intercept `fetch` to `/v1/call` (monkeypatch `globalThis.fetch`, or a\n Service Worker scoped to the demo) and answer from in-page mock servers: a few namespaces whose tools\n return canned or computed results. Then the page can run **the real generated client**, emitted at docs\n build time by `mcpx client`/`mcpx types` against fixture servers, not a hand-written imitation. Open\n question: the client reads its endpoint and session through `env()` (Deno/`process`), and imports\n `node:*` builtins lazily for the Deno shim (`emit.go:348-390`); both need to degrade cleanly in a browser.\n- **Go -> WASM of the daemon** (`GOOS=js GOARCH=wasm`) is possible but buys little: `os/exec` cannot spawn\n processes in a browser, so it could not start a single MCP server, and unix sockets do not exist. The\n one thing it would add is in-browser codegen from an arbitrary JSON Schema, which build-time generation\n already covers. Not worth a multi-megabyte download.\n- **WASM MCP servers** (a server compiled to WASM running in the page) are possible for toy servers only;\n the servers people care about (Chrome, GitHub, filesystem) cannot run in a tab.\n\nFidelity gaps to state on the page: no launcher (`@placeholders`, #7), no real runtime APIs beyond the\nbrowser's (`Deno.*` and `node:fs` absent), tools are mocks. The label should say \"simulated\".\n\n### 2. A hosted public daemon (\"remote\")\n\nA daemon on a server we run, with `/v1/exec` exposed through a proxy that adds CORS. Maximum wow: real\nservers, real output, no install. The dominant cost is not engineering: it is **executing arbitrary code\nfrom anonymous users**. `/v1/exec` runs a full deno/bun/node process with filesystem, network and\nsubprocess access (AGENTS.md \"Scripts\"). Making that safe means per-request sandboxes (gVisor, Firecracker),\negress filtering, CPU/memory/time limits, rate limiting, and abuse monitoring, and it costs money on every\nclick. Security design is deferred for the whole backlog, but here it is not a detail to defer: it is the\nwhole cost.\n\n### 3. The reader's own daemon at 127.0.0.1 (the note's \"local mcp\")\n\nThe page calls `http://127.0.0.1:\u003cport>/v1/exec` on the reader's machine. Real servers, the reader's own\nconfig, and a great \"it's already running on my laptop\" moment. Obstacles, all real:\n\n- **Chrome Local Network Access.** Since Chrome 142 a public site requesting a loopback address triggers a\n permission prompt; Chrome 145 split it into `local-network` and `loopback-network` permissions. Only\n secure contexts may ask, so the docs must be HTTPS (they will be, #119). A granted request is exempt\n from mixed-content blocking when the target is an IP literal or `fetch(..., { targetAddressSpace:\n \"loopback\" })` is used (developer.chrome.com/blog/local-network-access; MDN \"Local network access\").\n Other browsers differ; `http://127.0.0.1` is \"potentially trustworthy\" by spec so plain mixed content is\n usually not the blocker, the permission is.\n- **CORS on the daemon.** The daemon sends no CORS headers. It would need an explicit allow-list: a setting\n such as `daemon.cors` (a list of origins, default empty), not `*`. Allowing the docs origin to call\n `/v1/exec` is allowing that origin to run code on the reader's machine; the allow-list must be something\n the reader turned on.\n- **A known port.** The TCP port is random by default. The page needs `daemon.port` set to a documented\n value, or a discovery step the browser cannot do.\n- **Only after install.** A first-time visitor has no daemon; this serves the second visit.\n\n### 4. Paste the command (the note's \"daemon/cli-client\")\n\nA button that copies the edited example as a runnable command:\n`mcpx exec '\u003csource>'` for a snippet, or a two-liner that writes `.mcpx/scripts/\u003cname>.ts` and runs\n`mcpx run \u003cname>`. Zero browser plumbing, runs against the reader's real servers, works in every browser,\nand it teaches the actual interface. Shell quoting of arbitrary source is the one trap: single-quoted\nstrings cannot contain `'`, so generate a quoted heredoc (`mcpx exec \"$(cat \u003c\u003c'EOF' ... EOF)\"`). Piping\nis not an option today: `mcpx exec` requires the source as an argument and errors with\n`usage: mcpx exec '\u003ctypescript>'` when there is none (`internal/cli/commands.go:488-491`); stdin is passed\nthrough to the script, not read as source (`internal/cli/exec.go:495-497`).\n\n## Approaches\n\n### Approach A -- hosted public daemon (least recommended)\n\nBuild candidate 2. It is the only option that shows real servers to someone who has not installed\nanything, which is why it is tempting. Why not: it turns a docs site into a public code-execution service.\nThe sandboxing, egress control, quotas and abuse handling are a product of their own, with a running bill,\nand the first incident is a crypto miner or a spam relay running on our account. The benefit over a\nconvincing simulation is small for a 30-second visitor who cannot tell the difference.\n\n### Approach B -- local daemon first (middle)\n\nBuild candidate 3 as the primary Run button, with candidate 4 as the fallback when no daemon answers.\nEverything is real, nothing is hosted. Needs: a `daemon.cors` origin allow-list setting (default empty),\na documented fixed port or a docs-specific opt-in (`mcpx daemon --port 8899 --cors https://\u003cshort>`, where\n`--cors` is proposed, not existing),\n`targetAddressSpace: \"loopback\"` on the page's fetch, and a clear explanation of Chrome's permission\nprompt. Weak for its audience: the 30-second reader has not installed mcpx yet, so the primary button\nfails for exactly the person the home page is for, and the opt-in steps cost more than pasting a command.\n\n### Approach C -- staged: paste-the-command + in-browser simulation now, local daemon later (recommended)\n\nRecommended.\n\n1. **Now: candidate 4.** Every example gets \"Copy as `mcpx exec`\" and \"Copy as script\". Trivial, real, and\n useful on every page, not only the home page.\n2. **Now: candidate 1 without WASM.** An editable example that runs in the page against in-page mocks,\n using the real generated client from a build-time `mcpx client` run, a strip-only TS transform, and a\n small editor. Labelled \"simulated -- runs in your browser\". Delivers the \"click Run, see output\" moment\n to someone who has installed nothing, at zero hosting cost.\n3. **Later, opt-in: candidate 3.** Once a reader has mcpx, a \"Run on my machine\" toggle calls their daemon.\n Gate it on a `daemon.cors` allow-list the reader sets deliberately, and on a fixed `daemon.port`. This\n is also the path an embedded daemon UI would share (see the surfaces theme's web issue #86).\n4. **Never by default: candidate 2.**\n\nWhy C: it serves the first-time reader (simulation) and the installed reader (paste the command) with no\nnew daemon surface, and defers the only daemon change (CORS) until someone asks for it. The only new code\nis static page JS.\n\n## Open questions\n\n- Does the generated client run unmodified in a browser if `env()` returns `undefined` and `node:*` imports\n fail? If not, a small `--target browser` option on `mcpx client` is cleaner than patching output.\n- Which mock namespaces make a convincing demo without implying tools the reader will not have? The story's\n `chrome_devtools` flow cannot be simulated honestly (screenshots); something like a fake `github` or\n `weather` namespace can.\n- Should `mcpx exec -` read source from stdin, as `mcpx diagnose` already accepts `-`\n (`\u003cscript|file|-|'\u003csource>'>`, `internal/cli/manual.go`)? It would make the paste button's command\n shorter and quoting-proof; today the heredoc form is required.\n- For the later local mode: a docs-specific flag, or a general `daemon.cors` setting? The setting is more\n honest (it is what it is), and a flag alias can follow.\n- Is the in-browser demo worth maintaining on pages beyond the home page (#147 script page)?\n\n## Ease · Impact · Related\n\n**Ease**: S for the copy-as-command buttons; M for the in-browser simulation; M for the later local-daemon\nmode (CORS setting, docs, browser testing); XL for a hosted daemon. **Impact**: med (a strong home-page\nmoment; not required to understand or install mcpx).\n**Depends on / related**: #155 (the example slot), #117 (the generator must allow page JS and an\ninclude of the generated client), #119 (HTTPS origin, required for the local-network permission),\n#147 (script/SDK pages could reuse it), #7 (launcher behaviour the simulation omits), #79 (typecheck\ndefault changes what a real run prints), the surfaces theme's web-frontend issue #86 (a daemon-served UI is the\nother consumer of CORS/port decisions).\n\nSecurity/auth deferred; see tracker.\n\n","author":{"url":"https://github.com/dezren39","@type":"Person","name":"dezren39"},"datePublished":"2026-10-28T22:12:44Z","url":"https://github.com/developing-today/code/issues/1876"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:ad6b5d2b-a0f8-425c-f200-753cfb246643 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C8A0:1E1784:2C782A:3B659B:6B06167F |
| html-safe-nonce | c90ddbb8869401049d7d07080a5a00d52dde7e44df8ff9bbfc98f2d9e9e43a03 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDOEEwOjFFMTc4NDoyQzc4MkE6M0I2NTlCOjZCMDYxNjdGIiwidmlzaXRvcl9pZCI6Ijg5NDk1NDcwNjAxMTg4MjA0NzkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 1d6170987b0dbb904975245c32343bcacdb9e477f5d4db8fdf93380c430e13a5 |
| hovercard-subject-tag | issue:6088449261 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/developing-today/code/1876/issue_layout |
| twitter:image | https://opengraph.githubassets.com/65d4dd8082172a18effb5888f78013ab8195fad87490ccbf906102b01eb5aa2b/developing-today/code/issues/1876 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/65d4dd8082172a18effb5888f78013ab8195fad87490ccbf906102b01eb5aa2b/developing-today/code/issues/1876 |
| og:image:alt | Relocated from dezren39/darwin-nix#156 on 2026-10-28 (placement audit): mcpx's single source lives in developing-today/code (pkgs/mcpx); re-home tracked at #309. Original body below; issue referenc... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dezren39 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 97d4714e567728e1f85f88b0cf68c89f0f8a3dc41e8869af7aeb8195ad990374 |
| turbo-cache-control | no-preview |
| go-import | github.com/developing-today/code git https://github.com/developing-today/code.git |
| octolytics-dimension-user_id | 26439447 |
| octolytics-dimension-user_login | developing-today |
| octolytics-dimension-repository_id | 627308783 |
| octolytics-dimension-repository_nwo | developing-today/code |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 627308783 |
| octolytics-dimension-repository_network_root_nwo | developing-today/code |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 866f202ebf7ac5aff8f633417d9fd8a53818a977 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width