Repository navigation
feat(mcpx): home-page example — copy-as-command + in-browser simulation (#1876) #2501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a94dba1
095d0ea
e278b3e
7cb04e0
16c6e1d
7ba4a4c
66f0281
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| # The home-page example: copy it or run it in the page | ||
|
|
||
| The example on the home page is not a picture of code. It is the working | ||
| script from [`home-example/example.ts`](home-example/example.ts), and a | ||
| reader can do two things with it before installing anything is required | ||
| of them — and a third once it is. | ||
|
|
||
| **Copy as mcpx exec.** One click puts a command on the clipboard that | ||
| runs the example against your own daemon and your own servers: | ||
|
|
||
| ```sh | ||
| mcpx exec "$(cat <<'MCPX_EOF' | ||
| const echoed = await tools.demo.echo({ message: "hello from a script" }); | ||
|
|
||
| console.log("demo.echo:", String(echoed)); | ||
| MCPX_EOF | ||
| )" | ||
| ``` | ||
|
|
||
| The heredoc is quoted, which is the whole trick: an example full of | ||
| apostrophes, `$` signs and backticks arrives at `mcpx exec` byte for | ||
| byte, because `mcpx exec` takes its source as an argument and its stdin | ||
| belongs to the script. *Copy as script* puts the source itself on the | ||
|
Comment on lines
+19
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| clipboard instead, for a file under `.mcpx/scripts/` and `mcpx run`. | ||
|
|
||
| **Run it in the page.** The example is editable, and Run executes the | ||
| edited version in the browser tab. This is a simulation and the page | ||
| labels it as one: the script runs through the real generated client, but | ||
| its `POST /v1/call` is answered by a fake daemon in the page whose only | ||
| namespace is a mock `demo` server. It is the right tool for "what does | ||
| this code do" — change a line, see the output change — and the wrong one | ||
| for "what will this do against my servers", which is what the copy | ||
| button is for. | ||
|
|
||
| What the simulation does not have: real MCP servers, the launcher, and | ||
| the runtime APIs (`Deno.*`, `node:fs`) a real run provides. Running an | ||
| example against your own daemon from the page is a later, opt-in stage; | ||
| running strangers' code on a hosted daemon is not planned at all. The | ||
| component, its mocks, and its regeneration script live in | ||
| [`home-example/`](home-example/README.md). | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| # The home-page example component | ||
|
|
||
| Issue #1876, Approach C, stages 1–2. This directory is the example slot of | ||
| the mcpx home page, landed in the docs source because the page itself | ||
| (#1874) and the site build/deploy (#1941) have not landed yet — when they | ||
| do, the generator includes `component.html` where the example goes and | ||
| runs `generate-client.sh` as part of the build. Nothing here is a parallel | ||
| site. | ||
|
|
||
| ## What a reader gets | ||
|
|
||
| - **Stage 1 — copy-as-command** (`copy-command.js`). Every docs example | ||
| can be copied two ways: *Copy as mcpx exec* (a quoted-heredoc command | ||
| that runs the snippet against the reader's real daemon; see the file | ||
| header for why the quoting has to be a heredoc) and *Copy as script* | ||
| (the source itself, plus `scriptCommands()` for the save-and-`mcpx run` | ||
| two-liner). | ||
| - **Stage 2 — run it in the page** (`component.html`, `run-example.js`). | ||
| The example is editable; Run executes it in the tab. The label says | ||
| **"Simulated — runs in your browser"**, because it is one: | ||
| - the script runs through a strip-only TypeScript transform | ||
| (`strip-types.js`) and is imported as a blob module; | ||
| - it talks to the **real generated client** — `client.ts`, emitted by | ||
| `mcpx client --ns demo` against the deterministic fixture server | ||
| (`internal/testsupport/fakemcp`), and `client.browser.js`, that same | ||
| file after Node's strip-only transform. Neither is hand-written; | ||
| regenerate both with `./generate-client.sh`; | ||
| - the client's one hot route, `POST /v1/call`, is answered by a fake | ||
| daemon (`fake-daemon.js`) from in-page mocks (`mocks.js`). `/v1/batch`, | ||
| `/v1/resource` and `/v1/artifacts` are not simulated and answer with | ||
| an honest error. | ||
| - **No-JS fallback**: the static highlighted example, unchanged. | ||
|
|
||
| ## Fidelity gaps (also stated on the page) | ||
|
|
||
| - The only namespace is the mock `demo` fixture; its deterministic tools | ||
| are mirrored, the rest return an error naming the limitation. No real | ||
| MCP servers, no launcher placeholders, no `Deno.*`/`node:fs`. | ||
| - Mocks are computed from the same rules as the fixture where the fixture | ||
| is deterministic (echo, open/state/wipe, structured, boom, fancy-name). | ||
|
|
||
| ## Stage 3 is not here | ||
|
|
||
| Running against the reader's own daemon (a `daemon.cors` allow-list | ||
| setting, a fixed `daemon.port`, Chrome Local Network Access handling) is | ||
| excluded — a separate later follow-on. A hosted public daemon is rejected | ||
| in the issue, permanently. This component makes no daemon changes. | ||
|
|
||
| ## Verify | ||
|
|
||
| ```sh | ||
| node smoke-test.mjs # shell round-trip for stage 1; end-to-end run for stage 2 | ||
| ./generate-client.sh # regenerate client.ts / client.browser.js from the fixture | ||
| ``` | ||
|
|
||
| #1941 should wire `smoke-test.mjs` into the docs CI pipeline; until then | ||
| it is the recorded smoke check for this component. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
Repository: developing-today/code
Length of output: 25987
Script executed:
Repository: developing-today/code
Length of output: 9915
Name the
demoserver as a prerequisite of the copy-as-exec example.The copied command calls
tools.demo.echo. The page says it runs against "your own daemon and your own servers," but the example works only when the reader has configured a server nameddemo. The default configuration does not define one, so the copied command fails on a default install. Add that prerequisite to the page, or change the example to call a tool that the reader's servers are known to provide.LanguageTool
[grammar] ~8-~8: Ensure spelling is correct
Context: ...em — and a third once it is. Copy as mcpx exec. One click puts a command on the...
(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)