@ractive-ch/tab-mcp-client 0.16.1 → 0.17.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 (33) hide show
  1. package/CHANGELOG.md +849 -0
  2. package/README.md +102 -74
  3. package/address.d.ts +8 -8
  4. package/cdn/{confirm-y30cx7e1.min.js → confirm-mqmvsxg1.min.js} +2 -2
  5. package/cdn/{connect-bbhj2y7w.min.js → connect-c7wn48yp.min.js} +2 -2
  6. package/cdn/{connect-bbhj2y7w.min.js.map → connect-c7wn48yp.min.js.map} +1 -1
  7. package/cdn/{connection-w97tf22a.min.js → connection-0xqwz17v.min.js} +7 -7
  8. package/cdn/{connection-w97tf22a.min.js.map → connection-0xqwz17v.min.js.map} +5 -5
  9. package/cdn/{index-vt5zk9me.min.js → index-t33bb2g4.min.js} +4 -4
  10. package/cdn/{index-vt5zk9me.min.js.map → index-t33bb2g4.min.js.map} +4 -4
  11. package/cdn/tab-mcp-client.min.js +3 -3
  12. package/cdn/tab-mcp-client.min.js.map +4 -4
  13. package/{confirm-fgnjgd08.js → confirm-vj2zbq4w.js} +2 -2
  14. package/{connect-8jpb0k29.js → connect-9pefy0xe.js} +2 -2
  15. package/{connect-8jpb0k29.js.map → connect-9pefy0xe.js.map} +1 -1
  16. package/{connection-g91xjjgm.js → connection-gang7f5x.js} +10 -23
  17. package/{connection-g91xjjgm.js.map → connection-gang7f5x.js.map} +5 -5
  18. package/connection.d.ts +2 -2
  19. package/index-dmh5vm5m.js.map +1 -1
  20. package/{index-jnz7w9xa.js → index-qw8qy5ed.js} +11 -11
  21. package/{index-jnz7w9xa.js.map → index-qw8qy5ed.js.map} +2 -2
  22. package/index.js +24 -26
  23. package/index.js.map +4 -4
  24. package/internal.d.ts +2 -0
  25. package/package.json +1 -1
  26. package/protocol.d.ts +6 -7
  27. package/secret.d.ts +1 -1
  28. package/strings.d.ts +1 -1
  29. package/tab-mcp.d.ts +10 -1
  30. package/types.d.ts +16 -2
  31. package/visible.d.ts +1 -1
  32. /package/cdn/{confirm-y30cx7e1.min.js.map → confirm-mqmvsxg1.min.js.map} +0 -0
  33. /package/{confirm-fgnjgd08.js.map → confirm-vj2zbq4w.js.map} +0 -0
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.1.** 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.17.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.2
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.1/cdn/tab-mcp-client.min.js";
53
+ import { TabMcp } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.17.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
@@ -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
 
@@ -565,10 +583,12 @@ outcome `unanswered`. Any other value, and a throw, is a refusal.
565
583
  the end of the help leads to the guide with the rest (ChatGPT's Mac app, turning the
566
584
  Codex feature off, what to do when it fails). A page can link its own guide and give
567
585
  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.
586
+ The user adds the address to their AI app. It is the app's address
587
+ (`https://<relay>/s/<app>/mcp`), the same in every user's dialog.
588
+ 3. The AI app opens the relay's sign-in page in the browser. The dialog shows a code of
589
+ 8 letters (`XXXX-XXXX`) with a Copy button, which the user types or pastes there, in
590
+ any case, with or without the dash. The relay finds the page by it. The code changes
591
+ every 2 minutes and after each use.
572
592
  4. Once the AI app connects, the dialog says so at the top: a check mark, "Claude
573
593
  (claude.ai) is connected" (every connected app is named) and what to do next (close it and ask the app to use the
574
594
  page's tools); screen readers hear the same. The setup (address, code, help) moves
@@ -583,8 +603,7 @@ The relay makes a new code the moment one is entered, but the AI app connects on
583
603
  moment later. When the relay says the code was used (`reason: "used"` in the event
584
604
  `pairingcode`), the dialog shows "Code used. Waiting for your AI app…" instead of the new
585
605
  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.
606
+ replaces an expired one, or one that comes without a reason, shows at once.
588
607
 
589
608
  Until an app is connected, the dialog offers no prominent button under the code: only a small
590
609
  "Close" at the bottom (and Escape). Closing it stops the code (`stopPairing()`); the page
@@ -593,58 +612,64 @@ shows the same address with a new code. While the dialog is open, calling it aga
593
612
  double click) opens no second one; the call resolves when that one closes. A call for another
