sayshape-mcp 0.1.0 → 0.1.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 CHANGED
@@ -55,6 +55,31 @@ The view has no website of its own, so an `image` only loads from a host you lis
55
55
 
56
56
  The one list does three things: the view's engine loads from those hosts and no others, the server asks the chat app to allow them in the view's Content Security Policy (MCP Apps `resourceDomains`), and the model is told which hosts work, so it doesn't invent URLs elsewhere. Images must be https, and the host must send CORS headers (`Access-Control-Allow-Origin`), as image CDNs do, because the view keeps its canvas readable for Save image and Copy text. An image that can't load shows its description instead. Some chat apps may not honour a view's CSP request; then images show their descriptions there.
57
57
 
58
+ ## In chat apps that can't draw interfaces
59
+
60
+ Coding agents and other text-only clients (Claude Code, Codex, Antigravity and others) call `show_interface` but can't show MCP Apps views. When a client connects without announcing MCP Apps support (the `io.modelcontextprotocol/ui` capability), and the spec has nothing to fix, `show_interface`'s text result carries a small, complete HTML page instead, with two sentences telling the model what to do with it: publish it as a page if it has a tool for that, or save it as an `.html` file and give the person its path to open in a browser. The server itself writes no files. For these clients the result is text alone, with no structured part: the structured part is for the view, and some clients (Claude Code is one) give their model the structured part in place of the text, which would lose the page. Clients that draw views get exactly what they got before.
61
+
62
+ The page is a few kilobytes plus the spec: a canvas, the engine loaded from jsDelivr (`sayshape@<version>/dist/sayshape.global.js`, and the map's own script when the spec has a map), and the spec embedded as JSON with `<` escaped, so nothing in it can end the script. It follows light and dark mode, and a `data-theme="light"` or `"dark"` on its root element; its background is the engine theme's own; and it fits a phone with no sideways scrolling.
63
+
64
+ A page outside the chat has no conversation to send `emit:` actions to, so for these clients only:
65
+
66
+ - **The model is told not to use `emit:`.** Their quick start (in `show_interface`'s description and `sayshape_docs` with nothing named) says to leave it out and ask the person to reply in the chat instead.
67
+ - **A spec with `emit:` gets it back to fix**, line by line, with no page until it's gone. Buttons can keep `set:`, `go:` or `notify:`, so they still do something on the page. Everything else in the interface (state, controls, charts, screens) works.
68
+ - **Links pressed in `rich=true` text open in a new tab** (https only). In the chat they're sent to the model as `emit:link`; on the page, the page is the host, so it opens them as any web page would.
69
+
70
+ Clients that draw views see none of this: the same descriptions, the same docs and the same results as before.
71
+
72
+ What doesn't work there:
73
+
74
+ - **Save image and Copy text** aren't on the page.
75
+ - **It needs internet access** to load the engine from the CDN; without it, or before the pinned version is on the CDN, the page names the engine version that didn't load.
76
+ - **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.
77
+ - 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.
78
+ - 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).)
79
+ - 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.
80
+
81
+ 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.
82
+
58
83
  ## Tokens
59
84
 
60
85
  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.
@@ -135,9 +160,7 @@ This is a **source-level integration API**, not yet a published SDK. SayShape do
135
160
 
136
161
  ## Install
137
162
 
138
- You need Node.js 20 or later.
139
-
140
- > **Not on npm yet.** Until it's published, build it from source and point your chat app at `dist/server.js` (see **From source** below), using `"command": "node", "args": ["/full/path/to/sayshape/mcp/dist/server.js"]` in place of the `npx` lines. Once it's published, the `npx` settings below work as written.
163
+ You need Node.js 20 or later (22.13 or later for `--data`). `npx` downloads the server from npm the first time.
141
164
 
142
165
  **Claude Desktop:** Settings → Developer → Edit Config, then add:
143
166
 
@@ -161,7 +184,7 @@ Quit Claude Desktop completely (Cmd+Q) and reopen it. If it can't find `npx`, us
161
184
  }
162
185
  ```
163
186
 
164
- **Apps that connect to a URL** (custom connectors in Claude on the web, ChatGPT developer mode): run it over HTTP and put it behind HTTPS (a reverse proxy or a tunnel). It listens only on 127.0.0.1:
187
+ **Apps that connect to a URL** (custom connectors in Claude on the web, ChatGPT developer mode): run it over HTTP and put it behind HTTPS (a reverse proxy or a tunnel). By default it listens only on 127.0.0.1; to host it for others, see [Host it publicly](#host-it-publicly).
165
188
 
166
189
  ```bash
