sayshape-mcp 0.2.1 → 0.2.2
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.
- package/README.md +35 -2
- package/dist/server.js +1467 -166
- package/dist/ui.html +119 -86
- package/dist/widget-engine.json +1 -0
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -42,6 +42,8 @@ When none is on, there's no toolbar at all. Whoever installs the server chooses,
|
|
|
42
42
|
| `--scene` | **Experimental.** Turn on scenes: pictures and animations the model paints from shapes, with parts people can press and soft shadows, glow and shine for depth (off by default). Leave it out to turn them off again. |
|
|
43
43
|
| `--behavior` | **Experimental.** Turn on behavior: things that change by themselves on a timer (a countdown, a simulation) and, together with `--scene`, shapes people drag (off by default). Rules only change the interface's own values; they still can't run code. Chat apps that can't draw views don't get it. |
|
|
44
44
|
| `--image-hosts cdn.example.com,*.img.example.com` | Hosts `image` elements may load from, comma-separated; `*.example.com` allows its subdomains. None by default, so no images show. See [Images](#images). |
|
|
45
|
+
| `--widget-dir <folder>` | For chat apps that can't draw MCP Apps views but can show a widget made from a file: write each interface there as one self-contained file (stdio only; refused with `--http`). Off by default. See [Chat apps that show widgets from files](#chat-apps-that-show-widgets-from-files). |
|
|
46
|
+
| `--widget-host <name>` | With `--widget-dir` only: hook that chat app's adapter into every file, so `emit:` presses (and the interface's state) are saved for the model's next turn. Names: `muse`. An unknown name, or no `--widget-dir`, stops the server with a message. Off by default. See [Adapting a file to a chat app](#adapting-a-file-to-a-chat-app---widget-host). |
|
|
45
47
|
|
|
46
48
|
```json
|
|
47
49
|
"sayshape": { "command": "node", "args": ["/full/path/to/sayshape/mcp/dist/server.js", "--theme", "blue", "--theme-picker"] }
|
|
@@ -86,10 +88,41 @@ What doesn't work there:
|
|
|
86
88
|
- **Interfaces that load datasets** (`--data`, `--mcp-result`) can't be shown: the page has no way to fetch rows, and the rows never go through the conversation. The model is told so and answers in text.
|
|
87
89
|
- It uses the default Teal light and dark themes; `--theme`, `--theme-picker` and the chat app's own colors and fonts apply only to the view.
|
|
88
90
|
- The engine version is pinned and moves at releases, so the page can be one release behind the server: an element added in the newest release may not draw there yet. ([Why](https://github.com/premmannava/sayshape/blob/main/docs/releasing.md#the-engine-version-the-text-only-page-loads).)
|
|
91
|
+
- For chat apps whose sandbox blocks the CDN but can show a widget from a file, see [`--widget-dir`](#chat-apps-that-show-widgets-from-files).
|
|
89
92
|
- In `--http` mode the server makes a new server for every request and never sees what the client announced, so it always answers as for a client that draws views.
|
|
90
93
|
|
|
91
94
|
The same interface sent again gets no second page, and a spec with problems gets them to fix first, with no page. To see what a client announces, start the server with `SAYSHAPE_LOG_CLIENT=1` in its environment: each connection writes the client's name and capabilities to stderr.
|
|
92
95
|
|
|
96
|
+
### Chat apps that show widgets from files
|
|
97
|
+
|
|
98
|
+
Some chat apps show a widget built from a file on your computer, inside a sandbox that loads nothing from outside: no scripts from a CDN, no network requests, no remote images. The page above can't draw there, because it loads the engine from jsDelivr. Muse is the one this was tested in. What its sandbox allows is what such an app needs the file to be: inline scripts, `blob:` scripts and `DecompressionStream` work; the widget has to be an HTML fragment (no `<!doctype>`, `<html>`, `<head>` or `<body>`) under 1 MB, stored whole with the chat and run in its own frame, so nothing is shared between widgets; the app scans a widget's source for browser storage names; and the frame is about 656 px wide with Times as its default font.
|
|
99
|
+
|
|
100
|
+
Start the server with `--widget-dir <folder>` and, for a client that announces no MCP Apps support, `show_interface` writes the interface into that folder and returns a short text result instead of a page: the file's absolute path, and an instruction to create the widget from that file exactly as it is, without reading or editing it. The engine is inside the file, so it never passes through the model's context. Problems to fix are reported as before, with no file. Clients that draw views, and every client when the flag is off, get what they got before.
|
|
101
|
+
|
|
102
|
+
```json
|
|
103
|
+
"sayshape": { "command": "node", "args": ["/full/path/to/sayshape/mcp/dist/server.js", "--widget-dir", "/Users/you/sayshape-widgets"] }
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
- **One file, made from this server's own engine.** `npm run build` builds the engine from this repository's `src/` (`scripts/pack-widget-engine.mjs`: the same entry as the page's CDN build, plus the slide elements), gzips it with Node's zlib and ships it in the package as `dist/widget-engine.json`, so the file always matches the server that checked the spec. The fragment holds one wrapping `<div>` (full width, at most 760 px, with its own font), a canvas, the spec (as JSON with `<` escaped, so `</script>` in a spec stays inert), the packed engine and a loader: it decodes and unpacks the engine with `DecompressionStream` and runs it as a `blob:` script, so nothing is fetched and the engine still can't run anything a spec says. A spec that mentions a browser storage name has its first letter escaped, so the words never appear in the file. Where the engine can't be unpacked, a short plain note shows in place of the canvas. A plain interface makes a file of about 260 KB; one with a map about 480 KB (the map's outlines are a second packed script). If a file would reach 1 MB, none is written and the result says why.
|
|
107
|
+
- **The name is a hash** of the spec and everything that changes the file (the settings below and the engine), so the same interface reuses one file. The folder keeps the newest 50 (`sayshape-<16 hex digits>.html`); older ones are deleted, and nothing else in the folder is ever touched.
|
|
108
|
+
- **The server's settings reach the file.** `--theme`, `--accent`, `--image-hosts` (and `--logo`), `--scene`, `--behavior` and `--slides` all apply, and unlike the page, behavior and decks work, because the file carries this server's engine and not an older pinned one. (Images from other hosts can't load in a sandbox like Muse's, so an `image` shows its description there.) Fonts: the file draws in the system font where Instrument Sans or Inter isn't installed.
|
|
109
|
+
- **Light and dark** follow `data-theme="light|dark"` on the root element and the system's `prefers-color-scheme`, and changes to either.
|
|
110
|
+
- **As on the page:** interfaces that load datasets are refused with the same message, `emit:` is refused and removed by the model first (a widget has no chat to send to yet; see `--widget-host` below for the way around that), and links pressed in `rich=true` text open in a new tab (https only).
|
|
111
|
+
|
|
112
|
+
### Adapting a file to a chat app (`--widget-host`)
|
|
113
|
+
|
|
114
|
+
The fragment builder (`mcp/src/widget-file.ts`) takes a `host` option: the source of a function the loader calls once after the first draw, as `(source)(ui, sayshape, root)`, which may return `{ emit(action) }` to receive the actions that aren't links. `--widget-host <name>` sets it to one of the adapters in `mcp/src/widget-hosts/`; `muse` is the only one so far. It only works together with `--widget-dir`:
|
|
115
|
+
|
|
116
|
+
```json
|
|
117
|
+
"sayshape": { "command": "node", "args": ["/full/path/to/sayshape/mcp/dist/server.js", "--widget-dir", "/Users/you/sayshape-widgets", "--widget-host", "muse"] }
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
What changes with it, for clients that get a file:
|
|
121
|
+
|
|
122
|
+
- **The file carries the adapter.** The Muse adapter keeps `emit:` actions in a short list in the widget's state bridge, next to the interface's own state (saved without passwords, and skipped when it is large), and puts that state back when the widget is mounted again. If `--theme` or `--accent` was given, the adapter ignores the chat app's colors and the interface keeps its own; otherwise it follows the app's.
|
|
123
|
+
- **`emit:` is allowed.** The quick start no longer says not to use it, and a line with `emit:` is no longer a problem to fix. It says that presses are saved for the model's next turn instead: after the person's next message, the model reads the widget's state, where `actions` lists what they pressed (name, value, time). The result for a spec that uses `emit:` says the same.
|
|
124
|
+
- **Nothing else changes.** Without the flag, `emit:` is handled exactly as above; clients that draw MCP Apps views get the same tools, docs and results with or without it.
|
|
125
|
+
|
|
93
126
|
## Tokens
|
|
94
127
|
|
|
95
128
|
A model never reads the whole language guide (about 7,500 tokens). It gets a quick start in `show_interface`'s description (about 450) and asks `sayshape_docs` for only the elements it's about to use: about 140 tokens for a button, 700 for a chart and a table, 1,200 for a six-element dashboard. If it guesses an element wrong, the result of `show_interface` brings that element's docs, so a wrong guess costs one retry, not the whole guide. Retries are the expensive part, because each call resends the whole conversation, so the server avoids the needless ones: it quietly fixes Markdown fences and typographic quotes (the view tidies the same way), tells the model when a problem was only an ignored prop and needs no new call, and answers an unknown function like `argmax` with the one to use instead (`first(sort(rows, 'revenue', 'desc'))`). With a database, the rows go from the database to the interface, so the model's tokens don't grow with the data either.
|
|
@@ -217,7 +250,7 @@ To give Claude, ChatGPT and other chat apps a permanent HTTPS address, run the H
|
|
|
217
250
|
Start it with an exact version, never `@latest`, so what runs is what you checked:
|
|
218
251
|
|
|
219
252
|
```bash
|
|
220
|
-
npx -y sayshape-mcp@0.2.
|
|
253
|
+
npx -y sayshape-mcp@0.2.2 --http --host 0.0.0.0 --trust-proxy
|
|
221
254
|
```
|
|
222
255
|
|
|
223
256
|
| | |
|
|
@@ -247,6 +280,6 @@ npm run build
|
|
|
247
280
|
npm run test:e2e # the built view in Chromium, inside a sandboxed iframe driven by the MCP Apps host bridge
|
|
248
281
|
```
|
|
249
282
|
|
|
250
|
-
`test:e2e` runs the browser canvas/host-action test, the database-to-interface test, the **text-only page test** (`scripts/e2e-fallback.mjs`: a client without MCP Apps gets a page, which is opened from a file in Chromium with the engine built from `../src` standing in for jsDelivr, and must paint in light, dark and `data-theme`, fit 400px and keep a spec containing `</script>` inert), and the **stdio MCP result import test** (`scripts/e2e-import.mjs`). The last one starts the built server with `--mcp-result`, lists the imported schema, calls `show_interface` and verifies the exact rows delivered by app-only `fetch_dataset`. Screenshots from the browser tests go to `e2e-output/`.
|
|
283
|
+
`test:e2e` runs the browser canvas/host-action test, the database-to-interface test, the **text-only page test** (`scripts/e2e-fallback.mjs`: a client without MCP Apps gets a page, which is opened from a file in Chromium with the engine built from `../src` standing in for jsDelivr, and must paint in light, dark and `data-theme`, fit 400px and keep a spec containing `</script>` inert), the **widget file test** (`scripts/e2e-widget.mjs`: the file `--widget-dir` writes is opened in Chromium under a Content Security Policy that blocks every external script, connection and image, and must draw in light and dark, fit 400px, change on a press and keep a hostile spec inert), and the **stdio MCP result import test** (`scripts/e2e-import.mjs`). The last one starts the built server with `--mcp-result`, lists the imported schema, calls `show_interface` and verifies the exact rows delivered by app-only `fetch_dataset`. Screenshots from the browser tests go to `e2e-output/`.
|
|
251
284
|
|
|
252
285
|
The server bundles the engine from `../src`, so the guide, the parser and the view always match the library they were built with. The MCP packages (`@modelcontextprotocol/sdk`, `@modelcontextprotocol/ext-apps`, `zod`) are dependencies of this package only. The SayShape library itself still has none.
|