@ractive-ch/tab-mcp-client 0.16.2 → 0.18.0

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.
Files changed (57) hide show
  1. package/CHANGELOG.md +898 -0
  2. package/README.md +216 -90
  3. package/address.d.ts +8 -8
  4. package/allowed.d.ts +28 -0
  5. package/allowed.js +14 -0
  6. package/allowed.js.map +10 -0
  7. package/always-allowed.d.ts +140 -22
  8. package/cdn/allowed.min.js +4 -0
  9. package/cdn/allowed.min.js.map +10 -0
  10. package/cdn/confirm-f36n8xj5.min.js +4 -0
  11. package/cdn/confirm-f36n8xj5.min.js.map +10 -0
  12. package/cdn/connect-ph4xxen4.min.js +6 -0
  13. package/cdn/connect-ph4xxen4.min.js.map +12 -0
  14. package/cdn/{connection-w97tf22a.min.js → connection-0xqwz17v.min.js} +7 -7
  15. package/cdn/{connection-w97tf22a.min.js.map → connection-0xqwz17v.min.js.map} +5 -5
  16. package/cdn/{index-vt5zk9me.min.js → tab-mcp-client-2vx9mcww.min.js} +20 -9
  17. package/cdn/tab-mcp-client-2vx9mcww.min.js.map +12 -0
  18. package/cdn/tab-mcp-client-6gcmd7n8.min.js +5 -0
  19. package/cdn/tab-mcp-client-6gcmd7n8.min.js.map +10 -0
  20. package/cdn/tab-mcp-client.min.js +3 -3
  21. package/cdn/tab-mcp-client.min.js.map +4 -4
  22. package/{confirm-fgnjgd08.js → confirm-jbyqzy14.js} +29 -19
  23. package/confirm-jbyqzy14.js.map +10 -0
  24. package/confirm.d.ts +27 -20
  25. package/{connect-8jpb0k29.js → connect-13hkdpcx.js} +113 -16
  26. package/connect-13hkdpcx.js.map +10 -0
  27. package/connect.d.ts +2 -2
  28. package/{connection-g91xjjgm.js → connection-gang7f5x.js} +10 -23
  29. package/{connection-g91xjjgm.js.map → connection-gang7f5x.js.map} +5 -5
  30. package/connection.d.ts +2 -2
  31. package/dialog.d.ts +1 -1
  32. package/{index-jnz7w9xa.js → index-c1c266tm.js} +36 -98
  33. package/index-c1c266tm.js.map +11 -0
  34. package/index-dmh5vm5m.js.map +1 -1
  35. package/index-h8b3dc5p.js +245 -0
  36. package/index-h8b3dc5p.js.map +10 -0
  37. package/index.js +33 -22
  38. package/index.js.map +4 -4
  39. package/internal.d.ts +2 -0
  40. package/package.json +7 -2
  41. package/protocol.d.ts +6 -7
  42. package/react.d.ts +19 -0
  43. package/react.js +30 -1
  44. package/react.js.map +3 -3
  45. package/secret.d.ts +6 -0
  46. package/strings.d.ts +13 -4
  47. package/tab-mcp.d.ts +15 -5
  48. package/types.d.ts +32 -9
  49. package/visible.d.ts +1 -1
  50. package/cdn/confirm-y30cx7e1.min.js +0 -4
  51. package/cdn/confirm-y30cx7e1.min.js.map +0 -10
  52. package/cdn/connect-bbhj2y7w.min.js +0 -6
  53. package/cdn/connect-bbhj2y7w.min.js.map +0 -12
  54. package/cdn/index-vt5zk9me.min.js.map +0 -13
  55. package/confirm-fgnjgd08.js.map +0 -10
  56. package/connect-8jpb0k29.js.map +0 -10
  57. package/index-jnz7w9xa.js.map +0 -12
package/README.md CHANGED
@@ -3,14 +3,19 @@
3
3
  Offer a web page's functions as [MCP](https://modelcontextprotocol.io) tools to AI apps
4
4
  (Claude, ChatGPT, Claude Code, Codex) through a