594
613
  `document` (an iframe's, say) while it is open rejects with an `InvalidStateError`.
595
614
 
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). A secret that
600
- 0.4 or older kept under `tab-mcp:secret:<relay origin>` is copied to the new key once, so an
601
- existing page keeps its address; on a site with several pages the first one to connect
602
- keeps it, the others get new ones. The old key stays for pages still on 0.4.
603
-
604
- "New address" in the dialog (at the end of the setup, below the code, with a line on what
605
- it does; not next to Copy, since with no app connected it changes the address at once)
606
- calls `newAddress()`, which disconnects every
607
- app and makes a new address; when apps are connected, the dialog asks first. It first
608
- takes the old address back: it connects with the stored secret, and the relay revokes
609
- every grant of the address in
610
- the same step (`hello.revokeAll`), whether the page was connected or not. Then it makes
611
- the new secret, clears `grants`, and connects with it if the page was connected,
612
- connecting or reconnecting (or taken over). A page that never had a secret makes one
613
- without connecting. If the old address cannot be taken back (the relay is unreachable,
614
- or someone takes it over again first), it rejects and keeps the old secret, so calling
615
- it again tries again. A second call while it runs returns the same promise; `connect()`
616
- meanwhile waits for it and then connects with the new address. The relay's
617
- sign-in page points users to it when someone else may be guessing codes. A page with its
618
- own UI calls `newAddress()` from a click. Connected apps keep working after a reload once the page connects
615
+ The address is the app's: it is the same for every visitor and every visit. What tells
616
+ one user's page from another's is the address secret: the library keeps one per relay
617
+ and page in `localStorage`, under `tab-mcp:secret:<relay origin>:<server.name>` (set
618
+ `storageKey` to choose the key yourself; the name is URI-encoded). The relay keys the
619
+ page's session and the AI apps paired with it by a hash of the app id and that secret
620
+ (the address id), which is in no URL. A paired AI app therefore reaches the page again
621
+ after a reload and on later visits. A browser without the secret (another profile,
622
+ cleared storage, a renamed `server.name` without `storageKey`) is a page nobody has
623
+ paired with yet, and so is the same secret under another app id: changing `app`, or a
624
+ `server.name` that `app` is made from, means every AI app pairs again. Two pages of one
625
+ site with different server names keep different secrets; their addresses differ when
626
+ their app ids do. The key of 0.4 and older, `tab-mcp:secret:<relay origin>`, is not
627
+ read: a visitor whose last visit predates 0.5 pairs their AI apps again.
628
+
629
+ "Disconnect all apps" in the dialog (at the end of the setup, below the code, with a
630
+ line on what it does) calls `newAddress()`, which disconnects every app and makes a new
631
+ secret; when apps are connected, the dialog asks first. The method has its name from
632
+ when every page had an address of its own: the address the user sees does not change,
633
+ and each AI app connects again at the same address with a new code. It first takes the
634
+ page back: it connects with the stored secret, and the relay revokes every grant made
635
+ for it in the same step (`hello.revokeAll`), whether the page was connected or not.
636
+ Then it makes the new secret, clears `grants`, and connects with it if the page was
637
+ connected, connecting or reconnecting (or taken over). A page that never had a secret
638
+ makes one without connecting. If the page cannot be taken back (the relay is
639
+ unreachable, or someone takes it over again first), it rejects and keeps the old secret,
640
+ so calling it again tries again. A second call while it runs returns the same promise;
641
+ `connect()` meanwhile waits for it and then connects with the new secret. A page with
642
+ its own UI calls `newAddress()` from a click. Connected apps keep working after a reload once the page connects
619
643
  again; while the page is closed, they get "the page is not open".
620
644
 
621
- When another tab or program connects with the same address, it takes the address over:
645
+ When another tab or program connects with the same secret, it takes the page's place:
622
646
  the page gets `statechange` to `disconnected` with reason `replaced` at once, then the
623
647
  event `replaced`,
624
648
  and does not reconnect by itself. Tabs of the same page say on a `BroadcastChannel` (per
625
- relay and storage key; it carries the address id, which is part of the address, never
626
- the secret) when the relay accepted their session, so `replaced` says which it probably
627
- was:
649
+ relay and storage key; it carries a hash of the secret, never the secret) when the relay
650
+ accepted their session, so `replaced` says which it probably was:
628
651
 
629
652
  - `event.detail.sibling` is `true`: a tab of the same page in this browser said within
630
- the last 10 seconds that it claimed this tab's address, after this tab's own session
631
- started (a claim of another address, or one heard while this tab was still connecting,
632
- 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
653
+ the last 10 seconds that it connected with this tab's secret, after this tab's own
654
+ session started (a claim with another secret's hash, or one heard while this tab was
655
+ still connecting, does not count; a claim without a hash, from a tab still on
656
+ 0.15 or older, does). That message usually comes just after the takeover, so the
633
657
  library waits up to a second for it, and `replaced` may come that much after
634
658
  the `statechange`. The usual cause, and harmless. Once the page has opened the default
635
659
  dialog, the library shows "Opened in another tab".
636
660
  - `false`: none did (or the browser has no `BroadcastChannel`). It may be a program with
637
- a copy of the address secret, and the AI apps paired with the address now talk to it.
638
- The library shows "Another tab or program took over this page" with "New address".
661
+ a copy of the address secret, and the AI apps paired with the page now talk to it.
662
+ The library shows "Another tab or program took over this page" with "Disconnect all
663
+ apps".
639
664
 
640
665
  After a takeover, `newAddress()` (from the `replaced` listener, before it, or later, also
641
- after a reload) takes the address back as above and makes the new address only once the
642
- relay confirmed that no grant is left. If the address is taken over again before that,
666
+ after a reload) takes the page back as above and makes the new secret only once the
667
+ relay confirmed that no grant is left. If the page is taken over again before that,
643
668
  it rejects with an error whose `reason` is `"replaced"` and keeps the old secret, so
644
- calling it again takes it back again. A relay of 0.4 or older cannot take an address
669
+ calling it again takes it back again. A relay of 0.4 or older cannot take a page
645
670
  back: `newAddress()` rejects there with `reason` `"policy"`. When the takeover ended a
646
- session of this page, it then connects with the new address; the default notice opens
647
- the connect dialog to add it to the AI apps.
671
+ session of this page, it then connects with the new secret; the default notice opens
672
+ the connect dialog, where the user pairs the AI apps again.
648
673
 
649
674
  The default dialog closes when the page is replaced, and the notice appears also when the
650
675
  dialog is closed, but only once the page has opened the dialog: a page that connects on
