@ractive-ch/tab-mcp-client 0.17.0 → 0.18.1-rc.1

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 (47) hide show
  1. package/CHANGELOG.md +87 -0
  2. package/README.md +130 -19
  3. package/allowed.d.ts +28 -0
  4. package/allowed.js +14 -0
  5. package/allowed.js.map +10 -0
  6. package/always-allowed.d.ts +156 -22
  7. package/cdn/allowed.min.js +4 -0
  8. package/cdn/allowed.min.js.map +10 -0
  9. package/cdn/confirm-d722a9eb.min.js +4 -0
  10. package/cdn/confirm-d722a9eb.min.js.map +10 -0
  11. package/cdn/connect-x6ws6wqt.min.js +6 -0
  12. package/cdn/connect-x6ws6wqt.min.js.map +12 -0
  13. package/cdn/{index-t33bb2g4.min.js → tab-mcp-client-2vx9mcww.min.js} +20 -9
  14. package/cdn/tab-mcp-client-2vx9mcww.min.js.map +12 -0
  15. package/cdn/tab-mcp-client-5j3brdf3.min.js +5 -0
  16. package/cdn/tab-mcp-client-5j3brdf3.min.js.map +10 -0
  17. package/cdn/tab-mcp-client.min.js +3 -3
  18. package/cdn/tab-mcp-client.min.js.map +4 -4
  19. package/{confirm-vj2zbq4w.js → confirm-bqfdrx3f.js} +31 -18
  20. package/confirm-bqfdrx3f.js.map +10 -0
  21. package/confirm.d.ts +49 -20
  22. package/{connect-9pefy0xe.js → connect-ztsgybpq.js} +113 -16
  23. package/connect-ztsgybpq.js.map +10 -0
  24. package/connect.d.ts +2 -2
  25. package/dialog.d.ts +1 -1
  26. package/{index-qw8qy5ed.js → index-c1c266tm.js} +27 -89
  27. package/index-c1c266tm.js.map +11 -0
  28. package/index-s31xrfa2.js +267 -0
  29. package/index-s31xrfa2.js.map +10 -0
  30. package/index.js +16 -19
  31. package/index.js.map +4 -4
  32. package/package.json +7 -2
  33. package/react.d.ts +19 -0
  34. package/react.js +30 -1
  35. package/react.js.map +3 -3
  36. package/secret.d.ts +6 -0
  37. package/strings.d.ts +12 -3
  38. package/tab-mcp.d.ts +5 -4
  39. package/types.d.ts +16 -7
  40. package/cdn/confirm-mqmvsxg1.min.js +0 -4
  41. package/cdn/confirm-mqmvsxg1.min.js.map +0 -10
  42. package/cdn/connect-c7wn48yp.min.js +0 -6
  43. package/cdn/connect-c7wn48yp.min.js.map +0 -12
  44. package/cdn/index-t33bb2g4.min.js.map +0 -13
  45. package/confirm-vj2zbq4w.js.map +0 -10
  46. package/connect-9pefy0xe.js.map +0 -10
  47. package/index-qw8qy5ed.js.map +0 -12