5
5
  [tab-mcp](https://github.com/ractive/tab-mcp) relay. The page connects to the relay and
6
- gets an address. The user adds that address to their AI app and types a pairing code
7
- from the page; the AI app then calls the page's tools while the tab stays open. Nothing
6
+ shows its app's address, which is the same for every page of the app. The user adds that
7
+ address to their AI app and types a pairing code from the page, which tells the relay
8
+ which page is meant; the AI app then calls the page's tools while the tab stays open. Nothing
8
9
  is installed on the user's computer. With `webmcp: true` the library also registers the
9
10
  tools with the browser's own [WebMCP](#webmcp), for agents in the browser. A site's own
10
11
  assistant can call the same tools over a port, without a relay:
11
12
  [Your own assistant on the page](#your-own-assistant-on-the-page).
12
13
 
13
- **Status: 0.16.2.** Until 1.0, a new minor version can still change the API. Which AI apps
14
+ How the library, the relay and the tab-mcp browser extension fit together, with a
15
+ picture:
16
+ [How the parts fit together](https://github.com/ractive/tab-mcp#how-the-parts-fit-together).
17
+
18
+ **Status: 0.18.0.** Until 1.0, a new minor version can still change the API. Which AI apps
14
19
  work is listed in [compatibility](https://github.com/ractive/tab-mcp/blob/main/docs/compatibility.md).
15
20
 
16
21
  ## You need a relay
@@ -26,7 +31,7 @@ docker run --rm -p 8080:8080 \
26
31
  -e TAB_MCP_PUBLIC_URL=http://localhost:8080 \
27
32
  -e TAB_MCP_ALLOWED_ORIGINS=http://localhost:3000 \
28
33
  -e TAB_MCP_STORE=memory \
29
- ractive/tab-mcp:0.10.3
34
+ ractive/tab-mcp:0.12.0
30
35
  ```
31
36
 
32
37
  For production, see
@@ -45,7 +50,7 @@ Or without a bundler, from a CDN as an ES module:
45
50
 
46
51
  ```html
47
52
  <script type="module">
48
- import { TabMcp } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.16.2/cdn/tab-mcp-client.min.js";
53
+ import { TabMcp } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.18.0/cdn/tab-mcp-client.min.js";
49
54
  </script>
50
55
  ```
51
56
 
@@ -87,6 +92,19 @@ sets them instead, `icons: []` sends none. At most 8: `https:` (or `http:`) URLs
87
92
  PNG, JPEG, GIF, WebP or ICO `data:` URIs up to 16 KiB (no inline SVG). They go only in
88
93
  `server/discover`. An icon on `localhost` reaches only an AI app on the same computer.
89
94
 
95
+ `app` is the app id: the `<app>` of the page's MCP address
96
+ `https://<relay>/s/<app>/mcp`, which every page of the app shares. It is 1 to 32
97
+ characters of `a-z`, `0-9` and `-`, not starting or ending with `-`; anything else is a
98
+ `TypeError`. Without `app`, the id is made from `server.name`: lower case, letters
99
+ without their marks, each run of other characters as one `-`, at most 32 characters
100
+ ("My Notes" gives `my-notes`, "Bücher" gives `bucher`). A name that leaves nothing (no
101
+ letter a-z and no digit) is a `TypeError` when `relay` is set: set `app` then. A relay
102
+ may reserve an app id for certain origins (`sites[].apps` in its
103
+ [configuration](https://github.com/ractive/tab-mcp/blob/main/docs/configuration.md)); a
104
+ page of another origin that names it is refused (`connect()` rejects, reason `policy`).
105
+ `appName` is a name for people (at most 64 characters), shown in "the page is not open"
106
+ answers.
107
+
90
108
  ### Tools
91
109
 
92
110
  `registerTool(tool, { signal, callers, exposedTo })` takes a tool in the shape of the
@@ -188,7 +206,7 @@ trial token that a script adds later counts for a `TabMcp` made after it.
188
206
  - A WebMCP call takes the same path as an AI app's: the arguments are checked against
189
207
  `inputSchema` (Chrome does not check them), a consequential tool asks (`onConfirm`, or
190
208
  the library's dialog, which names the caller "An agent in this browser"), and
191
- `toolcall` and `toolcallend` fire with `client: { kind: "webmcp" }`. "Allow until reload" is
209
+ `toolcall` and `toolcallend` fire with `client: { kind: "webmcp" }`. "Always allow" is
192
210
  never offered or applied for these calls: there is no identity to remember it for.
193
211
  - The call resolves with what `execute` returned, which the browser hands the agent as
194
212
  JSON text. An MCP result goes out as its `structuredContent` if it has one, else as
@@ -226,7 +244,7 @@ trial token that a script adds later counts for a `TabMcp` made after it.
226
244
  way round, once a name is mirrored, the page's own native `registerTool()` of that name
227
245
  fails: a page that registers tools natively itself leaves `webmcp` off or uses other
228
246
  names.
229
- - tab-mcp for Chrome offers mirrored tools like any page tool, since it cannot know
247
+ - The tab-mcp browser extension offers mirrored tools like any page tool, since it cannot know
230
248
  whether the AI app is also paired with the page, so an AI app connected to the page and
231
249
  to the extension sees such a tool twice.
232
250
 
@@ -432,7 +450,7 @@ instructions, as the recipe does with a delimited block.
432
450
  in a message is ignored, so the other end cannot pass for an AI app of the relay.
433
451
  - Without `serve`'s `onConfirm`, a consequential call through the port asks the page's
434
452
  `onConfirm` or the library's dialog, which names the caller "Example assistant (this
435
- site's assistant)" and never offers "Allow until reload".
453
+ site's assistant)" and never offers "Always allow".
436
454
  - `requestTimeoutMs` (300 s by default, as `createTunnelFetch`; below 2^31 ms) limits each
437
455
  request on the page's side: on expiry the call is aborted (`execute`'s signal and the
438
456
  question's), `toolcallend` says `cancelled`, a later answer of the tool is dropped, and
@@ -466,18 +484,12 @@ asks the user before every call ("Don't allow" or "Allow"), showing the AI app a
466
484
  arguments. A refusal reaches the AI app as an error result, and so does a call whose tool
467
485
  was removed while the user was asked.
468
486
 
469
- `alwaysAllow: true` adds "Allow until reload", which lets that tool run without asking for
470
- that AI app, with any arguments, until the page is reloaded or the app is disconnected.
471
- The connect dialog lists such tools under the app ("Runs without asking: …") with "Ask
472
- again", and a tool registered again unchanged (React's `useTool` on a remount) keeps its
473
- entry; one whose title or description changed is asked again. It is off by default: it
474
- lifts the only brake at run time, which is what a prompt injection needs, and the relay
475
- cannot help, since its one OAuth scope (`tools`) covers every tool of the page. Consent
476
- per tool is the page's. Turn it on only for tools whose calls the user need not check one
477
- by one.
487
+ `alwaysAllow: true` adds "Always allow", which lets that tool run without asking for that
488
+ AI app from then on; see [Tools that run without asking](#tools-that-run-without-asking).
489
+ It is off by default.
478
490
 
479
491
  Tools are called while the user is in the AI app, so the dialog often opens in a tab in
480
- the background. "Allow" and "Allow until reload" can be clicked only once the page has
492
+ the background. "Allow" and "Always allow" can be clicked only once the page has
481
493
  been visible and focused for 750 ms with the dialog open; leaving the page
482
494
  disables them and coming back starts the wait again, so the click that brings the page
483
495
  forward cannot approve. One confirmation is shown at a time; the others wait, the shown
@@ -502,8 +514,8 @@ Not when an `onConfirm` answers (the page's, or for a served port its own): it m
502
514
  anywhere, such as a side panel or the site's chat. Say where in the tool's own
503
515
  description if the AI app should know.
504
516
 
505
- Pass `onConfirm` to ask in your own UI (it is asked every time; remember answers there if
506
- you want to). Show the verified `client.host` next to the name the AI app declares, as the
517
+ Pass `onConfirm` to ask in your own UI (it is asked for every call the user has not
518
+ allowed, see [Tools that run without asking](#tools-that-run-without-asking)). Show the verified `client.host` next to the name the AI app declares, as the
507
519
  library's dialog does, since anyone can declare any name. Escape the arguments and the
508
520
  name as the dialog does with `escapeInvisible` from `@ractive-ch/tab-mcp-client/visible`
509
521
  (an entry of its own, not in the core):
@@ -535,6 +547,109 @@ outcome `unanswered`. Any other value, and a throw, is a refusal.
535
547
  `mcp.confirmInPage(request, { document })` is the library's own dialog, for an
536
548
  `onConfirm` that handles only some calls itself (`document` defaults to the global one).
537
549
 
550
+ ### Tools that run without asking
551
+
552
+ The user can let a consequential tool run without asking, for one connected AI app: one
553
+ tool at a time ("Always allow" this tool), or everything ("Allow everything, no questions
554
+ asked"). An allowed call runs at once, with the library's dialog and with your own
555
+ `onConfirm` alike: neither is asked. Only AI apps through the relay can be allowed; an
556
+ agent in the browser (WebMCP) and a served port have no grant to remember it for and are
557
+ always asked.
558
+
559
+ The option `alwaysAllow` decides what the library's dialogs offer:
560
+
561
+ | `alwaysAllow` | The confirmation offers | The connect dialog shows | Kept |
562
+ | ---------------- | -------------------------- | ------------------------------------- | -------------------------------------------- |
563
+ | unset or `false` | Don't allow, Allow | nothing (unless something is allowed) | in `storage`, for your own switches |
564
+ | `true` | … and "Always allow" | the switches under each app | in `storage`, until the app is disconnected |
565
+ | `"until-reload"` | … and "Allow until reload" | the switches under each app | in memory, until the page is reloaded |
566
+
567
+ With `true` and `storage: null`, nothing outlives the page either, and the button says
568
+ "Allow until reload". The confirmation never offers "allow everything": that is a
569
+ deliberate act in the connect dialog, not an answer to one question. In the connect
570
+ dialog, each connected app gets a switch per tool that asks (its title or name;
571
+ destructive ones marked) and "Allow everything, no questions asked", with a sentence on
572
+ what it means. The switches are checkboxes with `role="switch"` whose accessible names
573
+ name the app. A tool that is allowed but not registered right now (a page may offer some
574
+ tools only on some views) is listed by its name, as a switch that can only be turned
575
+ off. When the page does not offer allowing (`alwaysAllow` unset) but something is
576
+ allowed for an app (by your own switches), the connect dialog shows only that, as
577
+ switches that can only be turned off ("everything" only while it is on): the user can
578
+ see and end what runs without asking where they disconnect apps, and is never offered
579
+ more than the page chose to offer.
580
+
581
+ **What counts.** An allowed tool runs without asking as long as its title and
582
+ description are the ones the user allowed: a tool registered with another one is asked
583
+ again and leaves the list. A tool that is not registered for a while keeps its allowance
584
+ (a reload registers every tool again; a page may offer some only on some views).
585
+ "Everything" covers every tool, also ones registered later, changed ones and destructive
586
+ ones: that is why it is a switch of its own.
587
+
588
+ **Where it is kept, and when it ends.** In the page's `storage` (by default
589
+ `localStorage`), under the address secret's key with `#allowed` appended: the grant ids,
590
+ the tool names and the title and description the user saw, and a fingerprint of the
591
+ secret; no arguments, no results. An allowance ends with its grant, as the relay reports
592
+ it: the app is disconnected (in the page or elsewhere), "Disconnect all apps"
593
+ (`newAddress()`), the grant expired, the user signed out (identity binding). A dropped
594
+ connection, a reload or a page that has not connected yet keeps them. Tabs that share the
595
+ address share them, and a change in one counts in the others at once.
596
+
597
+ **Your own switches.** `@ractive-ch/tab-mcp-client/allowed` (an entry of its own, not in
598
+ the core) has the same allowances for a UI of your own, also with `alwaysAllow` unset:
599
+
600
+ ```ts
601
+ import { allowedTools } from "@ractive-ch/tab-mcp-client/allowed";
602
+
603
+ const allowed = allowedTools(mcp); // one object per TabMcp
604
+ function drawSwitches() {
605
+ list.replaceChildren(
606
+ ...mcp.grants.flatMap((grant) => [
607
+ ...allowed.tools().map((tool) =>
608
+ mySwitch(`${tool.title ?? tool.name}${tool.destructive ? " (destructive)" : ""}`,
609
+ allowed.has(grant.grantId, tool.name),
610
+ (on) => on ? allowed.allow(grant.grantId, tool.name) : allowed.ask(grant.grantId, tool.name)),
611
+ ),
612
+ mySwitch("Allow everything, no questions asked",
613
+ allowed.everything(grant.grantId),
614
+ (on) => allowed.setEverything(grant.grantId, on)),
615
+ ]),
616
+ );
617
+ }
618
+ allowed.onChange(drawSwitches); // allowances and tools
619
+ mcp.addEventListener("grantschange", drawSwitches);
620
+ ```
621
+
622
+ - `tools()`: the tools that ask (`consequentialHint`, callable through the relay), each
623
+ `{ name, title?, description, destructive }`.
624
+ - `has(grantId, name)`: whether a call runs without asking now. `list(grantId)`: the
625
+ names allowed one by one (one registered now with another title or description is
626
+ not in it). `everything(grantId)`. These only read, so they are safe while drawing.
627
+ - `allow(grantId, name)` (as the tool is registered now), `ask(grantId, name)`,
628
+ `setEverything(grantId, on)`, `forget(grantId)` (everything of that app asks again).
629
+ Allowing does nothing for an app that is not in `mcp.grants`. `ask` while
630
+ "everything" is on turns "everything" off for that app too, and leaves the other
631
+ tools allowed one by one as they are: asking again errs towards asking.
632
+ - `onChange(listener)` returns what stops it. `kept` says whether they outlive a reload.
633
+ The methods are bound: `const { allow, ask } = allowedTools(mcp)` works.
634
+ - In React, `useAllowedTools(grantId)` of `@ractive-ch/tab-mcp-client/react` returns
635
+ `{ tools (each with allowed), everything, allowedTools }` and renders again on a change.
636
+ - Without a bundler, `cdn/allowed.min.js` sits beside the CDN build's
637
+ `tab-mcp-client.min.js` and shares its chunks (one store with the dialogs); a page
638
+ that does not import it loads nothing of it. Take both from the same version:
639
+
640
+ ```js
641
+ import { TabMcp } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.18.0/cdn/tab-mcp-client.min.js";
642
+ import { allowedTools } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.18.0/cdn/allowed.min.js";
643
+ ```
644
+
645
+ **The risk.** An allowance outlives the user's attention: for up to the grant's 90 days,
646
+ calls run that nobody looks at. An AI app can be steered by text it reads (a web page, a
647
+ mail, a document), and an allowed tool is then the one that runs on its say. Offer it
648
+ for tools one would not want to check each time, whose worst call is cheap to undo; not
649
+ for tools that pay, send, delete or publish. "Everything" also covers tools the user has
650
+ not seen, and ones the page adds later. The relay cannot help: its one OAuth scope
651
+ (`tools`) covers every tool of the page, so consent per tool is the page's.
652
+
538
653
  ### Connecting and pairing
539
654
 
540
655
  1. The user clicks your button. `showConnectDialog()` connects (call it from the click
@@ -565,16 +680,18 @@ outcome `unanswered`. Any other value, and a throw, is a refusal.
565
680
  the end of the help leads to the guide with the rest (ChatGPT's Mac app, turning the
566
681
  Codex feature off, what to do when it fails). A page can link its own guide and give
567
682
  its own steps (`ui.setup`, see [Texts and help of the dialogs](#texts-and-help-of-the-dialogs)).
568
- The user adds the address to their AI app.
569
- 3. The AI app opens the relay's sign-in page in the browser. The dialog shows a 6-digit
570
- code with a Copy button, which the user types or pastes there. The code changes every
571
- 2 minutes and after each use.
683
+ The user adds the address to their AI app. It is the app's address
684
+ (`https://<relay>/s/<app>/mcp`), the same in every user's dialog.
685
+ 3. The AI app opens the relay's sign-in page in the browser. The dialog shows a code of
686
+ 8 letters (`XXXX-XXXX`) with a Copy button, which the user types or pastes there, in
687
+ any case, with or without the dash. The relay finds the page by it. The code changes
688
+ every 2 minutes and after each use.
572
689
  4. Once the AI app connects, the dialog says so at the top: a check mark, "Claude
573
690
  (claude.ai) is connected" (every connected app is named) and what to do next (close it and ask the app to use the
574
691
  page's tools); screen readers hear the same. The setup (address, code, help) moves
575
692
  behind "Connect another app", closed, so the next code does not appear in view; the
576
- connected app is listed with a Disconnect button (and the tools it may run without
577
- asking, with "Ask again"), and "Done" closes the dialog. A Disconnect the relay could
693
+ connected app is listed with a Disconnect button (and, with `alwaysAllow`, the
694
+ switches for what it may run without asking), and "Done" closes the dialog. A Disconnect the relay could
578
695
  not save says so in the list ("The relay could not save this. Try again.").
579
696
  Opened again while an app is connected, the dialog starts like this, with the focus
580
697
  on Done.
@@ -583,8 +700,7 @@ The relay makes a new code the moment one is entered, but the AI app connects on
583
700
  moment later. When the relay says the code was used (`reason: "used"` in the event
584
701
  `pairingcode`), the dialog shows "Code used. Waiting for your AI app…" instead of the new
585
702
  code, for up to 10 seconds; if no app connects by then, the new code appears. A code that
586
- replaces an expired or locked one (too many wrong tries), or one from a relay that does not
587
- say why, shows at once.
703
+ replaces an expired one, or one that comes without a reason, shows at once.
588
704
 
589
705
  Until an app is connected, the dialog offers no prominent button under the code: only a small
590
706
  "Close" at the bottom (and Escape). Closing it stops the code (`stopPairing()`); the page
@@ -593,57 +709,64 @@ shows the same address with a new code. While the dialog is open, calling it aga
593
709
  double click) opens no second one; the call resolves when that one closes. A call for another
594
710
  `document` (an iframe's, say) while it is open rejects with an `InvalidStateError`.
595
711
 
596
- The address stays the same across visits: the library keeps a secret per relay and page
597
- in `localStorage`, under `tab-mcp:secret:<relay origin>:<server.name>`, so two pages of one
598
- site with different server names get different addresses (set `storageKey` to choose the
599
- key yourself; the name is URI-encoded, and renaming it changes the address). The key of 0.4
600
- and older, `tab-mcp:secret:<relay origin>`, is not read: a visitor whose last visit predates
601
- 0.5 gets a new address and pairs their AI apps again.
602
-
603
- "New address" in the dialog (at the end of the setup, below the code, with a line on what
604
- it does; not next to Copy, since with no app connected it changes the address at once)
605
- calls `newAddress()`, which disconnects every
606
- app and makes a new address; when apps are connected, the dialog asks first. It first
607
- takes the old address back: it connects with the stored secret, and the relay revokes
608
- every grant of the address in
609
- the same step (`hello.revokeAll`), whether the page was connected or not. Then it makes
610
- the new secret, clears `grants`, and connects with it if the page was connected,
611
- connecting or reconnecting (or taken over). A page that never had a secret makes one
612
- without connecting. If the old address cannot be taken back (the relay is unreachable,
613
- or someone takes it over again first), it rejects and keeps the old secret, so calling
614
- it again tries again. A second call while it runs returns the same promise; `connect()`
615
- meanwhile waits for it and then connects with the new address. The relay's
616
- sign-in page points users to it when someone else may be guessing codes. A page with its
617
- own UI calls `newAddress()` from a click. Connected apps keep working after a reload once the page connects
712
+ The address is the app's: it is the same for every visitor and every visit. What tells
713
+ one user's page from another's is the address secret: the library keeps one per relay
714
+ and page in `localStorage`, under `tab-mcp:secret:<relay origin>:<server.name>` (set
715
+ `storageKey` to choose the key yourself; the name is URI-encoded). The relay keys the
716
+ page's session and the AI apps paired with it by a hash of the app id and that secret
717
+ (the address id), which is in no URL. A paired AI app therefore reaches the page again
718
+ after a reload and on later visits. A browser without the secret (another profile,
719
+ cleared storage, a renamed `server.name` without `storageKey`) is a page nobody has
720
+ paired with yet, and so is the same secret under another app id: changing `app`, or a
721
+ `server.name` that `app` is made from, means every AI app pairs again. Two pages of one
722
+ site with different server names keep different secrets; their addresses differ when
723
+ their app ids do. The key of 0.4 and older, `tab-mcp:secret:<relay origin>`, is not
724
+ read: a visitor whose last visit predates 0.5 pairs their AI apps again.
725
+
726
+ "Disconnect all apps" in the dialog (at the end of the setup, below the code, with a
727
+ line on what it does) calls `newAddress()`, which disconnects every app and makes a new
728
+ secret; when apps are connected, the dialog asks first. The method has its name from
729
+ when every page had an address of its own: the address the user sees does not change,
730
+ and each AI app connects again at the same address with a new code. It first takes the
731
+ page back: it connects with the stored secret, and the relay revokes every grant made
732
+ for it in the same step (`hello.revokeAll`), whether the page was connected or not.
733
+ Then it makes the new secret, clears `grants`, and connects with it if the page was
734
+ connected, connecting or reconnecting (or taken over). A page that never had a secret
735
+ makes one without connecting. If the page cannot be taken back (the relay is
736
+ unreachable, or someone takes it over again first), it rejects and keeps the old secret,
737
+ so calling it again tries again. A second call while it runs returns the same promise;
738
+ `connect()` meanwhile waits for it and then connects with the new secret. A page with
739
+ its own UI calls `newAddress()` from a click. Connected apps keep working after a reload once the page connects
618
740
  again; while the page is closed, they get "the page is not open".
619
741
 
620
- When another tab or program connects with the same address, it takes the address over:
742
+ When another tab or program connects with the same secret, it takes the page's place:
621
743
  the page gets `statechange` to `disconnected` with reason `replaced` at once, then the
622
744
  event `replaced`,
623
745
  and does not reconnect by itself. Tabs of the same page say on a `BroadcastChannel` (per
624
- relay and storage key; it carries the address id, which is part of the address, never
625
- the secret) when the relay accepted their session, so `replaced` says which it probably
626
- was:
746
+ relay and storage key; it carries a hash of the secret, never the secret) when the relay
747
+ accepted their session, so `replaced` says which it probably was:
627
748
 
628
749
  - `event.detail.sibling` is `true`: a tab of the same page in this browser said within
629
- the last 10 seconds that it claimed this tab's address, after this tab's own session
630
- started (a claim of another address, or one heard while this tab was still connecting,
631
- does not count; a claim without an address, from a tab still on 0.15 or older, does). That message usually comes just after the takeover, so the
750
+ the last 10 seconds that it connected with this tab's secret, after this tab's own
751
+ session started (a claim with another secret's hash, or one heard while this tab was
752
+ still connecting, does not count; a claim without a hash, from a tab still on
753
+ 0.15 or older, does). That message usually comes just after the takeover, so the
632
754
  library waits up to a second for it, and `replaced` may come that much after
633
755
  the `statechange`. The usual cause, and harmless. Once the page has opened the default
634
756
  dialog, the library shows "Opened in another tab".
635
757
  - `false`: none did (or the browser has no `BroadcastChannel`). It may be a program with
636
- a copy of the address secret, and the AI apps paired with the address now talk to it.
637
- The library shows "Another tab or program took over this page" with "New address".
758
+ a copy of the address secret, and the AI apps paired with the page now talk to it.
759
+ The library shows "Another tab or program took over this page" with "Disconnect all
760
+ apps".
638
761
 
639
762
  After a takeover, `newAddress()` (from the `replaced` listener, before it, or later, also
640
- after a reload) takes the address back as above and makes the new address only once the
641
- relay confirmed that no grant is left. If the address is taken over again before that,
763
+ after a reload) takes the page back as above and makes the new secret only once the
764
+ relay confirmed that no grant is left. If the page is taken over again before that,
642
765
  it rejects with an error whose `reason` is `"replaced"` and keeps the old secret, so
643
- calling it again takes it back again. A relay of 0.4 or older cannot take an address
766
+ calling it again takes it back again. A relay of 0.4 or older cannot take a page
644
767
  back: `newAddress()` rejects there with `reason` `"policy"`. When the takeover ended a
645
- session of this page, it then connects with the new address; the default notice opens
646
- the connect dialog to add it to the AI apps.
768
+ session of this page, it then connects with the new secret; the default notice opens
769
+ the connect dialog, where the user pairs the AI apps again.
647
770
 
648
771
  The default dialog closes when the page is replaced, and the notice appears also when the
649
772
  dialog is closed, but only once the page has opened the dialog: a page that connects on
@@ -653,8 +776,8 @@ with its own UI shows the same from `replaced`:
653
776
  ```ts
654
777
  mcp.addEventListener("replaced", (e) => {
655
778
  if (e.detail.sibling) showNote("Opened in another tab.");
656
- else showWarning("Another tab or program took over this page's address.", {
657
- action: "New address",
779
+ else showWarning("Another tab or program took over this page.", {
780
+ action: "Disconnect all apps",
658
781
  onClick: () => mcp.newAddress(), // from the click
659
782
  });
660
783
  });
@@ -663,12 +786,12 @@ mcp.addEventListener("replaced", (e) => {
663
786
  Script on the page's origin can post on the channel and make a takeover look like a
664
787
  sibling; such script can read the secret anyway, so `sibling` is a hint, not a proof.
665
788
 
666
- ### Keeping the address safe
789
+ ### Keeping the address secret safe
667
790
 
668
- Whoever has the address secret can take over the page's address from anywhere, and the
669
- AI apps paired with it then send their arguments to them and get their tool descriptions
670
- and results, until the page gets a new address. They get no token and cannot pair a new
671
- app without a code. Script on your origin (cross-site scripting, a compromised
791
+ Whoever has the address secret can take the page's place from anywhere, and the AI apps
792
+ paired with the page then send their arguments to them and get their tool descriptions
793
+ and results, until the page makes a new secret (`newAddress()`). They get no token and
794
+ cannot pair a new app without a code. Script on your origin (cross-site scripting, a compromised
672
795
  third-party script, another page on the same origin) or access to the device can copy it
673
796
  ([threat model](https://github.com/ractive/tab-mcp/blob/main/docs/threat-model.md), A4).
674
797
 
@@ -681,9 +804,10 @@ third-party script, another page on the same origin) or access to the device can
681
804
  shared profile, or in a web app with accounts that pairs by code, the next user of the
682
805
  page gets the AI apps the previous one paired. Call `newAddress()` when the user logs
683
806
  out, or use identity binding.
684
- - The page origin that the relay's sign-in page shows is what the page's browser
685
- reported; a program can claim any origin. Do not tell users it proves which page they
686
- pair with.
807
+ - The relay's sign-in page names the AI app and the app id of the address, not the page
808
+ or its origin: the code alone says which page is paired. Whoever types a user's code
809
+ on that page connects their own AI app to the user's page, so tell users never to
810
+ pass their code on. With identity binding there is no code to pass on.
687
811
 
688
812
  When the connection breaks (reason `network`, `heartbeat` or `shutdown`: a dropped
689
813
  network, a phone pausing the tab in the background, a relay restart; close codes 1001,
@@ -694,8 +818,8 @@ come back at once), and at once when the tab comes back to the front or the netw
694
818
  returns. Meanwhile `state` is `reconnecting` (while it waits and while it makes an
695
819
  attempt), `reconnecting` says which attempt is next and when, and `statechange` fires
696
820
  for each attempt it schedules; only the `statechange` that leaves `connected` carries the
697
- `reason` ([Your own UI](#your-own-ui)). Calling `connect()` meanwhile tries at once. It never reconnects after `disconnect()`, a new address,
698
- another tab taking over the address (`replaced`), an expired or idle session, or a
821
+ `reason` ([Your own UI](#your-own-ui)). Calling `connect()` meanwhile tries at once. It never reconnects after `disconnect()`, `newAddress()`,
822
+ another tab taking the page's place (`replaced`), an expired or idle session, or a
699
823
  refusal by the relay, and an attempt the relay refuses stops it (an unreachable relay is
700
824
  tried again); the event `error` then says why, with `state` already `disconnected`, just
701
825
  before the `statechange` to `disconnected`, also when a `connect()` of the page waits on
@@ -726,15 +850,17 @@ if (localStorage.getItem(key) === "1") {
726
850
  ```
727
851
 
728
852
  `resume: true` lets `connect()` run without a click. Offer a way to turn it off. With
729
- two tabs of the page open, the newer one takes the address over: listen for `replaced`
853
+ two tabs of the page open, the newer one takes the older one's place: listen for `replaced`
730
854
  (above) to tell the older tab why it went off.
731
855
 
732
856
  ### Identity binding (no code)
733
857
 
734
858
  On a relay that pairs by `oidc` ([identity binding](https://github.com/ractive/tab-mcp/blob/main/docs/configuration.md#identity-binding)),
735
859
  the user signs in to the AI app's connection with the account they use on your page,
736
- and no code is shown. Your backend proves who is signed in: give the library a function
737
- that fetches a short-lived tab assertion for the page's address.
860
+ and no code is shown. The relay pairs the AI app with the app's page whose user is that
861
+ person and whose "Connect your AI app" dialog is open. Your backend proves who is signed
862
+ in: give the library a function that fetches a short-lived tab assertion for the page's
863
+ address. The address is the app's, so the assertion's `aud` names the app, not one page.
738
864
 
739
865
  ```ts
740
866
  const mcp = new TabMcp({
@@ -777,7 +903,7 @@ Instead of `showConnectDialog()`, use the methods, properties and events below.
777
903
  |---|---|
778
904
  | `connect(options?)` | resolves with the session (`SessionInfo`) |
779
905
  | `disconnect()` | ends the session at once |
780
- | `newAddress()` | resolves once the new address is in use (connected again if it was on) |
906
+ | `newAddress()` | disconnects every app ("Disconnect all apps"); resolves once the new secret is in use (connected again if it was on) |
781
907
  | `startPairing()`, `stopPairing()` | codes come only while pairing is on |
782
908
  | `revoke(grantId)` | resolves once the relay removed the grant |
783
909
  | `signOut()` | resolves once the relay removed the grants (identity binding) |
@@ -790,16 +916,16 @@ the session ends after the message was sent and before the relay answered, and w
790
916
  or may not have done it, and `grants` says so once the page is connected again. They
791
917
  also reject with the relay's refusal of that message, an `Error` whose `code` is
792
918
  `store_unavailable` (the relay could not save the change: try again) or `unknown_id`.
793
- A relay after 0.10.3 names the message it answers (`for`, and `grantId` for a
919
+ A relay after 0.12.0 names the message it answers (`for`, and `grantId` for a
794
920
  revocation), so with several revocations pending only the one it answers rejects; an
795
921
  older relay's refusal rejects every pending `revoke()` and `signOut()`. When the relay
796
922
  does not know a grant the page lists (it expired), the grant leaves `grants` (with
797
923
  `grantschange`) and its `revoke()` resolves.
798
924
 
799
925
  With a relay, `newAddress()` rejects with an error whose `addressChanged` says what happened: `false`
800
- when the old address could not be taken back (it is kept with its grants; call
801
- `newAddress()` again), `true` when the address changed and only connecting with the new
802
- one failed (call `connect()`).
926
+ when the page could not be taken back (the old secret is kept with its grants; call
927
+ `newAddress()` again), `true` when the secret changed, so every app is disconnected, and
928
+ only connecting with the new one failed (call `connect()`).
803
929
 
804
930
  The properties are `state` (`disconnected`, `connecting`, `connected`, `reconnecting`),
805
931
  `session` (while connected; `session.address` is the MCP address, `session.appName` the
@@ -1017,7 +1143,7 @@ function TodoList() {
1017
1143
  again only when its name, title, description, input or output schema or annotations
1018
1144
  change, or `options.callers` or `options.exposedTo` (by value: a new array with the same
1019
1145
  entries is no change; [which callers see a tool](#which-callers-see-a-tool),
1020
- [WebMCP](#webmcp), whose `webmcp` on the provider turns it on). Registered again unchanged, a tool allowed until reload stays
1146
+ [WebMCP](#webmcp), whose `webmcp` on the provider turns it on). Registered again unchanged, an allowed tool stays
1021
1147
  allowed. StrictMode's double mount registers it once at a time. A duplicate name or an
1022
1148
  invalid tool is thrown from the component's render, for an error boundary. Tools that
1023
1149
  read state right after another tool changed it should read it from a store (as the
@@ -1074,15 +1200,15 @@ from a CDN uses the core API. [examples/react-todo](https://github.com/ractive/t
1074
1200
  is a complete todo app.
1075
1201
 
1076
1202
  For end-to-end tests of a page's tools, `@ractive-ch/tab-mcp/testing` (the relay's
1077
- package) starts a relay in the test process and issues a token for the page's address
1078
- without pairing; see the relay's [README](https://github.com/ractive/tab-mcp/tree/main/packages/tab-mcp#testing-a-pages-tools).
1203
+ package) starts a relay in the test process and issues a token for the page connected
1204
+ at the app's address without pairing; see the relay's [README](https://github.com/ractive/tab-mcp/tree/main/packages/tab-mcp#testing-a-pages-tools).
1079
1205
 
1080
1206
  ## Security
1081
1207
 
1082
1208
  Connecting an AI app to a page means trusting that page, as with any MCP server. Keep
1083
1209
  cross-site scripting out of your page: a script that reads the address secret can take
1084
- over the address. The library sends the secret only over `https:`/`wss:` (plain `http:`
1085
- only to `localhost`). See
1210
+ the page's place at the relay. The library sends the secret only over `https:`/`wss:`
1211
+ (plain `http:` only to `localhost`). See
1086
1212
  [SECURITY.md](https://github.com/ractive/tab-mcp/blob/main/SECURITY.md) and the
1087
1213
  [threat model](https://github.com/ractive/tab-mcp/blob/main/docs/threat-model.md).
1088
1214
 
@@ -1091,7 +1217,7 @@ only to `localhost`). See
1091
1217
  - [Live examples](https://ractive.ch/tab-mcp/)
1092
1218
  - [Example: a React todo app](https://github.com/ractive/tab-mcp/tree/main/examples/react-todo)
1093
1219
  - [Tab–relay protocol](https://github.com/ractive/tab-mcp/blob/main/docs/protocol.md)
1094
- - [Changelog](https://github.com/ractive/tab-mcp/blob/main/CHANGELOG.md)
1220
+ - [Changelog](https://github.com/ractive/tab-mcp/blob/main/packages/tab-mcp-client/CHANGELOG.md), also in the package as `CHANGELOG.md`
1095
1221
 
1096
1222
  ## Licence
1097
1223
 
package/address.d.ts CHANGED
@@ -1,14 +1,14 @@
1
1
  /**
2
- * The address id in the `/tab` URL (DEC-098): a load balancer in front of
3
- * several relays routes every request of one address to one instance by it.
4
- * Part of the lazily loaded chunk (DEC-035), not the core.
2
+ * A hash of the page's secret: what the tabs of one page tell each other by
3
+ * when one of them takes over (DEC-095), in place of the secret. It is not the
4
+ * relay's address id, which is of the app and the secret (DEC-196), and never
5
+ * part of a URL. Part of the lazily loaded chunk
6
+ * (DEC-035), not the core.
5
7
  */
6
8
  /**
7
- * The address id of a secret, as the relay derives it (DEC-027):
9
+ * The hash of a secret that the tabs of a page name it by:
8
10
  * base32(sha256(secret)). `undefined` where Web Crypto is missing (`null`: a
9
- * page on plain http other than localhost) or fails; the URL then has no id,
10
- * which one relay accepts and only a load balancer cannot route.
11
+ * page on plain http other than localhost) or fails; a replaced tab then
12
+ * cannot tell a sibling tab from an impostor.
11
13
  */
12
14
  export declare function addressIdOf(secret: string, subtle?: SubtleCrypto | null): Promise<string | undefined>;
13
- /** The `/tab` URL with `?a=<id>`. Never the secret: URLs end up in logs. */
14
- export declare function withAddress(url: string, address: string | undefined): string;
package/allowed.d.ts ADDED
@@ -0,0 +1,28 @@
1
+ /**
2
+ * `@ractive-ch/tab-mcp-client/allowed`: the tools that run without asking,
3
+ * per connected AI app, for a page that draws its own switches ("always
4
+ * allow this tool", "allow everything, no questions asked"). The library's
5
+ * dialogs use the same allowances. An entry of its own, out of the core
6
+ * (DEC-200).
7
+ *
8
+ * ```ts
9
+ * import { allowedTools } from "@ractive-ch/tab-mcp-client/allowed";
10
+ * const allowed = allowedTools(mcp);
11
+ * for (const tool of allowed.tools()) {
12
+ * box.checked = allowed.has(grant.grantId, tool.name);
13
+ * box.onchange = () => box.checked ? allowed.allow(grant.grantId, tool.name) : allowed.ask(grant.grantId, tool.name);
14
+ * }
15
+ * ```
16
+ */
17
+ import { type AllowedTool, type AllowedTools } from "./always-allowed.js";
18
+ import type { TabMcp } from "./tab-mcp.js";
19
+ export type { AllowedTool, AllowedTools };
20
+ /**
21
+ * The allowances of `mcp`: one object per `TabMcp`, the same for every
22
+ * call. Kept in its `storage` next to the address secret until the app is
23
+ * disconnected (in memory with `storage: null` or `alwaysAllow:
24
+ * "until-reload"`); they end with the app's grant, as the relay reports it,
25
+ * and with `newAddress()`. A call they allow runs without asking, with the
26
+ * library's dialog and with the page's own `onConfirm` alike.
27
+ */
28
+ export declare function allowedTools(mcp: TabMcp): AllowedTools;
package/allowed.js ADDED
@@ -0,0 +1,14 @@
1
+ import {
2
+ allowedFor
3
+ } from "./index-h8b3dc5p.js";
4
+
5
+ // src/allowed.ts
6
+ function allowedTools(mcp) {
7
+ return allowedFor(mcp);
8
+ }
9
+ export {
10
+ allowedTools
11
+ };
12
+
13
+ //# debugId=F620A76B3CA348AE64756E2164756E21
14
+ //# sourceMappingURL=allowed.js.map
package/allowed.js.map ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/allowed.ts"],
4
+ "sourcesContent": [
5
+ "/**\n * `@ractive-ch/tab-mcp-client/allowed`: the tools that run without asking,\n * per connected AI app, for a page that draws its own switches (\"always\n * allow this tool\", \"allow everything, no questions asked\"). The library's\n * dialogs use the same allowances. An entry of its own, out of the core\n * (DEC-200).\n *\n * ```ts\n * import { allowedTools } from \"@ractive-ch/tab-mcp-client/allowed\";\n * const allowed = allowedTools(mcp);\n * for (const tool of allowed.tools()) {\n * box.checked = allowed.has(grant.grantId, tool.name);\n * box.onchange = () => box.checked ? allowed.allow(grant.grantId, tool.name) : allowed.ask(grant.grantId, tool.name);\n * }\n * ```\n */\n\nimport {\n\ttype AllowedTool,\n\ttype AllowedTools,\n\tallowedFor,\n} from \"./always-allowed.ts\";\nimport type { TabMcp } from \"./tab-mcp.ts\";\n\nexport type { AllowedTool, AllowedTools };\n\n/**\n * The allowances of `mcp`: one object per `TabMcp`, the same for every\n * call. Kept in its `storage` next to the address secret until the app is\n * disconnected (in memory with `storage: null` or `alwaysAllow:\n * \"until-reload\"`); they end with the app's grant, as the relay reports it,\n * and with `newAddress()`. A call they allow runs without asking, with the\n * library's dialog and with the page's own `onConfirm` alike.\n */\nexport function allowedTools(mcp: TabMcp): AllowedTools {\n\treturn allowedFor(mcp);\n}\n"
6
+ ],
7
+ "mappings": ";;;;;AAkCO,SAAS,YAAY,CAAC,KAA2B;AAAA,EACvD,OAAO,WAAW,GAAG;AAAA;",
8
+ "debugId": "F620A76B3CA348AE64756E2164756E21",
9
+ "names": []
10
+ }