@@ -654,8 +679,8 @@ with its own UI shows the same from `replaced`:
654
679
  ```ts
655
680
  mcp.addEventListener("replaced", (e) => {
656
681
  if (e.detail.sibling) showNote("Opened in another tab.");
657
- else showWarning("Another tab or program took over this page's address.", {
658
- action: "New address",
682
+ else showWarning("Another tab or program took over this page.", {
683
+ action: "Disconnect all apps",
659
684
  onClick: () => mcp.newAddress(), // from the click
660
685
  });
661
686
  });
@@ -664,12 +689,12 @@ mcp.addEventListener("replaced", (e) => {
664
689
  Script on the page's origin can post on the channel and make a takeover look like a
665
690
  sibling; such script can read the secret anyway, so `sibling` is a hint, not a proof.
666
691
 
667
- ### Keeping the address safe
692
+ ### Keeping the address secret safe
668
693
 
669
- Whoever has the address secret can take over the page's address from anywhere, and the
670
- AI apps paired with it then send their arguments to them and get their tool descriptions
671
- and results, until the page gets a new address. They get no token and cannot pair a new
672
- app without a code. Script on your origin (cross-site scripting, a compromised
694
+ Whoever has the address secret can take the page's place from anywhere, and the AI apps
695
+ paired with the page then send their arguments to them and get their tool descriptions
696
+ and results, until the page makes a new secret (`newAddress()`). They get no token and
697
+ cannot pair a new app without a code. Script on your origin (cross-site scripting, a compromised
673
698
  third-party script, another page on the same origin) or access to the device can copy it
674
699
  ([threat model](https://github.com/ractive/tab-mcp/blob/main/docs/threat-model.md), A4).
675
700
 
@@ -682,9 +707,10 @@ third-party script, another page on the same origin) or access to the device can
682
707
  shared profile, or in a web app with accounts that pairs by code, the next user of the
683
708
  page gets the AI apps the previous one paired. Call `newAddress()` when the user logs
684
709
  out, or use identity binding.
685
- - The page origin that the relay's sign-in page shows is what the page's browser
686
- reported; a program can claim any origin. Do not tell users it proves which page they
687
- pair with.
710
+ - The relay's sign-in page names the AI app and the app id of the address, not the page
711
+ or its origin: the code alone says which page is paired. Whoever types a user's code
712
+ on that page connects their own AI app to the user's page, so tell users never to
713
+ pass their code on. With identity binding there is no code to pass on.
688
714
 
689
715
  When the connection breaks (reason `network`, `heartbeat` or `shutdown`: a dropped
690
716
  network, a phone pausing the tab in the background, a relay restart; close codes 1001,
@@ -695,8 +721,8 @@ come back at once), and at once when the tab comes back to the front or the netw
695
721
  returns. Meanwhile `state` is `reconnecting` (while it waits and while it makes an
696
722
  attempt), `reconnecting` says which attempt is next and when, and `statechange` fires
697
723
  for each attempt it schedules; only the `statechange` that leaves `connected` carries the
698
- `reason` ([Your own UI](#your-own-ui)). Calling `connect()` meanwhile tries at once. It never reconnects after `disconnect()`, a new address,
699
- another tab taking over the address (`replaced`), an expired or idle session, or a
724
+ `reason` ([Your own UI](#your-own-ui)). Calling `connect()` meanwhile tries at once. It never reconnects after `disconnect()`, `newAddress()`,
725
+ another tab taking the page's place (`replaced`), an expired or idle session, or a
700
726
  refusal by the relay, and an attempt the relay refuses stops it (an unreachable relay is
701
727
  tried again); the event `error` then says why, with `state` already `disconnected`, just
702
728
  before the `statechange` to `disconnected`, also when a `connect()` of the page waits on
@@ -727,15 +753,17 @@ if (localStorage.getItem(key) === "1") {
727
753
  ```
728
754
 
729
755
  `resume: true` lets `connect()` run without a click. Offer a way to turn it off. With
730
- two tabs of the page open, the newer one takes the address over: listen for `replaced`
756
+ two tabs of the page open, the newer one takes the older one's place: listen for `replaced`
731
757
  (above) to tell the older tab why it went off.
732
758
 
733
759
  ### Identity binding (no code)
734
760
 