package/CHANGELOG.md CHANGED
@@ -6,6 +6,91 @@ the Git tag `client-v<version>`. The format follows
6
6
  [Semantic Versioning](https://semver.org/). The relay has its own
7
7
  [changelog](https://github.com/ractive/tab-mcp/blob/main/packages/tab-mcp/CHANGELOG.md).
8
8
 
9
+ ## [0.18.1-rc.1][client-0.18.1-rc.1] - 2026-11-20
10
+
11
+ ### Fixed
12
+
13
+ - **The confirmation chunk's `confirmInPage` works with a host of the caller's own
14
+ again.** Code that loads the built confirmation chunk (`confirm-<hash>.js`) and calls
15
+ its `confirmInPage(mcp, request, document, options)` with a stand-in for the `TabMcp`
16
+ (a desktop app's own MCP endpoint, say) broke in 0.18.0, which the 0.18.0 entry did
17
+ not say:
18
+ - it read the internal `_allowed` of the host, so a host without it threw;
19
+ - its fourth argument became the dialog texts (`ui`) alone, so the 0.17 options
20
+ `{ alwaysAllow, ui, allowDelayMs }` were silently ignored: no third button per
21
+ call, no translated texts, no other delay.
22
+
23
+ Now the fourth argument is again `{ alwaysAllow?, ui?, allowDelayMs? }`, as in 0.17.
24
+ A host needs only `grants`; it may send `grantschange` (any event: the allowances
25
+ are then pruned against `grants` as they are, whatever the event carries). It needs
26
+ no `_allowed` and no `session`. For a host that is not a `TabMcp`, nothing is
27
+ allowed or kept unless the call offers it with `alwaysAllow`; then the button says
28
+ "Allow until reload" (`true` and `"until-reload"` alike: nothing of a stand-in
29
+ outlives a reload), and an allowance is kept in memory for the host's grants only,
30
+ until a reload or until its grant leaves `grants`, and applies to that app's later
31
+ calls of the tool. A call counts as allowed only while its grant is in the host's
32
+ `grants` at that moment, also without an event. For a `TabMcp`, `alwaysAllow`
33
+ overrides the page's option for that call. As since 0.13, only a client with
34
+ `kind: "relay"` can be allowed. Hosts that added `_allowed` or `session` for 0.18.0
35
+ can drop them; an `_allowed` that is not a `TabMcp`'s (such as that workaround's)
36
+ now makes the host a stand-in, so pass `alwaysAllow` to keep offering the button.
37
+ `TabMcp.confirmInPage(request, { document })` is unchanged.
38
+
39
+ ### Changed
40
+
41
+ - `allowedTools(mcp).has(grantId, name)`, and a call, count an allowance only while
42
+ the app is in `mcp.grants`: before the first connect after a reload, `has` is
43
+ `false` (the allowance is still kept, `list` shows it). Calls only come while
44
+ connected, so for them nothing changes.
45
+
46
+ ## [0.18.0][client-0.18.0] - 2026-11-20
47
+
48
+ ### Added
49
+
50
+ - **`@ractive-ch/tab-mcp-client/allowed`**, an entry of its own (not in the core):
51
+ `allowedTools(mcp)` returns the tools that run without asking, per connected AI app,
52
+ for a page that draws its own switches: `tools()` (the tools that ask, each with
53
+ `destructive`), `has`, `list`, `allow`, `ask`, `everything`, `setEverything`,
54
+ `forget`, `onChange` and `kept`. Types `AllowedTools`, `AllowedTool` (DEC-200). It
55
+ works with `alwaysAllow` unset too, kept in `storage`. Without a bundler:
56
+ `cdn/allowed.min.js` beside `cdn/tab-mcp-client.min.js` (package export
57
+ `./cdn/allowed`), sharing its chunks; a page that does not import it loads nothing
58
+ more.
59
+ - **"Allow everything, no questions asked"** per AI app: every tool runs without asking,
60
+ also ones registered later, changed and destructive ones.
61
+ - **Switches in the connect dialog**: under each connected app, a switch per tool that
62
+ asks (destructive ones marked) and "Allow everything, no questions asked" with a
63
+ sentence on what it means; checkboxes with `role="switch"` whose accessible names name
64
+ the app. Tools allowed but not registered right now are listed by name, to turn off.
65
+ Without `alwaysAllow`, only what is allowed for that app is shown, as switches that can
66
+ only be turned off. The methods of `allowedTools(mcp)` are bound; `ask` while
67
+ "everything" is on turns "everything" off for that app.
68
+ - `useAllowedTools(grantId)` in `@ractive-ch/tab-mcp-client/react`: the tools that ask,
69
+ each with `allowed`, `everything` and the `allowedTools` object to change them.
70
+ - `alwaysAllow: "until-reload"`.
71
+ - `ui.strings`: `alwaysAllow`, `alwaysAllowNote`, `destructive`, `allowToolApp`,
72
+ `allowDestructiveToolApp`, `allowEverything`, `allowEverythingApp`,
73
+ `allowEverythingNote`.
74
+
75
+ ### Changed
76
+
77
+ - **`alwaysAllow: true` keeps allowances until the app is disconnected**, in `storage`
78
+ under the secret's key with `#allowed` appended (grant ids, tool names, the title and
79
+ description the user saw, a fingerprint of the secret; no arguments). They end when
80
+ the relay reports the grant gone (disconnected, "Disconnect all apps", expired, signed
81
+ out), not on a dropped connection or a reload. With `storage: null` they are kept in
82
+ memory. `alwaysAllow: "until-reload"` is the old behaviour.
83
+ - **The confirmation's third button** says "Always allow" with `alwaysAllow: true`, and
84
+ "Allow until reload" with `"until-reload"` or `storage: null`, each with its own note.
85
+ - **An allowed call no longer reaches the page's own `onConfirm`**: it runs without
86
+ asking. React's provider always installs an `onConfirm`, so this holds there too.
87
+ - **A tool that is unregistered keeps its allowance** (a reload registers every tool
88
+ again); one registered again with another title or description is asked again, as
89
+ before.
90
+ - `ui.strings`: `runsWithoutAsking` is the heading over the switches ("Runs without
91
+ asking", without `{tools}`); `askAgain` and `askAgainApp` are gone ("Ask again" is
92
+ replaced by the switches).
93
+
9
94
  ## [0.17.0][client-0.17.0] - 2026-11-19
10
95
 
11
96
  ### Breaking
@@ -822,6 +907,8 @@ First alpha of the browser library, on the npm dist-tag `alpha`.
822
907
  `<script type="module">` under `@ractive-ch/tab-mcp-client/cdn`.
823
908
  - The connect dialog shows the pairing code from the relay.
824
909
 
910
+ [client-0.18.1-rc.1]: https://github.com/ractive/tab-mcp/releases/tag/client-v0.18.1-rc.1
911
+ [client-0.18.0]: https://github.com/ractive/tab-mcp/releases/tag/client-v0.18.0
825
912
  [client-0.17.0]: https://github.com/ractive/tab-mcp/releases/tag/client-v0.17.0
826
913
  [client-0.16.2]: https://github.com/ractive/tab-mcp/releases/tag/client-v0.16.2
827
914
  [client-0.16.1]: https://github.com/ractive/tab-mcp/releases/tag/client-v0.16.1
package/README.md CHANGED
@@ -15,7 +15,7 @@ How the library, the relay and the tab-mcp browser extension fit together, with
15
15
  picture:
16
16
  [How the parts fit together](https://github.com/ractive/tab-mcp#how-the-parts-fit-together).
17
17
 
18
- **Status: 0.17.0.** Until 1.0, a new minor version can still change the API. Which AI apps
18
+ **Status: 0.18.1-rc.1.** Until 1.0, a new minor version can still change the API. Which AI apps
19
19
  work is listed in [compatibility](https://github.com/ractive/tab-mcp/blob/main/docs/compatibility.md).
20
20
 
21
21
  ## You need a relay
@@ -50,7 +50,7 @@ Or without a bundler, from a CDN as an ES module:
50
50
 
51
51
  ```html
52
52
  <script type="module">
53
- import { TabMcp } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.17.0/cdn/tab-mcp-client.min.js";
53
+ import { TabMcp } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.18.1-rc.1/cdn/tab-mcp-client.min.js";
54
54
  </script>
55
55
  ```
56
56
 
@@ -206,7 +206,7 @@ trial token that a script adds later counts for a `TabMcp` made after it.
206
206
  - A WebMCP call takes the same path as an AI app's: the arguments are checked against
207
207
  `inputSchema` (Chrome does not check them), a consequential tool asks (`onConfirm`, or
208
208
  the library's dialog, which names the caller "An agent in this browser"), and
209
- `toolcall` and `toolcallend` fire with `client: { kind: "webmcp" }`. "Allow until reload" is
209
+ `toolcall` and `toolcallend` fire with `client: { kind: "webmcp" }`. "Always allow" is
210
210
  never offered or applied for these calls: there is no identity to remember it for.
211
211
  - The call resolves with what `execute` returned, which the browser hands the agent as
212
212
  JSON text. An MCP result goes out as its `structuredContent` if it has one, else as
@@ -450,7 +450,7 @@ instructions, as the recipe does with a delimited block.
450
450
  in a message is ignored, so the other end cannot pass for an AI app of the relay.
451
451
  - Without `serve`'s `onConfirm`, a consequential call through the port asks the page's
452
452
  `onConfirm` or the library's dialog, which names the caller "Example assistant (this
453
- site's assistant)" and never offers "Allow until reload".
453
+ site's assistant)" and never offers "Always allow".
454
454
  - `requestTimeoutMs` (300 s by default, as `createTunnelFetch`; below 2^31 ms) limits each
455
455
  request on the page's side: on expiry the call is aborted (`execute`'s signal and the
456
456
  question's), `toolcallend` says `cancelled`, a later answer of the tool is dropped, and
@@ -484,18 +484,12 @@ asks the user before every call ("Don't allow" or "Allow"), showing the AI app a
484
484
  arguments. A refusal reaches the AI app as an error result, and so does a call whose tool
485
485
  was removed while the user was asked.
486
486
 
487
- `alwaysAllow: true` adds "Allow until reload", which lets that tool run without asking for
488
- that AI app, with any arguments, until the page is reloaded or the app is disconnected.
489
- The connect dialog lists such tools under the app ("Runs without asking: …") with "Ask
490
- again", and a tool registered again unchanged (React's `useTool` on a remount) keeps its
491
- entry; one whose title or description changed is asked again. It is off by default: it
492
- lifts the only brake at run time, which is what a prompt injection needs, and the relay
493
- cannot help, since its one OAuth scope (`tools`) covers every tool of the page. Consent
494
- per tool is the page's. Turn it on only for tools whose calls the user need not check one
495
- 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.
496
490
 
497
491
  Tools are called while the user is in the AI app, so the dialog often opens in a tab in
498
- 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
499
493
  been visible and focused for 750 ms with the dialog open; leaving the page
500
494
  disables them and coming back starts the wait again, so the click that brings the page
501
495
  forward cannot approve. One confirmation is shown at a time; the others wait, the shown
@@ -520,8 +514,8 @@ Not when an `onConfirm` answers (the page's, or for a served port its own): it m
520
514
  anywhere, such as a side panel or the site's chat. Say where in the tool's own
521
515
  description if the AI app should know.
522
516
 
523
- Pass `onConfirm` to ask in your own UI (it is asked every time; remember answers there if
524
- 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
525
519
  library's dialog does, since anyone can declare any name. Escape the arguments and the
526
520
  name as the dialog does with `escapeInvisible` from `@ractive-ch/tab-mcp-client/visible`
527
521
  (an entry of its own, not in the core):
@@ -552,6 +546,123 @@ outcome `unanswered`. Any other value, and a throw, is a refusal.
552
546
 
553
547
  `mcp.confirmInPage(request, { document })` is the library's own dialog, for an
554
548
  `onConfirm` that handles only some calls itself (`document` defaults to the global one).
549
+ A call the user allowed for its AI app resolves `true` without the dialog.
550
+
551
+ An app that shows the dialog for an MCP endpoint of its own, without a `TabMcp` (a
552
+ desktop app, say), can load the built confirmation chunk (`confirm-<hash>.js`; its name
553
+ changes with each build) and call its `confirmInPage(host, request, document, options)`.
554
+ `host` is a stand-in with `grants` (the AI apps it allows for, `{ grantId }`), optionally
555
+ an `EventTarget` that sends `grantschange` when they change (any event: the allowances
556
+ are pruned against `grants` as they are then). A call counts as allowed only while its
557
+ grant is in `grants`, also without an event. `options` are
558
+ `alwaysAllow` (`true` or `"until-reload"` offers "Allow until reload" for that call;
559
+ without it nothing is allowed or kept), `ui` (the dialog's texts) and `allowDelayMs`
560
+ (tests only). Such allowances live in memory, for the host's grants, until a reload; only
561
+ a client with `kind: "relay"` can be allowed.
562
+
563
+ ### Tools that run without asking
564
+
565
+ The user can let a consequential tool run without asking, for one connected AI app: one
566
+ tool at a time ("Always allow" this tool), or everything ("Allow everything, no questions
567
+ asked"). An allowed call runs at once, with the library's dialog and with your own
568
+ `onConfirm` alike: neither is asked. Only AI apps through the relay can be allowed; an
569
+ agent in the browser (WebMCP) and a served port have no grant to remember it for and are
570
+ always asked.
571
+
572
+ The option `alwaysAllow` decides what the library's dialogs offer:
573
+
574
+ | `alwaysAllow` | The confirmation offers | The connect dialog shows | Kept |
575
+ | ---------------- | -------------------------- | ------------------------------------- | -------------------------------------------- |
576
+ | unset or `false` | Don't allow, Allow | nothing (unless something is allowed) | in `storage`, for your own switches |
577
+ | `true` | … and "Always allow" | the switches under each app | in `storage`, until the app is disconnected |
578
+ | `"until-reload"` | … and "Allow until reload" | the switches under each app | in memory, until the page is reloaded |
579
+
580
+ With `true` and `storage: null`, nothing outlives the page either, and the button says
581
+ "Allow until reload". The confirmation never offers "allow everything": that is a
582
+ deliberate act in the connect dialog, not an answer to one question. In the connect
583
+ dialog, each connected app gets a switch per tool that asks (its title or name;
584
+ destructive ones marked) and "Allow everything, no questions asked", with a sentence on
585
+ what it means. The switches are checkboxes with `role="switch"` whose accessible names
586
+ name the app. A tool that is allowed but not registered right now (a page may offer some
587
+ tools only on some views) is listed by its name, as a switch that can only be turned
588
+ off. When the page does not offer allowing (`alwaysAllow` unset) but something is
589
+ allowed for an app (by your own switches), the connect dialog shows only that, as
590
+ switches that can only be turned off ("everything" only while it is on): the user can
591
+ see and end what runs without asking where they disconnect apps, and is never offered
592
+ more than the page chose to offer.
593
+
594
+ **What counts.** An allowed tool runs without asking as long as its title and
595
+ description are the ones the user allowed: a tool registered with another one is asked
596
+ again and leaves the list. A tool that is not registered for a while keeps its allowance
597
+ (a reload registers every tool again; a page may offer some only on some views).
598
+ "Everything" covers every tool, also ones registered later, changed ones and destructive
599
+ ones: that is why it is a switch of its own.
600
+
601
+ **Where it is kept, and when it ends.** In the page's `storage` (by default
602
+ `localStorage`), under the address secret's key with `#allowed` appended: the grant ids,
603
+ the tool names and the title and description the user saw, and a fingerprint of the
604
+ secret; no arguments, no results. An allowance ends with its grant, as the relay reports
605
+ it: the app is disconnected (in the page or elsewhere), "Disconnect all apps"
606
+ (`newAddress()`), the grant expired, the user signed out (identity binding). A dropped
607
+ connection, a reload or a page that has not connected yet keeps them. Tabs that share the
608
+ address share them, and a change in one counts in the others at once.
609
+
610
+ **Your own switches.** `@ractive-ch/tab-mcp-client/allowed` (an entry of its own, not in
611
+ the core) has the same allowances for a UI of your own, also with `alwaysAllow` unset:
612
+
613
+ ```ts
614
+ import { allowedTools } from "@ractive-ch/tab-mcp-client/allowed";
615
+
616
+ const allowed = allowedTools(mcp); // one object per TabMcp
617
+ function drawSwitches() {
618
+ list.replaceChildren(
619
+ ...mcp.grants.flatMap((grant) => [
620
+ ...allowed.tools().map((tool) =>
621
+ mySwitch(`${tool.title ?? tool.name}${tool.destructive ? " (destructive)" : ""}`,
622
+ allowed.has(grant.grantId, tool.name),
623
+ (on) => on ? allowed.allow(grant.grantId, tool.name) : allowed.ask(grant.grantId, tool.name)),
624
+ ),
625
+ mySwitch("Allow everything, no questions asked",
626
+ allowed.everything(grant.grantId),
627
+ (on) => allowed.setEverything(grant.grantId, on)),
628
+ ]),
629
+ );
630
+ }
631
+ allowed.onChange(drawSwitches); // allowances and tools
632
+ mcp.addEventListener("grantschange", drawSwitches);
633
+ ```
634
+
635
+ - `tools()`: the tools that ask (`consequentialHint`, callable through the relay), each
636
+ `{ name, title?, description, destructive }`.
637
+ - `has(grantId, name)`: whether a call runs without asking now (only for an app in
638
+ `mcp.grants`). `list(grantId)`: the
639
+ names allowed one by one (one registered now with another title or description is
640
+ not in it). `everything(grantId)`. These only read, so they are safe while drawing.
641
+ - `allow(grantId, name)` (as the tool is registered now), `ask(grantId, name)`,
642
+ `setEverything(grantId, on)`, `forget(grantId)` (everything of that app asks again).
643
+ Allowing does nothing for an app that is not in `mcp.grants`. `ask` while
644
+ "everything" is on turns "everything" off for that app too, and leaves the other
645
+ tools allowed one by one as they are: asking again errs towards asking.
646
+ - `onChange(listener)` returns what stops it. `kept` says whether they outlive a reload.
647
+ The methods are bound: `const { allow, ask } = allowedTools(mcp)` works.
648
+ - In React, `useAllowedTools(grantId)` of `@ractive-ch/tab-mcp-client/react` returns
649
+ `{ tools (each with allowed), everything, allowedTools }` and renders again on a change.
650
+ - Without a bundler, `cdn/allowed.min.js` sits beside the CDN build's
651
+ `tab-mcp-client.min.js` and shares its chunks (one store with the dialogs); a page
652
+ that does not import it loads nothing of it. Take both from the same version:
653
+
654
+ ```js
655
+ import { TabMcp } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.18.1-rc.1/cdn/tab-mcp-client.min.js";
656
+ import { allowedTools } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.18.1-rc.1/cdn/allowed.min.js";
657
+ ```
658
+
659
+ **The risk.** An allowance outlives the user's attention: for up to the grant's 90 days,
660
+ calls run that nobody looks at. An AI app can be steered by text it reads (a web page, a
661
+ mail, a document), and an allowed tool is then the one that runs on its say. Offer it
662
+ for tools one would not want to check each time, whose worst call is cheap to undo; not
663
+ for tools that pay, send, delete or publish. "Everything" also covers tools the user has
664
+ not seen, and ones the page adds later. The relay cannot help: its one OAuth scope
665
+ (`tools`) covers every tool of the page, so consent per tool is the page's.
555
666
 
556
667
  ### Connecting and pairing
557
668
 
@@ -593,8 +704,8 @@ outcome `unanswered`. Any other value, and a throw, is a refusal.
593
704
  (claude.ai) is connected" (every connected app is named) and what to do next (close it and ask the app to use the
594
705
  page's tools); screen readers hear the same. The setup (address, code, help) moves
595
706
  behind "Connect another app", closed, so the next code does not appear in view; the
596
- connected app is listed with a Disconnect button (and the tools it may run without
597
- asking, with "Ask again"), and "Done" closes the dialog. A Disconnect the relay could
707
+ connected app is listed with a Disconnect button (and, with `alwaysAllow`, the
708
+ switches for what it may run without asking), and "Done" closes the dialog. A Disconnect the relay could
598
709
  not save says so in the list ("The relay could not save this. Try again.").
599
710
  Opened again while an app is connected, the dialog starts like this, with the focus
600
711
  on Done.
@@ -1046,7 +1157,7 @@ function TodoList() {
1046
1157
  again only when its name, title, description, input or output schema or annotations
1047
1158
  change, or `options.callers` or `options.exposedTo` (by value: a new array with the same
1048
1159
  entries is no change; [which callers see a tool](#which-callers-see-a-tool),
1049
- [WebMCP](#webmcp), whose `webmcp` on the provider turns it on). Registered again unchanged, a tool allowed until reload stays
1160
+ [WebMCP](#webmcp), whose `webmcp` on the provider turns it on). Registered again unchanged, an allowed tool stays
1050
1161
  allowed. StrictMode's double mount registers it once at a time. A duplicate name or an
1051
1162
  invalid tool is thrown from the component's render, for an error boundary. Tools that
1052
1163
  read state right after another tool changed it should read it from a store (as the
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-s31xrfa2.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
+ }
@@ -1,34 +1,168 @@
1
1
  /**
2
- * The tools a user chose "Allow until reload" for, per AI app (grant), kept
3
- * in memory for the page's lifetime. An entry goes when its grant goes, when
4
- * the user resets it in the connect dialog, or when its tool is gone. A tool
5
- * registered again as it was (React's `useTool` does that on a remount) keeps
6
- * it; one whose title or description changed, what the user saw when
7
- * allowing it, is asked again.
2
+ * The tools that run without asking, per AI app (grant), DEC-096 and
3
+ * DEC-200: the ones the user allowed one by one, each with what the user
4
+ * saw of it (title and description; a tool that changed since is asked
5
+ * again and leaves the list), and "everything", which covers every tool of
6
+ * the page, also ones the user has not seen.
7
+ *
8
+ * Kept in the page's `storage` under the secret's key with `#allowed`, so
9
+ * that they outlive a reload; in memory with `alwaysAllow: "until-reload"`,
10
+ * with `storage: null` and without a relay. Storage is read first on every
11
+ * question, so that a change in another tab of the same address counts at
12
+ * once (only one tab at a time holds the connection, DEC-095).
13
+ *
14
+ * An allowance ends with its grant, and only on what the relay says: the
15
+ * grants of a new session, a removed grant, `newAddress()` (the relay
16
+ * revoked them all). A dropped connection, or a page that has not connected
17
+ * yet, keeps them: `grantschange` does not fire then. They also belong to
18
+ * the address secret they were made under, so a new secret (`newAddress()`
19
+ * here or in another tab) ends them even where nothing listened.
20
+ *
21
+ * Out of the core: the confirmation (`confirm.ts`, which the core loads for
22
+ * every consequential call), the connect dialog and
23
+ * `@ractive-ch/tab-mcp-client/allowed` import it.
8
24
  */
9
25
  import type { TabMcp } from "./tab-mcp.js";
10
26
  import type { ConfirmRequest } from "./types.js";
27
+ /** What the user saw of a tool: its name, title and description. */
11
28
  type ToolSeen = ConfirmRequest["tool"];
12
- export declare class AlwaysAllowed {
13
- #private;
14
- has(grantId: string, tool: ToolSeen): boolean;
15
- add(grantId: string, tool: ToolSeen): void;
16
- /** The tools allowed for a grant (title, else name), in the order allowed. */
29
+ /** A tool as the registry or a call names it. */
30
+ type ToolNow = {
31
+ name: string;
32
+ title?: string | undefined;
33
+ description: string;
34
+ };
35
+ /** A tool that asks before it runs, for a page's switch. */
36
+ export interface AllowedTool {
37
+ name: string;
38
+ title?: string;
39
+ description: string;
40
+ /** Marked `destructiveHint`: it may delete or overwrite. */
41
+ destructive: boolean;
42
+ }
43
+ /**
44
+ * The tools that run without asking, per connected AI app (`Grant.grantId`),
45
+ * for a page that draws its own switches: `allowedTools(mcp)` of
46
+ * `@ractive-ch/tab-mcp-client/allowed`. The library's dialogs use the same.
47
+ * The methods are bound: `const { allow } = allowedTools(mcp)` works. The
48
+ * queries (`tools`, `list`, `has`, `everything`) only read: safe while
49
+ * drawing.
50
+ */
51
+ export interface AllowedTools {
52
+ /**
53
+ * `true`: kept in the page's `storage` until the app is disconnected;
54
+ * `false`: in memory, until the page is reloaded or the app is
55
+ * disconnected (`alwaysAllow: "until-reload"`, `storage: null`).
56
+ */
57
+ readonly kept: boolean;
58
+ /**
59
+ * The page's tools that ask before they run (`consequentialHint`, callable
60
+ * by AI apps through the relay), in the order registered.
61
+ */
62
+ tools(): AllowedTool[];
63
+ /**
64
+ * The names of the tools allowed one by one for this app, in the order
65
+ * allowed; also one that is not registered right now (it runs without
66
+ * asking again once it is back unchanged). One registered now with another
67
+ * title or description than the user allowed is not in it (it asks).
68
+ */
17
69
  list(grantId: string): string[];
18
- /** Ask again for every tool of a grant. */
70
+ /**
71
+ * Whether a call of this tool by this app runs without asking now: the
72
+ * app is in `mcp.grants`, and "everything" is on or the tool is allowed
73
+ * and registered unchanged.
74
+ */
75
+ has(grantId: string, name: string): boolean;
76
+ /**
77
+ * Allow one tool for this app from now on, as it is registered now (its
78
+ * title and description). Nothing happens for an app that is not in
79
+ * `mcp.grants` or a tool that is not in `tools()`.
80
+ */
81
+ allow(grantId: string, name: string): void;
82
+ /**
83
+ * Ask again before this app runs this tool. While "everything" is on for
84
+ * the app, that goes off too (asking again errs towards asking); the
85
+ * other tools allowed one by one stay allowed.
86
+ */
87
+ ask(grantId: string, name: string): void;
88
+ /** Whether "Allow everything, no questions asked" is on for this app. */
89
+ everything(grantId: string): boolean;
90
+ /**
91
+ * "Allow everything, no questions asked" for this app: every tool runs
92
+ * without asking, with any arguments, also tools registered later, changed
93
+ * ones and destructive ones. Turning it on does nothing for an app that
94
+ * is not in `mcp.grants`.
95
+ */
96
+ setEverything(grantId: string, on: boolean): void;
97
+ /** Ask again for everything of this app: its tools and "everything". */
19
98
  forget(grantId: string): void;
20
- /** Forget every grant not in `grantIds`. */
21
- keepGrants(grantIds: Iterable<string>): void;
22
- /** Forget every tool not in `names`. */
23
- keepTools(names: Iterable<string>): void;
24
- /** Calls `listener` on every change; returns what stops it. */
99
+ /**
100
+ * Calls `listener` on every change of the allowances (also one in
101
+ * another tab of the same address) and of `tools()`; returns what stops it.
102
+ */
25
103
  onChange(listener: () => void): () => void;
26
104
  }
27
105
  /**
28
- * The tools allowed until reload of `mcp`, made on first use. Its grants
29
- * and tools are followed: a tool's absence counts only after the current
30
- * task, so that one unregistered and registered again at once (React) keeps
31
- * its entries.
106
+ * A caller's own stand-in for a `TabMcp` in the confirmation chunk's
107
+ * `confirmInPage` (a desktop app with an MCP endpoint of its own, say): the
108
+ * AI apps it allows for, and optionally `grantschange` events (with
109
+ * `detail.grants`) when they change. Its allowances live in memory, for
110
+ * those grants only, until the page is reloaded.
111
+ */
112
+ export interface ConfirmHost {
113
+ readonly grants: readonly {
114
+ readonly grantId: string;
115
+ }[];
116
+ addEventListener?(type: string, listener: (event: Event) => void): void;
117
+ }
118
+ /**
119
+ * The allowances of one `TabMcp` (or a caller's stand-in, `ConfirmHost`).
120
+ * The public methods are arrow fields, so that they work taken off the
121
+ * object; the queries never write.
122
+ */
123
+ export declare class Allowances implements AllowedTools {
124
+ #private;
125
+ readonly kept: boolean;
126
+ /** The library's dialogs offer allowing (`alwaysAllow` on). */
127
+ readonly offered: boolean;
128
+ constructor(mcp: TabMcp | ConfirmHost);
129
+ readonly tools: () => AllowedTool[];
130
+ readonly list: (grantId: string) => string[];
131
+ readonly has: (grantId: string, name: string) => boolean;
132
+ /**
133
+ * Whether this call runs without asking: "everything", or this tool as
134
+ * the user saw it. Only reads: a tool that changed since asks, and leaves
135
+ * the list when the registry or another tab's change is seen
136
+ * (`toolsChanged`).
137
+ */
138
+ allows(grantId: string, tool: ToolNow): boolean;
139
+ readonly allow: (grantId: string, name: string) => void;
140
+ /** Allow `tool` as the user saw it, for an app the relay still lists. */
141
+ keep(grantId: string, tool: ToolSeen): void;
142
+ readonly ask: (grantId: string, name: string) => void;
143
+ readonly everything: (grantId: string) => boolean;
144
+ readonly setEverything: (grantId: string, on: boolean) => void;
145
+ readonly forget: (grantId: string) => void;
146
+ /**
147
+ * Only the grants the relay lists now: the others ended. What was kept
148
+ * under another secret is dropped from storage too (it allowed nothing
149
+ * already).
150
+ */
151
+ keepGrants(grantIds: Iterable<string>): void;
152
+ /**
153
+ * The registry changed, or another tab changed the allowances: a tool
154
+ * registered with another title or description than the user saw leaves
155
+ * every list. One that is not registered stays (a reload registers them
156
+ * all again, a page may offer some only on some views). Tells the
157
+ * listeners in any case.
158
+ */
159
+ toolsChanged(): void;
160
+ readonly onChange: (listener: () => void) => (() => void);
161
+ }
162
+ /**
163
+ * The allowances of `mcp`, made on first use. They follow its grants (only
164
+ * when the relay names them, see above; a stand-in's `grantschange`) and
165
+ * its tools.
32
166
  */
33
- export declare function allowedFor(mcp: TabMcp): AlwaysAllowed;
167
+ export declare function allowedFor(mcp: TabMcp | ConfirmHost): Allowances;
34
168
  export {};
@@ -0,0 +1,4 @@
1
+ import{r}from"./tab-mcp-client-5j3brdf3.min.js";function e(o){return r(o)}export{e as allowedTools};
2
+
3
+ //# debugId=276A38D7EC2846AF64756E2164756E21
4
+ //# sourceMappingURL=allowed.min.js.map
@@ -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": "gDAkCO,SAAS,CAAY,CAAC,EAA2B,CACvD,OAAO,EAAW,CAAG",
8
+ "debugId": "276A38D7EC2846AF64756E2164756E21",
9
+ "names": []
10
+ }
@@ -0,0 +1,4 @@
1
+ import{a,t,o,e,n,s,d,l}from"./tab-mcp-client-2vx9mcww.min.js";import{r}from"./tab-mcp-client-5j3brdf3.min.js";function ee(u){try{return s(JSON.stringify(u,null,2))}catch{return}}var ne=750,te=500,J=new WeakMap;function K(u,i,b={}){if(u.signal.aborted)return Promise.resolve("deny");let g=J.get(i);if(g===void 0)g={shown:!1,waiting:[]},J.set(i,g);let f=g,c=()=>{let h=f.waiting.shift();f.shown=h!==void 0,h?.(),f.changed?.()},L=()=>{try{return ie(u,i,b,f,c)}catch(h){return c(),Promise.reject(h)}};if(!f.shown)return f.shown=!0,L();return new Promise((h)=>{let v=()=>{if(u.signal.removeEventListener("abort",E),b.allowedNow?.()===!0){h("allow"),c();return}h(L())},E=()=>{f.waiting.splice(f.waiting.indexOf(v),1),f.changed?.(),h("deny")};u.signal.addEventListener("abort",E,{once:!0}),f.waiting.push(v),f.changed?.()})}function ie(u,i,b,g,f){let c=b.strings??a(void 0),L=b.allowDelayMs??ne,h=u.tool.title??u.tool.name,v=d(u.client,c),E={tool:h,client:v},{dialog:m,id:C}=l(i,"tab-mcp-confirm",c,...o(i,c.confirmTitle,E)),H=e(i,"p",{className:"tab-mcp-waiting"}),I=()=>{let p=g.waiting.length;H.hidden=p===0,H.textContent=p===1?c.waitingOne:t(c.waitingMany,{n:String(p)})};g.changed=I,I();let z=n(i,c.deny,()=>m.close("deny"),"tab-mcp-deny","primary"),B=(p,j,R)=>{let A=n(i,p,()=>{if(!A.disabled)m.close(j)},R);return A},k=[B(c.allow,"allow","tab-mcp-allow")],W=[],Q=b.alwaysAllow;if(Q===!0||Q==="until-reload"){let p=Q===!0;k.unshift(B(p?c.alwaysAllow:c.allowUntilReload,"always","tab-mcp-always")),W.push(e(i,"p",{className:"tab-mcp-always-note"},...o(i,p?c.alwaysAllowNote:c.allowUntilReloadNote,E)))}let Y=e(i,"div",{className:"tab-mcp-actions"},z,...k.flatMap((p)=>[" ",p])),N=!1,U=!1,M=()=>{for(let p of k)p.disabled=!(N&&U)};M();let O=ee(u.arguments),y=e(i,"pre",{className:"tab-mcp-arguments",id:`${C}-arguments`,text:O??c.argumentsHidden});if(O===void 0)for(let p of[...k,...W])p.hidden=!0;y.dir="ltr",y.style.setProperty("white-space","pre-wrap"),y.style.setProperty("overflow-wrap","anywhere"),y.style.setProperty("max-height","var(--tab-mcp-arguments-height, min(50vh, 24rem))"),y.style.setProperty("overflow","auto"),y.hidden=Object.keys(u.arguments).length===0;let T=e(i,"p",{className:"tab-mcp-scroll-note",text:c.scrollToAllow});T.hidden=!0;let _=e(i,"p",{id:`${C}-who`},...o(i,c.confirmWho,E));m.setAttribute("aria-describedby",O!==void 0&&!y.hidden&&O.length<=te?`${_.id} ${y.id}`:_.id),m.append(_,e(i,"p",{className:"tab-mcp-description",text:u.tool.description}),y,T,Y,...W,H),i.body.append(m);let x=i.defaultView;return new Promise((p,j)=>{let R=()=>m.close("deny");u.signal.addEventListener("abort",R,{once:!0});let A,P,F=()=>{if(P!==void 0&&i.title===P.shown)i.title=P.page;P=void 0},X=()=>{if(i.visibilityState!=="hidden")F();else if(P===void 0)P={page:i.title,shown:`${c.titlePrefix}${i.title}`},i.title=P.shown},D=(w)=>{if(w?.type==="close"&&w.target===m)return;if(X(),clearTimeout(A),A=void 0,N=!1,M(),w?.type==="blur"||i.visibilityState==="hidden"||!i.hasFocus())return;A=setTimeout(()=>{N=!0,M()},L)},S=()=>{if(U)return;if(y.scrollTop+y.clientHeight<y.scrollHeight-2){T.hidden=!1,y.tabIndex=0;return}U=!0,T.hidden=!0,M()},V=(w)=>{if(N)return;let q=w.target?.localName==="button";if(w.key==="Escape"||q&&(w.key==="Enter"||w.key===" "))w.preventDefault()},Z=(w)=>{if(!N)w.preventDefault()};i.addEventListener("visibilitychange",D),i.addEventListener("close",D,!0),x?.addEventListener("focus",D),x?.addEventListener("blur",D),x?.addEventListener("resize",S),y.addEventListener("scroll",S),m.addEventListener("keydown",V),m.addEventListener("keyup",V),m.addEventListener("cancel",Z);let G=()=>{if(clearTimeout(A),F(),i.removeEventListener("visibilitychange",D),i.removeEventListener("close",D,!0),x?.removeEventListener("focus",D),x?.removeEventListener("blur",D),x?.removeEventListener("resize",S),u.signal.removeEventListener("abort",R),m.remove(),g.changed===I)g.changed=void 0};m.addEventListener("close",()=>{let w=m.returnValue;G(),p(w==="allow"||w==="always"?w:"deny"),f()},{once:!0});try{m.showModal()}catch(w){G(),j(w),f();return}z.focus(),D(),S()})}function ae(u,i,b,g={}){let{client:f}=i,c=a(g.ui),{allowDelayMs:L}=g;if(f.kind!=="relay")return K(i,b,{strings:c,allowDelayMs:L}).then((C)=>C==="allow");let{grantId:h}=f,v=r(u),E=()=>v.allows(h,i.tool);if(E())return Promise.resolve(!0);let m=g.alwaysAllow??v.offered;return K(i,b,{strings:c,allowDelayMs:L,alwaysAllow:m!==!1&&(m===!0&&v.kept?!0:"until-reload"),allowedNow:E}).then((C)=>{if(C==="always")v.keep(h,i.tool);return C!=="deny"})}function se(u,i,b){let{client:g}=i;if(g.kind==="relay"&&r(u).allows(g.grantId,i.tool))return Promise.resolve(!0);if(b===void 0)return u.confirmInPage(i);return Promise.resolve().then(()=>b(i)).then((f)=>f==="unanswered"?f:f===!0)}export{se as confirmCall,ae as confirmInPage};
2
+
3
+ //# debugId=D0E23A81AC714FF364756E2164756E21
4
+ //# sourceMappingURL=confirm-d722a9eb.min.js.map