167
190
  npx -y sayshape-mcp --http 3001 # http://127.0.0.1:3001/mcp
@@ -177,6 +200,32 @@ cd sayshape/mcp && npm ci && npm run build
177
200
 
178
201
  Then ask for something visual: *"Show the 2022 World Cup final as a stat card"*, or *"Make me a tip calculator for $86 split three ways"*.
179
202
 
203
+ ## Host it publicly
204
+
205
+ To give Claude, ChatGPT and other chat apps a permanent HTTPS address, run the HTTP mode on a host that puts its own HTTPS proxy in front (Render, Fly.io, Railway and the like). There's no sign-in: anyone who has the address can call it, which is fine for `show_interface` and `sayshape_docs`, since they read nothing but the spec they're sent.
206
+
207
+ Start it with an exact version, never `@latest`, so what runs is what you checked:
208
+
209
+ ```bash
210
+ npx -y sayshape-mcp@0.1.2 --http --host 0.0.0.0 --trust-proxy
211
+ ```
212
+
213
+ | | |
214
+ |---|---|
215
+ | `--http [port]` | Serve MCP on `/mcp`. The port is the flag's, else the `PORT` environment variable (container hosts set it), else 3001. |
216
+ | `--host <address>` | Where to listen. `127.0.0.1` by default; `0.0.0.0` (or `::`) to take requests from the host's proxy. `HOST` from the environment is used when no flag is given, but only if it's an IP address: some machines set `HOST` to their own name. |
217
+ | `--rate-limit <n>` | Calls a minute per client address, in this process (default 300 when listening beyond loopback, off on loopback; 0 turns it off). Each call in a JSON-RPC batch counts. Over the limit, a request gets `429` with `Retry-After`. |
218
+ | `--trust-proxy [hops]` | Count calls by `X-Forwarded-For` instead of the connection's address. Behind a proxy every connection comes from the proxy, so without this everyone shares one count. Each proxy appends the address it received the request from, so the server takes the entry written by the `hops`-th proxy from the end (default 1) and ignores anything the client wrote before it. Set it to exactly the number of proxies in front of the server (your host's docs say how many); more lets clients pick their own address, and never use it without a proxy. |
219
+ | `--allow-public-data` | See below. |
220
+
221
+ `GET /` answers `200` with one plain line, for the host's health check; it isn't rate limited. Requests have limits too: headers must arrive within 10 seconds and the whole request within 30, bodies are capped at 1 MB and headers at 16 KB and 100 fields, and at most 1,000 connections are open at once.
222
+
223
+ **What it logs:** one line at startup (the address, port and rate limit), and a note if it ignores `HOST`. Nothing from a request: no specs, no addresses, no errors with request content. Specs come from people's conversations and can hold personal data. `SAYSHAPE_LOG_CLIENT=1` adds one line per connection with the client app's name, version and capabilities, still nothing from the conversation. Your host's own access logs are separate: they usually record each request's address, path and status, so check its settings and your privacy policy.
224
+
225
+ **Calls come from the chat apps' servers.** When Claude or ChatGPT calls a connector, the request comes from the company's servers, not from each person's computer, so everyone using it through one app may share a few addresses and one count. Watch for `429`s once people use it, and raise `--rate-limit` if they're legitimate.
226
+
227
+ **Don't use `--data` here.** A public server with `--data` would let anyone, with no sign-in, read every table in the database (`query_data` runs any `SELECT`), fetch other callers' results by their id (`d1`, `d2`…), and stall the server with one slow query. So with `--http` on an address beyond loopback, `--data` is refused unless you also pass `--allow-public-data`; only do that for data that's public anyway, on an address protected some other way. `--mcp-result` is refused with `--http` altogether.
228
+
180
229
  ## Development
181
230
 
182
231
  Publishing: `npm publish` from this folder runs the tests and the build first (`prepublishOnly`), then uploads `dist/`, this README and the license.
@@ -188,6 +237,6 @@ npm run build
188
237
  npm run test:e2e # the built view in Chromium, inside a sandboxed iframe driven by the MCP Apps host bridge
189
238
  ```
190
239
 
191
- `test:e2e` runs the browser canvas/host-action test, the database-to-interface test, 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/`.
240
+ `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/`.
192
241
 
193
242
  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.