735
761
  On a relay that pairs by `oidc` ([identity binding](https://github.com/ractive/tab-mcp/blob/main/docs/configuration.md#identity-binding)),
736
762
  the user signs in to the AI app's connection with the account they use on your page,
737
- and no code is shown. Your backend proves who is signed in: give the library a function
738
- that fetches a short-lived tab assertion for the page's address.
763
+ and no code is shown. The relay pairs the AI app with the app's page whose user is that
764
+ person and whose "Connect your AI app" dialog is open. Your backend proves who is signed
765
+ in: give the library a function that fetches a short-lived tab assertion for the page's
766
+ address. The address is the app's, so the assertion's `aud` names the app, not one page.
739
767
 
740
768
  ```ts
741
769
  const mcp = new TabMcp({
@@ -778,7 +806,7 @@ Instead of `showConnectDialog()`, use the methods, properties and events below.
778
806
  |---|---|
779
807
  | `connect(options?)` | resolves with the session (`SessionInfo`) |
780
808
  | `disconnect()` | ends the session at once |
781
- | `newAddress()` | resolves once the new address is in use (connected again if it was on) |
809
+ | `newAddress()` | disconnects every app ("Disconnect all apps"); resolves once the new secret is in use (connected again if it was on) |
782
810
  | `startPairing()`, `stopPairing()` | codes come only while pairing is on |
783
811
  | `revoke(grantId)` | resolves once the relay removed the grant |
784
812
  | `signOut()` | resolves once the relay removed the grants (identity binding) |
@@ -791,16 +819,16 @@ the session ends after the message was sent and before the relay answered, and w
791
819
  or may not have done it, and `grants` says so once the page is connected again. They
792
820
  also reject with the relay's refusal of that message, an `Error` whose `code` is
793
821
  `store_unavailable` (the relay could not save the change: try again) or `unknown_id`.
794
- A relay after 0.10.2 names the message it answers (`for`, and `grantId` for a
822
+ A relay after 0.12.0 names the message it answers (`for`, and `grantId` for a
795
823
  revocation), so with several revocations pending only the one it answers rejects; an
796
824
  older relay's refusal rejects every pending `revoke()` and `signOut()`. When the relay
797
825
  does not know a grant the page lists (it expired), the grant leaves `grants` (with
798
826
  `grantschange`) and its `revoke()` resolves.
799
827
 
800
828
  With a relay, `newAddress()` rejects with an error whose `addressChanged` says what happened: `false`
801
- when the old address could not be taken back (it is kept with its grants; call
802
- `newAddress()` again), `true` when the address changed and only connecting with the new
803
- one failed (call `connect()`).
829
+ when the page could not be taken back (the old secret is kept with its grants; call
830
+ `newAddress()` again), `true` when the secret changed, so every app is disconnected, and
831
+ only connecting with the new one failed (call `connect()`).
804
832
 
805
833
  The properties are `state` (`disconnected`, `connecting`, `connected`, `reconnecting`),
806
834
  `session` (while connected; `session.address` is the MCP address, `session.appName` the
@@ -1075,15 +1103,15 @@ from a CDN uses the core API. [examples/react-todo](https://github.com/ractive/t
1075
1103
  is a complete todo app.
1076
1104
 
1077
1105
  For end-to-end tests of a page's tools, `@ractive-ch/tab-mcp/testing` (the relay's
1078
- package) starts a relay in the test process and issues a token for the page's address
1079
- without pairing; see the relay's [README](https://github.com/ractive/tab-mcp/tree/main/packages/tab-mcp#testing-a-pages-tools).
1106
+ package) starts a relay in the test process and issues a token for the page connected
1107
+ 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).
1080
1108
 
1081
1109
  ## Security
1082
1110
 
1083
1111
  Connecting an AI app to a page means trusting that page, as with any MCP server. Keep
1084
1112
  cross-site scripting out of your page: a script that reads the address secret can take
1085
- over the address. The library sends the secret only over `https:`/`wss:` (plain `http:`
1086
- only to `localhost`). See
1113
+ the page's place at the relay. The library sends the secret only over `https:`/`wss:`
1114
+ (plain `http:` only to `localhost`). See
1087
1115
  [SECURITY.md](https://github.com/ractive/tab-mcp/blob/main/SECURITY.md) and the
1088
1116
  [threat model](https://github.com/ractive/tab-mcp/blob/main/docs/threat-model.md).
1089
1117
 
@@ -1092,7 +1120,7 @@ only to `localhost`). See
1092
1120
  - [Live examples](https://ractive.ch/tab-mcp/)
1093
1121
  - [Example: a React todo app](https://github.com/ractive/tab-mcp/tree/main/examples/react-todo)
1094
1122
  - [Tab–relay protocol](https://github.com/ractive/tab-mcp/blob/main/docs/protocol.md)
1095
- - [Changelog](https://github.com/ractive/tab-mcp/blob/main/CHANGELOG.md)
1123
+ - [Changelog](https://github.com/ractive/tab-mcp/blob/main/packages/tab-mcp-client/CHANGELOG.md), also in the package as `CHANGELOG.md`
1096
1124
 
1097
1125
  ## Licence
1098
1126
 
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;
@@ -1,4 +1,4 @@
1
- import{c,o,n,s,e,t,r,a,d}from"./index-vt5zk9me.min.js";function q(u){try{return r(JSON.stringify(u,null,2))}catch{return}}var ee=750,te=500,G=new WeakMap;function J(u,i,v={}){if(u.signal.aborted)return Promise.resolve("deny");let p=G.get(i);if(p===void 0)p={shown:!1,waiting:[]},G.set(i,p);let f=p,l=()=>{let y=f.waiting.shift();f.shown=y!==void 0,y?.(),f.changed?.()},D=()=>{try{return ne(u,i,v,f,l)}catch(y){return l(),Promise.reject(y)}};if(!f.shown)return f.shown=!0,D();return new Promise((y)=>{let L=()=>{if(u.signal.removeEventListener("abort",b),v.allowedNow?.()===!0){y("allow"),l();return}y(D())},b=()=>{f.waiting.splice(f.waiting.indexOf(L),1),f.changed?.(),y("deny")};u.signal.addEventListener("abort",b,{once:!0}),f.waiting.push(L),f.changed?.()})}function ne(u,i,v,p,f){let l=v.strings??o(void 0),D=v.allowDelayMs??ee,y=u.tool.title??u.tool.name,L=a(u.client,l),b={tool:y,client:L},{dialog:w,id:_}=d(i,"tab-mcp-confirm",l,...s(i,l.confirmTitle,b)),S=e(i,"p",{className:"tab-mcp-waiting"}),I=()=>{let h=p.waiting.length;S.hidden=h===0,S.textContent=h===1?l.waitingOne:n(l.waitingMany,{n:String(h)})};p.changed=I,I();let j=t(i,l.deny,()=>w.close("deny"),"tab-mcp-deny","primary"),z=(h,U,k)=>{let A=t(i,h,()=>{if(!A.disabled)w.close(U)},k);return A},N=[z(l.allow,"allow","tab-mcp-allow")],H=[];if(v.alwaysAllow===!0)N.unshift(z(l.allowUntilReload,"always","tab-mcp-always")),H.push(e(i,"p",{className:"tab-mcp-always-note"},...s(i,l.allowUntilReloadNote,b)));let K=e(i,"div",{className:"tab-mcp-actions"},j,...N.flatMap((h)=>[" ",h])),M=!1,W=!1,P=()=>{for(let h of N)h.disabled=!(M&&W)};P();let O=q(u.arguments),g=e(i,"pre",{className:"tab-mcp-arguments",id:`${_}-arguments`,text:O??l.argumentsHidden});if(O===void 0)for(let h of[...N,...H])h.hidden=!0;g.dir="ltr",g.style.setProperty("white-space","pre-wrap"),g.style.setProperty("overflow-wrap","anywhere"),g.style.setProperty("max-height","var(--tab-mcp-arguments-height, min(50vh, 24rem))"),g.style.setProperty("overflow","auto"),g.hidden=Object.keys(u.arguments).length===0;let T=e(i,"p",{className:"tab-mcp-scroll-note",text:l.scrollToAllow});T.hidden=!0;let Q=e(i,"p",{id:`${_}-who`},...s(i,l.confirmWho,b));w.setAttribute("aria-describedby",O!==void 0&&!g.hidden&&O.length<=te?`${Q.id} ${g.id}`:Q.id),w.append(Q,e(i,"p",{className:"tab-mcp-description",text:u.tool.description}),g,T,K,...H,S),i.body.append(w);let C=i.defaultView;return new Promise((h,U)=>{let k=()=>w.close("deny");u.signal.addEventListener("abort",k,{once:!0});let A,x,B=()=>{if(x!==void 0&&i.title===x.shown)i.title=x.page;x=void 0},Y=()=>{if(i.visibilityState!=="hidden")B();else if(x===void 0)x={page:i.title,shown:`${l.titlePrefix}${i.title}`},i.title=x.shown},E=(m)=>{if(m?.type==="close"&&m.target===w)return;if(Y(),clearTimeout(A),A=void 0,M=!1,P(),m?.type==="blur"||i.visibilityState==="hidden"||!i.hasFocus())return;A=setTimeout(()=>{M=!0,P()},D)},R=()=>{if(W)return;if(g.scrollTop+g.clientHeight<g.scrollHeight-2){T.hidden=!1,g.tabIndex=0;return}W=!0,T.hidden=!0,P()},F=(m)=>{if(M)return;let Z=m.target?.localName==="button";if(m.key==="Escape"||Z&&(m.key==="Enter"||m.key===" "))m.preventDefault()},X=(m)=>{if(!M)m.preventDefault()};i.addEventListener("visibilitychange",E),i.addEventListener("close",E,!0),C?.addEventListener("focus",E),C?.addEventListener("blur",E),C?.addEventListener("resize",R),g.addEventListener("scroll",R),w.addEventListener("keydown",F),w.addEventListener("keyup",F),w.addEventListener("cancel",X);let V=()=>{if(clearTimeout(A),B(),i.removeEventListener("visibilitychange",E),i.removeEventListener("close",E,!0),C?.removeEventListener("focus",E),C?.removeEventListener("blur",E),C?.removeEventListener("resize",R),u.signal.removeEventListener("abort",k),w.remove(),p.changed===I)p.changed=void 0};w.addEventListener("close",()=>{let m=w.returnValue;V(),h(m==="allow"||m==="always"?m:"deny"),f()},{once:!0});try{w.showModal()}catch(m){V(),U(m),f();return}j.focus(),E(),R()})}function re(u,i,v,p={}){let{client:f}=i,l={strings:o(p.ui),allowDelayMs:p.allowDelayMs};if(f.kind!=="relay")return J(i,v,l).then((b)=>b==="allow");let{grantId:D}=f,y=c(u),L=()=>y.has(D,i.tool);if(L())return Promise.resolve(!0);return J(i,v,{...l,alwaysAllow:p.alwaysAllow,allowedNow:L}).then((b)=>{if(b==="always"&&u.grants.some((w)=>w.grantId===D))y.add(D,i.tool);return b!=="deny"})}export{re as confirmInPage};
1
+ import{c,o,n,s,e,t,r,a,d}from"./index-t33bb2g4.min.js";function q(u){try{return r(JSON.stringify(u,null,2))}catch{return}}var ee=750,te=500,G=new WeakMap;function J(u,i,v={}){if(u.signal.aborted)return Promise.resolve("deny");let p=G.get(i);if(p===void 0)p={shown:!1,waiting:[]},G.set(i,p);let f=p,l=()=>{let y=f.waiting.shift();f.shown=y!==void 0,y?.(),f.changed?.()},D=()=>{try{return ne(u,i,v,f,l)}catch(y){return l(),Promise.reject(y)}};if(!f.shown)return f.shown=!0,D();return new Promise((y)=>{let L=()=>{if(u.signal.removeEventListener("abort",b),v.allowedNow?.()===!0){y("allow"),l();return}y(D())},b=()=>{f.waiting.splice(f.waiting.indexOf(L),1),f.changed?.(),y("deny")};u.signal.addEventListener("abort",b,{once:!0}),f.waiting.push(L),f.changed?.()})}function ne(u,i,v,p,f){let l=v.strings??o(void 0),D=v.allowDelayMs??ee,y=u.tool.title??u.tool.name,L=a(u.client,l),b={tool:y,client:L},{dialog:w,id:_}=d(i,"tab-mcp-confirm",l,...s(i,l.confirmTitle,b)),S=e(i,"p",{className:"tab-mcp-waiting"}),I=()=>{let h=p.waiting.length;S.hidden=h===0,S.textContent=h===1?l.waitingOne:n(l.waitingMany,{n:String(h)})};p.changed=I,I();let j=t(i,l.deny,()=>w.close("deny"),"tab-mcp-deny","primary"),z=(h,U,k)=>{let A=t(i,h,()=>{if(!A.disabled)w.close(U)},k);return A},N=[z(l.allow,"allow","tab-mcp-allow")],H=[];if(v.alwaysAllow===!0)N.unshift(z(l.allowUntilReload,"always","tab-mcp-always")),H.push(e(i,"p",{className:"tab-mcp-always-note"},...s(i,l.allowUntilReloadNote,b)));let K=e(i,"div",{className:"tab-mcp-actions"},j,...N.flatMap((h)=>[" ",h])),M=!1,W=!1,P=()=>{for(let h of N)h.disabled=!(M&&W)};P();let O=q(u.arguments),g=e(i,"pre",{className:"tab-mcp-arguments",id:`${_}-arguments`,text:O??l.argumentsHidden});if(O===void 0)for(let h of[...N,...H])h.hidden=!0;g.dir="ltr",g.style.setProperty("white-space","pre-wrap"),g.style.setProperty("overflow-wrap","anywhere"),g.style.setProperty("max-height","var(--tab-mcp-arguments-height, min(50vh, 24rem))"),g.style.setProperty("overflow","auto"),g.hidden=Object.keys(u.arguments).length===0;let T=e(i,"p",{className:"tab-mcp-scroll-note",text:l.scrollToAllow});T.hidden=!0;let Q=e(i,"p",{id:`${_}-who`},...s(i,l.confirmWho,b));w.setAttribute("aria-describedby",O!==void 0&&!g.hidden&&O.length<=te?`${Q.id} ${g.id}`:Q.id),w.append(Q,e(i,"p",{className:"tab-mcp-description",text:u.tool.description}),g,T,K,...H,S),i.body.append(w);let C=i.defaultView;return new Promise((h,U)=>{let k=()=>w.close("deny");u.signal.addEventListener("abort",k,{once:!0});let A,x,B=()=>{if(x!==void 0&&i.title===x.shown)i.title=x.page;x=void 0},Y=()=>{if(i.visibilityState!=="hidden")B();else if(x===void 0)x={page:i.title,shown:`${l.titlePrefix}${i.title}`},i.title=x.shown},E=(m)=>{if(m?.type==="close"&&m.target===w)return;if(Y(),clearTimeout(A),A=void 0,M=!1,P(),m?.type==="blur"||i.visibilityState==="hidden"||!i.hasFocus())return;A=setTimeout(()=>{M=!0,P()},D)},R=()=>{if(W)return;if(g.scrollTop+g.clientHeight<g.scrollHeight-2){T.hidden=!1,g.tabIndex=0;return}W=!0,T.hidden=!0,P()},F=(m)=>{if(M)return;let Z=m.target?.localName==="button";if(m.key==="Escape"||Z&&(m.key==="Enter"||m.key===" "))m.preventDefault()},X=(m)=>{if(!M)m.preventDefault()};i.addEventListener("visibilitychange",E),i.addEventListener("close",E,!0),C?.addEventListener("focus",E),C?.addEventListener("blur",E),C?.addEventListener("resize",R),g.addEventListener("scroll",R),w.addEventListener("keydown",F),w.addEventListener("keyup",F),w.addEventListener("cancel",X);let V=()=>{if(clearTimeout(A),B(),i.removeEventListener("visibilitychange",E),i.removeEventListener("close",E,!0),C?.removeEventListener("focus",E),C?.removeEventListener("blur",E),C?.removeEventListener("resize",R),u.signal.removeEventListener("abort",k),w.remove(),p.changed===I)p.changed=void 0};w.addEventListener("close",()=>{let m=w.returnValue;V(),h(m==="allow"||m==="always"?m:"deny"),f()},{once:!0});try{w.showModal()}catch(m){V(),U(m),f();return}j.focus(),E(),R()})}function re(u,i,v,p={}){let{client:f}=i,l={strings:o(p.ui),allowDelayMs:p.allowDelayMs};if(f.kind!=="relay")return J(i,v,l).then((b)=>b==="allow");let{grantId:D}=f,y=c(u),L=()=>y.has(D,i.tool);if(L())return Promise.resolve(!0);return J(i,v,{...l,alwaysAllow:p.alwaysAllow,allowedNow:L}).then((b)=>{if(b==="always"&&u.grants.some((w)=>w.grantId===D))y.add(D,i.tool);return b!=="deny"})}export{re as confirmInPage};
2
2
 
3
3
  //# debugId=9D80C139269021CA64756E2164756E21
4
- //# sourceMappingURL=confirm-y30cx7e1.min.js.map
4
+ //# sourceMappingURL=confirm-mqmvsxg1.min.js.map
@@ -1,6 +1,6 @@
1
- import{c,i,o,n,s,e,t,r,a,u,d,l}from"./index-vt5zk9me.min.js";function ze(f){let h=f.normalize("NFKD").replace(/\p{M}/gu,"").toLowerCase().replace(/[^a-z0-9_-]+/g,"-").replace(/-{2,}/g,"-").replace(/^-+|-+$/g,"").slice(0,40).replace(/-+$/,"");return h===""?"tools":h}function Qe(f){try{let h=new URL(f).href;return/^https?:\/\/[A-Za-z0-9.:[\]/_~-]+$/.test(h)?h:void 0}catch{return}}var Ke="https://ractive.ch/tab-mcp/connect/",je="mcp_2026_07_28";function Ve(f,h){let p=ze(f),M=Qe(h),w=(m)=>M===void 0?{}:{text:"Run:",command:m};return[{id:"claude",app:"Claude (claude.ai and the desktop app)",text:"Settings → Connectors → Add custom connector, then paste the address."},{id:"chatgpt",app:"ChatGPT",text:"On chatgpt.com: Plugins, add an MCP server with the address, then Connect. The Mac app needs more steps: see the guide."},{id:"claude-code",app:"Claude Code",text:"Add the address with claude mcp add --transport http.",...w(`claude mcp add --transport http ${p} ${M}`),note:[{text:"Then type "},{code:"/mcp"},{text:" in Claude Code and choose Authenticate."}]},{id:"codex",app:"Codex",text:`Run codex features enable ${je}, then add the address with codex mcp add --url and sign in with codex mcp login.`,...w(`codex features enable ${je}
1
+ import{c,i,o,n,s,e,t,r,a,u,d,l}from"./index-t33bb2g4.min.js";function ze(f){let h=f.normalize("NFKD").replace(/\p{M}/gu,"").toLowerCase().replace(/[^a-z0-9_-]+/g,"-").replace(/-{2,}/g,"-").replace(/^-+|-+$/g,"").slice(0,40).replace(/-+$/,"");return h===""?"tools":h}function Qe(f){try{let h=new URL(f).href;return/^https?:\/\/[A-Za-z0-9.:[\]/_~-]+$/.test(h)?h:void 0}catch{return}}var Ke="https://ractive.ch/tab-mcp/connect/",je="mcp_2026_07_28";function Ve(f,h){let p=ze(f),M=Qe(h),w=(m)=>M===void 0?{}:{text:"Run:",command:m};return[{id:"claude",app:"Claude (claude.ai and the desktop app)",text:"Settings → Connectors → Add custom connector, then paste the address."},{id:"chatgpt",app:"ChatGPT",text:"On chatgpt.com: Plugins, add an MCP server with the address, then Connect. The Mac app needs more steps: see the guide."},{id:"claude-code",app:"Claude Code",text:"Add the address with claude mcp add --transport http.",...w(`claude mcp add --transport http ${p} ${M}`),note:[{text:"Then type "},{code:"/mcp"},{text:" in Claude Code and choose Authenticate."}]},{id:"codex",app:"Codex",text:`Run codex features enable ${je}, then add the address with codex mcp add --url and sign in with codex mcp login.`,...w(`codex features enable ${je}
2
2
  codex mcp add ${p} --url ${M}
3
3
  codex mcp login ${p}`),note:[{text:"The last line opens the sign-in that asks for the code. Start a new chat in Codex after it connects."}]}]}function ct(f,h){return[...new Set(f.map((p)=>a(p.client,h)))]}function X(f,h){console.warn("tab-mcp: could not connect.",f);let p=f?.reason;if(p===void 0)return h.notConnected;if(p==="network")return h.unreachable;if(p==="rate_limited")return h.rateLimited;return h.refused}function rt(f,h){switch(f){case"expired":case"idle":return h.ended;case"user":return h.disconnected;case"network":case"heartbeat":case"shutdown":return h.lost;case"rate_limited":return h.rateLimited;default:return h.closed}}function lt(f,h){switch(f.identity){case"bound":return;case"pending":return h.checkingSignIn;case"refused":return f.identityMessage?n(h.signInRefusedWhy,{reason:f.identityMessage}):h.signInRefused;default:return h.signInFirst}}var xe=new WeakMap;function ut(f,h,p){let M=xe.has(f);if(xe.set(f,p===void 0?{doc:h}:{doc:h,ui:p}),M)return;f.addEventListener("replaced",(w)=>{let m=xe.get(f);if(m!==void 0&&f.state==="disconnected")pt(f,m.doc,w.detail.sibling,m.ui)})}function pt(f,h,p,M){let w=o(M);h.querySelector("dialog.tab-mcp-replaced")?.close();let{dialog:m}=d(h,"tab-mcp-replaced",w,p?w.replacedSiblingTitle:w.replacedTitle),T=e(h,"p",{className:"tab-mcp-status"});T.setAttribute("role","status"),T.hidden=!0;let y=t(h,w.close,()=>m.close(),"tab-mcp-replaced-close",p?"primary":void 0),R=e(h,"div",{className:"tab-mcp-actions"},y),P=y;if(!p){let I=t(h,w.newAddress,()=>{I.disabled=!0,T.hidden=!1,T.textContent=w.gettingNewAddress,f.newAddress().then(()=>{m.close(),f.showConnectDialog({document:h}).catch(()=>{})},(z)=>{I.disabled=!1,T.textContent=z?.reason==="replaced"?w.takenOverAgain:n(w.tryAgainOrClose,{reason:X(z,w)})})},"tab-mcp-new-address","primary");R.append(" ",I),P=I}m.append(e(h,"p",{className:"tab-mcp-description",text:p?w.replacedSibling:w.replaced}),T,R),m.addEventListener("close",()=>m.remove(),{once:!0}),h.body.append(m),m.showModal(),P.focus()}var mt=1e4;function vt(f,h,p,M="tools",w){let m=o(w),T=c(f),{dialog:y}=d(p,"tab-mcp-connect",m,m.connectTitle);y.tabIndex=-1;let R=e(p,"p",{className:"tab-mcp-status"});R.setAttribute("role","status");let P=e(p,"span",{className:"tab-mcp-announce"});P.setAttribute("aria-live","polite");for(let[g,b]of[["position","absolute"],["width","1px"],["height","1px"],["overflow","hidden"],["clip-path","inset(50%)"],["white-space","nowrap"]])P.style.setProperty(g,b);let I=(g)=>{P.textContent=P.textContent===g?`${g} `:g},z=`${i()}-success`,de=e(p,"p",{className:"tab-mcp-success-title"}),ce=e(p,"p",{className:"tab-mcp-success-next"}),ve=e(p,"span",{className:"tab-mcp-success-icon"});ve.setAttribute("aria-hidden","true");let ye=e(p,"div",{className:"tab-mcp-success",id:z},ve,e(p,"div",{className:"tab-mcp-success-text"},de,ce)),Ce=`${i()}-address`,Ne=e(p,"label",{text:m.addressLabel});Ne.htmlFor=Ce;let G=e(p,"input",{id:Ce,className:"tab-mcp-address-input"});G.readOnly=!0;let{button:Q,reset:Xe}=l(p,m,m.copyAddress,()=>G.value,()=>G.select(),I,"tab-mcp-address-copy","primary"),j=e(p,"div",{className:"tab-mcp-address"},Ne,G," ",Q),Z=t(p,m.newAddress,()=>at(),"tab-mcp-new-address"),re=e(p,"div",{className:"tab-mcp-new-address-row"},e(p,"small",{text:m.newAddressNote})," ",Z),Ae=`${i()}-new-address`,Se=e(p,"p",{id:Ae}),Ee=t(p,m.cancel,()=>{F=!1,x(),Z.focus()}),Ze=t(p,m.newAddressConfirm,()=>Ue(),"tab-mcp-new-address-confirm","danger"),K=e(p,"div",{className:"tab-mcp-new-address-question"},Se,e(p,"div",{className:"tab-mcp-actions"},Ee," ",Ze));K.setAttribute("role","group"),K.setAttribute("aria-labelledby",Ae);let U=e(p,"strong",{className:"tab-mcp-code-value"});U.style.setProperty("user-select","all"),U.style.setProperty("-webkit-user-select","all");let{button:Te,reset:Je}=l(p,m,m.copyCode,()=>U.textContent??"",()=>p.getSelection()?.selectAllChildren(U),I,"tab-mcp-code-copy"),le=e(p,"span",{},...s(p,m.codeSentence,{code:U}));le.setAttribute("aria-live","polite");let ue=e(p,"span",{className:"tab-mcp-code-used"}),pe=e(p,"p",{className:"tab-mcp-code"},le,ue," ",Te,e(p,"br"),e(p,"small",{className:"tab-mcp-code-note",text:m.codeNote})),Ie=e(p,"p",{className:"tab-mcp-sign-in",text:m.signIn}),Le=e(p,"ul"),me=e(p,"details",{className:"tab-mcp-help"},e(p,"summary",{text:m.help}),Le),De=w?.setup?.guide===void 0?Ke:w.setup.guide;if(De!==null){let g=e(p,"a",{text:m.guide});g.href=De,g.target="_blank",g.rel="noopener noreferrer",me.append(e(p,"p",{className:"tab-mcp-guide"},g))}let Ye=w?.setup?.instructions??Ve,ke=`${i()}-setup`,Me=e(p,"div",{className:"tab-mcp-setup",id:ke},j,me,pe,Ie,re,K),J=t(p,m.connectAnother,()=>{V=!V,x()},"tab-mcp-setup-toggle");J.setAttribute("aria-controls",ke);let Y=e(p,"ul"),ee=e(p,"p",{className:"tab-mcp-apps-note"});ee.setAttribute("role","status");let Pe=e(p,"div",{className:"tab-mcp-apps"},e(p,"h3",{text:m.connectedHeading}),Y,ee),$e=e(p,"small",{className:"tab-mcp-close-note",text:m.closeNote}),B=t(p,m.close,()=>y.close(),"tab-mcp-close"),te=t(p,m.done,()=>y.close(),"tab-mcp-done","primary"),H=t(p,m.connectAgain,()=>{_=void 0,f.connect().then(()=>{if(p.activeElement===B)ge().focus()},(g)=>{if(_=X(g,m),x(),p.activeElement===B&&!H.hidden)H.focus()}),x()},"tab-mcp-retry","primary"),et=e(p,"div",{className:"tab-mcp-actions"},$e," ",B,H,te);y.append(ye,R,Pe,J,Me,et,P);let V=!1,F=!1,q=!1,W=!1,_,ne,_e=new Set(f.grants.map((g)=>g.grantId)),Oe,fe,L,C=!1,Re=()=>C?te:H.hidden?B:H,ge=()=>C?te:Q,se=new Map,tt=(g)=>{let b=a(g.client,m),v=t(p,m.disconnect,()=>{ne=void 0,f.revoke(g.grantId).catch((k)=>{if(f.state==="connected")ne=k?.code==="store_unavailable"?m.storeUnavailable:m.disconnectFailed;x()}),x()},"tab-mcp-disconnect","danger");v.setAttribute("aria-label",n(m.disconnectApp,{app:b}));let A=t(p,m.askAgain,()=>T.forget(g.grantId),"tab-mcp-ask-again");A.setAttribute("aria-label",n(m.askAgainApp,{app:b}));let N=e(p,"span"),D=e(p,"div",{className:"tab-mcp-allowed"},N," ",A);return{item:e(p,"li",{},e(p,"span",{className:"tab-mcp-app"},n(m.appConnected,{app:b}))," ",v,D),disconnect:v,allowedText:N,allowedBox:D}},nt=(g)=>{if(Oe===g.address)return;Oe=g.address,Le.replaceChildren(...Ye(M,g.address).map(({app:b,text:v,command:A,note:N})=>{let D=e(p,"li",{},e(p,"strong",{text:`${b}:`}),` ${v}`);if(A!==void 0){let S=e(p,"pre",{text:A});S.dir="ltr";let{button:k}=l(p,m,n(m.copyCommand,{app:b}),()=>S.textContent??"",()=>p.getSelection()?.selectAllChildren(S),I,"tab-mcp-command-copy");D.append(e(p,"div",{className:"tab-mcp-command"},S,k))}if(N!==void 0)D.append(e(p,"small",{className:"tab-mcp-command-note"},...N.map((S)=>("code"in S)?e(p,"code",{text:S.code}):S.text)));return D}))},st=(g)=>{let b=f.pairingCode;if(b===void 0||g)clearTimeout(L),L=void 0;else if(b.code!==fe?.code){if(b.reason==="used"){if(L===void 0)L=setTimeout(()=>{L=void 0,fe=f.pairingCode,x()},mt),I(m.codeUsed)}else if(L!==void 0)clearTimeout(L),L=void 0}let v=L!==void 0;if(!v){if(U.textContent!==(b?.code??""))Je();U.textContent=b?.code??"",fe=b}return le.hidden=v,Te.hidden=v,ue.hidden=!v,ue.textContent=v?m.codeUsed:"",b!==void 0},x=()=>{let g=p.activeElement,{state:b,session:v,grants:A}=f,N=b==="connected",D=v?.pairing==="oidc",S=D?lt(f,m):void 0,k=v!==void 0&&S===void 0,He=new Set(A.map((E)=>E.grantId)),be=N&&A.some((E)=>!_e.has(E.grantId));if(_e=He,be){if(W=!1,!F)V=!1}let oe=ct(A,m);if(oe.length===0||!k)F=!1;C=!q&&N&&A.length>0;let we=oe.length===1;if(de.textContent=n(we?m.connectedOne:m.connectedMany,{apps:u(oe,m)}),ce.textContent=we?m.connectedNextOne:m.connectedNextMany,C)y.setAttribute("aria-describedby",z);else y.removeAttribute("aria-describedby");if(ye.hidden=!C,N)_=void 0;let qe=v?.appName;R.textContent=q?m.gettingNewAddress:b==="connecting"?m.connecting:b==="reconnecting"?m.reconnecting:!N?_??m.notConnected:S??(W?m.newAddressDone:qe!==void 0?n(m.readyApp,{app:qe}):m.readyPage),R.hidden=C;let it=!j.hidden;if(k&&G.value!==v.address)G.value=v.address,Xe();if(k)nt(v);if(j.hidden=me.hidden=re.hidden=!k,Z.disabled=!N,K.hidden=!F,F)Se.textContent=n(we?m.newAddressQuestionOne:m.newAddressQuestionMany,{apps:u(oe,m)});let dt=st(be);pe.hidden=D||!dt||!N,Ie.hidden=!D||f.identity!=="bound",J.hidden=!C,J.setAttribute("aria-expanded",String(V)),Me.hidden=C&&!V,Q.classList.toggle("tab-mcp-primary",!C);for(let[E,{item:ie}]of se){if(He.has(E))continue;ie.remove(),se.delete(E)}if(A.forEach((E,ie)=>{let O=se.get(E.grantId);if(O===void 0)O=tt(E),se.set(E.grantId,O);O.disconnect.disabled=!N;let We=T.list(E.grantId);if(O.allowedBox.hidden=We.length===0,O.allowedText.textContent=n(m.runsWithoutAsking,{tools:We.map(r).join(", ")}),Y.children[ie]!==O.item)Y.insertBefore(O.item,Y.children[ie]??null)}),ee.textContent=N?ne??"":m.disconnectNote,ee.hidden=N&&ne===void 0,Pe.hidden=A.length===0,$e.hidden=C||pe.hidden,B.hidden=C,te.hidden=!C,H.hidden=q||b!=="disconnected"&&b!=="reconnecting",g!==null&&g!==y&&g!==p.body&&(!g.isConnected||y.contains(g)&&g.closest("[hidden]")!==null))(K.contains(g)&&!re.hidden?Z:Re()).focus();else if(p.activeElement===y&&(C||k))ge().focus();else if(W&&k&&!it&&p.activeElement===B)Q.focus();if(be&&C)I(`${de.textContent}. ${ce.textContent}`)},at=()=>{if(f.state!=="connected")return;if(f.grants.length===0){Ue();return}F=!0,x(),Ee.focus()},Ue=()=>{q=!0,W=!1,B.focus(),F=!1,x(),f.newAddress().then(()=>{if(q=!1,W=!0,x(),!j.hidden)Q.focus()},(g)=>{q=!1,_=X(g,m),x(),Re().focus()})},ae,he=f.state==="reconnecting",Be=(g)=>{let{error:b}=g.detail;if(he&&b.reason!==void 0)ae=b},Fe=(g)=>{let{state:b,reason:v}=g.detail;if(v!==void 0&&v!=="new_address")_=rt(v,m),W=!1;if(b==="disconnected"&&he)_=ae===void 0?m.disconnected:X(ae,m);he=b==="reconnecting",ae=void 0,x()},Ge=()=>y.close();ut(f,p,w);let ot=T.onChange(x);return f.addEventListener("statechange",Fe),f.addEventListener("pairingcode",x),f.addEventListener("grantschange",x),f.addEventListener("identitychange",x),f.addEventListener("error",Be),f.addEventListener("replaced",Ge),p.body.append(y),f.startPairing(),x(),h.then(x,(g)=>{_=X(g,m),x()}),new Promise((g)=>{if(y.addEventListener("close",()=>{clearTimeout(L),f.stopPairing(),ot(),f.removeEventListener("statechange",Fe),f.removeEventListener("pairingcode",x),f.removeEventListener("grantschange",x),f.removeEventListener("identitychange",x),f.removeEventListener("error",Be),f.removeEventListener("replaced",Ge),y.remove(),g()},{once:!0}),y.showModal(),C||!j.hidden)ge().focus();else y.focus()})}export{vt as showConnectDialog};
4
4
 
5
5
  //# debugId=3DB23946634FC9AE64756E2164756E21
6
- //# sourceMappingURL=connect-bbhj2y7w.min.js.map
6
+ //# sourceMappingURL=connect-c7wn48yp.min.js.map