@ractive-ch/tab-mcp-client 0.7.0 → 0.9.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.
package/README.md CHANGED
@@ -6,7 +6,7 @@ relay. The page connects to the relay and gets an address. The user adds that ad
6
6
  their AI app and types a pairing code from the page; the AI app then calls the page's
7
7
  tools while the tab stays open. Nothing is installed on the user's computer.
8
8
 
9
- **Status: 0.7.0.** Until 1.0, a new minor version can still change the API. Which AI apps
9
+ **Status: 0.9.0.** Until 1.0, a new minor version can still change the API. Which AI apps
10
10
  work is listed in [compatibility](https://github.com/ractive/tab-mcp/blob/main/docs/compatibility.md).
11
11
 
12
12
  ## You need a relay
@@ -22,7 +22,7 @@ docker run --rm -p 8080:8080 \
22
22
  -e TAB_MCP_PUBLIC_URL=http://localhost:8080 \
23
23
  -e TAB_MCP_ALLOWED_ORIGINS=http://localhost:3000 \
24
24
  -e TAB_MCP_STORE=memory \
25
- ractive/tab-mcp:0.4.0
25
+ ractive/tab-mcp:0.5.1
26
26
  ```
27
27
 
28
28
  For production, see
@@ -38,7 +38,7 @@ Or without a bundler, from a CDN as an ES module:
38
38
 
39
39
  ```html
40
40
  <script type="module">
41
- import { TabMcp } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.7.0/cdn/tab-mcp-client.min.js";
41
+ import { TabMcp } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.9.0/cdn/tab-mcp-client.min.js";
42
42
  </script>
43
43
  ```
44
44
 
@@ -71,6 +71,14 @@ button.addEventListener("click", () => mcp.showConnectDialog());
71
71
 
72
72
  Importing the library loads only a small core; `connect()` loads the rest.
73
73
 
74
+ `server` is what the AI app sees: `name`, `version`, optional `title` and
75
+ `instructions`, and `icons`. Without `icons`, the page's own `<link rel="icon">` and
76
+ `<link rel="apple-touch-icon">` are sent, so an AI app that shows icons can show the
77
+ page's for its connector. `icons: [{ src, mimeType?, sizes?, theme? }]` (MCP's `Icon`)
78
+ sets them instead, `icons: []` sends none. At most 8: `https:` (or `http:`) URLs, or
79
+ PNG, JPEG, GIF, WebP or ICO `data:` URIs up to 16 KiB (no inline SVG). They go only in
80
+ `server/discover`. An icon on `localhost` reaches only an AI app on the same computer.
81
+
74
82
  ### Tools
75
83
 
76
84
  `registerTool(tool, { signal })` takes a tool in the shape of the WebMCP draft's
@@ -97,10 +105,16 @@ added and removed tools.
97
105
  ### Consequential tools
98
106
 
99
107
  Mark tools that change or delete something with `consequentialHint: true`. The page then
100
- asks the user before every call ("Allow", "Always allow" or "Don't allow"), showing the AI
101
- app and the arguments. "Always allow" lets that tool run without asking for that AI app
102
- until the page is reloaded or the app is disconnected. A refusal reaches the AI app as an
103
- error result, and so does a call whose tool was removed while the user was asked.
108
+ asks the user before every call ("Don't allow" or "Allow"), showing the AI app and the
109
+ arguments. A refusal reaches the AI app as an error result, and so does a call whose tool
110
+ was removed while the user was asked.
111
+
112
+ `alwaysAllow: true` adds "Always allow", which lets that tool run without asking for that
113
+ AI app until the page is reloaded or the app is disconnected. It is off by default: it
114
+ lifts the only brake at run time, which is what a prompt injection needs, and the relay
115
+ cannot help, since its one OAuth scope (`tools`) covers every tool of the page. Consent
116
+ per tool is the page's. Turn it on only for tools whose calls the user need not check one
117
+ by one.
104
118
 
105
119
  Tools are called while the user is in the AI app, so the dialog often opens in a tab in
106
120
  the background. "Allow" and "Always allow" can be clicked only once the page has been
@@ -170,6 +184,70 @@ sign-in page points users to it when someone else may be guessing codes. A page
170
184
  own UI calls `newAddress()` from a click. Connected apps keep working after a reload once the page connects
171
185
  again; while the page is closed, they get "the page is not open".
172
186
 
187
+ When another tab or program connects with the same address, it takes the address over:
188
+ the page gets `disconnected` with reason `replaced` at once, then the event `replaced`,
189
+ and does not reconnect by itself. Tabs of the same page say on a `BroadcastChannel` (per
190
+ relay and storage key; it carries neither the secret nor the address) when the relay
191
+ accepted their session, so `replaced` says which it probably was:
192
+
193
+ - `event.detail.sibling` is `true`: a tab of the same page in this browser said so within
194
+ the last 10 seconds. That message usually comes just after the takeover, so the
195
+ library waits up to a second for it, and `replaced` may come that much after
196
+ `disconnected`. The usual cause, and harmless. Once the page has opened the default
197
+ dialog, the library shows "Opened in another tab".
198
+ - `false`: none did (or the browser has no `BroadcastChannel`). It may be a program with
199
+ a copy of the address secret, and the AI apps paired with the address now talk to it.
200
+ The library shows "Another tab or program took over this page" with "New address".
201
+
202
+ After a takeover, `newAddress()` (from the `replaced` listener, before it, or later)
203
+ first takes the address back: it connects with the old secret and asks the relay to
204
+ revoke every grant of the address in the same step (`hello.revokeAll`), and makes the new
205
+ address only once the relay confirmed that no grant is left. If the address is taken
206
+ over again before that, it rejects with an error whose `reason` is `"replaced"` and keeps
207
+ the old secret, so calling it again takes it back again. Against a relay of 0.4 or older
208
+ it sends `grants.revokeAll` and waits until every grant is gone. Then it connects with
209
+ the new address; the default notice opens the connect dialog to add it to the AI apps.
210
+
211
+ The default dialog closes when the page is replaced, and the notice appears also when the
212
+ dialog is closed, but only once the page has opened the dialog: a page that connects on
213
+ load with `connect({ resume: true })` and never opens it shows its own message. A page
214
+ with its own UI shows the same from `replaced`:
215
+
216
+ ```ts
217
+ mcp.addEventListener("replaced", (e) => {
218
+ if (e.detail.sibling) showNote("Opened in another tab.");
219
+ else showWarning("Another tab or program took over this page's address.", {
220
+ action: "New address",
221
+ onClick: () => mcp.newAddress(), // from the click
222
+ });
223
+ });
224
+ ```
225
+
226
+ Script on the page's origin can post on the channel and make a takeover look like a
227
+ sibling; such script can read the secret anyway, so `sibling` is a hint, not a proof.
228
+
229
+ ### Keeping the address safe
230
+
231
+ Whoever has the address secret can take over the page's address from anywhere, and the
232
+ AI apps paired with it then send their arguments to them and get their tool descriptions
233
+ and results, until the page gets a new address. They get no token and cannot pair a new
234
+ app without a code. Script on your origin (cross-site scripting, a compromised
235
+ third-party script, another page on the same origin) or access to the device can copy it
236
+ ([threat model](https://github.com/ractive/tab-mcp/blob/main/docs/threat-model.md), A4).
237
+
238
+ - For a page with user accounts, use [identity binding](#identity-binding-no-code): a
239
+ copied secret then gets nothing, since a session needs a fresh assertion from your
240
+ backend.
241
+ - Run the page on its own origin, not a shared one such as `*.github.io`, and keep
242
+ third-party scripts off it.
243
+ - On a page that pairs by code, grants follow the browser profile, not the person: on a
244
+ shared profile, or in a web app with accounts that pairs by code, the next user of the
245
+ page gets the AI apps the previous one paired. Call `newAddress()` when the user logs
246
+ out, or use identity binding.
247
+ - The page origin that the relay's sign-in page shows is what the page's browser
248
+ reported; a program can claim any origin. Do not tell users it proves which page they
249
+ pair with.
250
+
173
251
  When the connection breaks (reason `network`, `heartbeat` or `shutdown`: a dropped
174
252
  network, a phone pausing the tab in the background, a relay restart), the library
175
253
  connects again by itself: after 5, 10, 20 and 40 seconds, then every 60 seconds, and at
@@ -223,7 +301,8 @@ Instead of `showConnectDialog()`, use `connect()`, `disconnect()`, `newAddress()
223
301
  `startPairing()` and `stopPairing()` (codes come only while pairing is on),
224
302
  `revoke(grantId)`, the properties `state`, `address`, `pairingCode`, `grants`,
225
303
  `reconnecting` and `tools`, and the events `statechange`, `connected`, `disconnected`,
226
- `pairingcode`, `grantschange`, `reconnecting`, `toolschange`, `replaced` and `error`. For an activity log, `toolcall`
304
+ `pairingcode`, `grantschange`, `reconnecting`, `toolschange`, `replaced` (with
305
+ `detail.sibling`, see above) and `error`. For an activity log, `toolcall`
227
306
  and `toolcallend` report every call by an AI app: its id, tool, arguments and AI app as it
228
307
  starts, then its outcome (`ok`, `error`, `declined` or `cancelled`), result and duration.
229
308
 
@@ -276,14 +355,17 @@ rule with two classes, such as `.tab-mcp-dialog .tab-mcp-primary` (0,2,0), wins
276
355
  of them. A page rule of one element and one pseudo-class still changes a property that the
277
356
  dialogs set only in their base rules (for example `button:hover { padding: 0 }`). Write
278
357
  overrides outside cascade layers: the dialogs' rules are not in a layer, so they win over
279
- any layered rule. Both dialogs are `dialog.tab-mcp-dialog`; the connect dialog is
358
+ any layered rule. All dialogs are `dialog.tab-mcp-dialog`; the connect dialog is
280
359
  `.tab-mcp-connect` (with `.tab-mcp-status`, `.tab-mcp-address`, `.tab-mcp-code`,
281
360
  `.tab-mcp-code-value`, `.tab-mcp-help`, `.tab-mcp-apps`, `.tab-mcp-app`,
282
361
  `.tab-mcp-new-address-question`, `.tab-mcp-actions`), the confirmation is
283
362
  `.tab-mcp-confirm` (with `.tab-mcp-description`, `.tab-mcp-arguments`,
284
363
  `.tab-mcp-always-note`, and the buttons `.tab-mcp-deny`, `.tab-mcp-allow`,
285
- `.tab-mcp-always`). Buttons are `.tab-mcp-primary` (the one next step: Copy the
286
- address, Done, and "Don't allow", the safe choice), `.tab-mcp-danger` (Disconnect and
364
+ `.tab-mcp-always`, with `alwaysAllow`), and the notice after `replaced` is
365
+ `.tab-mcp-replaced` (with `.tab-mcp-description`, `.tab-mcp-status`, and the buttons
366
+ `.tab-mcp-replaced-close` and `.tab-mcp-new-address`). Buttons are `.tab-mcp-primary` (the one
367
+ next step: Copy the address, Done, "Don't allow", the safe choice, and the notice's "New
368
+ address", or its "Close" after a sibling tab), `.tab-mcp-danger` (Disconnect and
287
369
  "Disconnect and get new address") or plain; every Copy button is also `.tab-mcp-copy`, and
288
370
  the Disconnect buttons in the apps list are `.tab-mcp-disconnect`. For example:
289
371
 
package/address.d.ts ADDED
@@ -0,0 +1,14 @@
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.
5
+ */
6
+ /**
7
+ * The address id of a secret, as the relay derives it (DEC-027):
8
+ * 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
+ */
12
+ 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;
@@ -0,0 +1,11 @@
1
+ var at=/^(?:\d{1,4}x\d{1,4}|any)$/;function ut(e){let{src:t,mimeType:r,sizes:s,theme:i}=e;if(typeof t!=="string")return;let d=/^https?:/i.test(t)&&t.length<=2048,o=/^data:image\/(?:png|jpeg|gif|webp|x-icon|vnd\.microsoft\.icon)[;,]/i.test(t)&&t.length<=16384;if(!d&&!o)return;let u={src:t};if(typeof r==="string"&&/^image\/[\w.+-]+$/i.test(r))u.mimeType=r.toLowerCase();let x=Array.isArray(s)?s.map((O)=>String(O).toLowerCase()).filter((O)=>at.test(O)):[];if(x.length>0)u.sizes=x;if(i==="light"||i==="dark")u.theme=i;return u}function xe(e){let t=[];for(let r of e){let s=typeof r==="object"&&r!==null?ut(r):void 0;if(s!==void 0)t.push(s);if(t.length===8)break}return t}function Ne(e=globalThis.document){try{let t=e?.querySelectorAll('link[rel~="icon" i], link[rel~="apple-touch-icon" i]');return xe([...t??[]].filter((r)=>r.getAttribute("href")?.trim()).map((r)=>{let s={src:r.href};if(r.type)s.mimeType=r.type;let i=r.getAttribute("sizes");if(i)s.sizes=i.trim().split(/\s+/);let d=/prefers-color-scheme:\s*(light|dark)/i.exec(r.media);if(d)s.theme=d[1]?.toLowerCase();return s}))}catch{return[]}}function ae(e,t){let r=typeof e;if(r!==typeof t)return!1;if(Array.isArray(e)){if(!Array.isArray(t))return!1;let s=e.length;if(s!==t.length)return!1;for(let i=0;i<s;i++)if(!ae(e[i],t[i]))return!1;return!0}if(r==="object"){if(!e||!t)return e===t;let s=Object.keys(e),i=Object.keys(t);if(s.length!==i.length)return!1;for(let o of s)if(!ae(e[o],t[o]))return!1;return!0}return e===t}function U(e){return encodeURI(lt(e))}function lt(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}var ft={prefixItems:!0,items:!0,allOf:!0,anyOf:!0,oneOf:!0},ct={$defs:!0,definitions:!0,properties:!0,patternProperties:!0,dependentSchemas:!0},pt={id:!0,$id:!0,$ref:!0,$schema:!0,$anchor:!0,$vocabulary:!0,$comment:!0,default:!0,enum:!0,const:!0,required:!0,type:!0,maximum:!0,minimum:!0,exclusiveMaximum:!0,exclusiveMinimum:!0,multipleOf:!0,maxLength:!0,minLength:!0,pattern:!0,format:!0,maxItems:!0,minItems:!0,uniqueItems:!0,maxProperties:!0,minProperties:!0},mt=typeof self<"u"&&self.location&&self.location.origin!=="null"?new URL(self.location.origin+self.location.pathname+location.search):new URL("https://github.com/cfworker");function ee(e,t=Object.create(null),r=mt,s=""){if(e&&typeof e==="object"&&!Array.isArray(e)){let d=e.$id||e.id;if(d){let o=new URL(d,r.href);if(o.hash.length>1)t[o.href]=e;else if(o.hash="",s==="")r=o;else ee(e,t,r)}}else if(e!==!0&&e!==!1)return t;let i=r.href+(s?"#"+s:"");if(t[i]!==void 0)throw Error(`Duplicate schema URI "${i}".`);if(t[i]=e,e===!0||e===!1)return t;if(e.__absolute_uri__===void 0)Object.defineProperty(e,"__absolute_uri__",{enumerable:!1,value:i});if(e.$ref&&e.__absolute_ref__===void 0){let d=new URL(e.$ref,r.href);d.hash=d.hash,Object.defineProperty(e,"__absolute_ref__",{enumerable:!1,value:d.href})}if(e.$recursiveRef&&e.__absolute_recursive_ref__===void 0){let d=new URL(e.$recursiveRef,r.href);d.hash=d.hash,Object.defineProperty(e,"__absolute_recursive_ref__",{enumerable:!1,value:d.href})}if(e.$anchor){let d=new URL("#"+e.$anchor,r.href);t[d.href]=e}for(let d in e){if(pt[d])continue;let o=`${s}/${U(d)}`,u=e[d];if(Array.isArray(u)){if(ft[d]){let x=u.length;for(let O=0;O<x;O++)ee(u[O],t,r,`${o}/${O}`)}}else if(ct[d])for(let x in u)ee(u[x],t,r,`${o}/${U(x)}`);else ee(u,t,r,o)}return t}var yt=/^(\d\d\d\d)-(\d\d)-(\d\d)$/,gt=[0,31,28,31,30,31,30,31,31,30,31,30,31],ht=/^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|[+-]\d\d(?::?\d\d)?)?$/i,$t=/^(?=.{1,253}\.?$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*\.?$/i,bt=/^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'"()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\?(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i,wt=/^(?:(?:[^\x00-\x20"'<>%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i,kt=/^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u{00a1}-\u{ffff}0-9]+-?)*[a-z\u{00a1}-\u{ffff}0-9]+)(?:\.(?:[a-z\u{00a1}-\u{ffff}0-9]+-?)*[a-z\u{00a1}-\u{ffff}0-9]+)*(?:\.(?:[a-z\u{00a1}-\u{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/iu,Rt=/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i,It=/^(?:\/(?:[^~/]|~0|~1)*)*$/,xt=/^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i,Tt=/^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/,_t=(e)=>{if(e[0]==='"')return!1;let[t,r,...s]=e.split("@");if(!t||!r||s.length!==0||t.length>64||r.length>253)return!1;if(t[0]==="."||t.endsWith(".")||t.includes(".."))return!1;if(!/^[a-z0-9.-]+$/i.test(r)||!/^[a-z0-9.!#$%&'*+/=?^_`{|}~-]+$/i.test(t))return!1;return r.split(".").every((i)=>/^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/i.test(i))},vt=/^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,St=/^((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))$/i,Mt=(e)=>e.length>1&&e.length<80&&(/^P\d+([.,]\d+)?W$/.test(e)||/^P[\dYMDTHS]*(\d[.,]\d+)?[YMDHS]$/.test(e)&&/^P([.,\d]+Y)?([.,\d]+M)?([.,\d]+D)?(T([.,\d]+H)?([.,\d]+M)?([.,\d]+S)?)?$/.test(e));function Y(e){return e.test.bind(e)}var Te={date:je,time:qe.bind(void 0,!1),"date-time":At,duration:Mt,uri:Nt,"uri-reference":Y(bt),"uri-template":Y(wt),url:Y(kt),email:_t,hostname:Y($t),ipv4:Y(vt),ipv6:Y(St),regex:qt,uuid:Y(Rt),"json-pointer":Y(It),"json-pointer-uri-fragment":Y(xt),"relative-json-pointer":Y(Tt)};function Et(e){return e%4===0&&(e%100!==0||e%400===0)}function je(e){let t=e.match(yt);if(!t)return!1;let r=+t[1],s=+t[2],i=+t[3];return s>=1&&s<=12&&i>=1&&i<=(s==2&&Et(r)?29:gt[s])}function qe(e,t){let r=t.match(ht);if(!r)return!1;let s=+r[1],i=+r[2],d=+r[3],o=!!r[5];return(s<=23&&i<=59&&d<=59||s==23&&i==59&&d==60)&&(!e||o)}var Ot=/t|\s/i;function At(e){let t=e.split(Ot);return t.length==2&&je(t[0])&&qe(!0,t[1])}var Pt=/\/|:/,Ct=/^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;function Nt(e){return Pt.test(e)&&Ct.test(e)}var jt=/[^\\]\\Z/;function qt(e){if(jt.test(e))return!1;try{return new RegExp(e,"u"),!0}catch(t){return!1}}function ze(e){let t=0,r=e.length,s=0,i;while(s<r)if(t++,i=e.charCodeAt(s++),i>=55296&&i<=56319&&s<r){if(i=e.charCodeAt(s),(i&64512)==56320)s++}return t}function E(e,t,r="2019-09",s=ee(t),i=!0,d=null,o="#",u="#",x=Object.create(null)){if(t===!0)return{valid:!0,errors:[]};if(t===!1)return{valid:!1,errors:[{instanceLocation:o,keyword:"false",keywordLocation:o,error:"False boolean schema."}]};let O=typeof e,v;switch(O){case"boolean":case"number":case"string":v=O;break;case"object":if(e===null)v="null";else if(Array.isArray(e))v="array";else v="object";break;default:throw Error(`Instances of "${O}" type are not supported.`)}let{$ref:B,$recursiveRef:D,$recursiveAnchor:V,type:C,const:G,enum:W,required:Q,not:L,anyOf:A,allOf:l,oneOf:g,if:R,then:T,else:y,format:n,properties:h,patternProperties:p,additionalProperties:S,unevaluatedProperties:_,minProperties:N,maxProperties:P,propertyNames:K,dependentRequired:z,dependentSchemas:j,dependencies:H,prefixItems:fe,items:re,additionalItems:Me,unevaluatedItems:Ee,contains:Oe,minContains:X,maxContains:me,minItems:Re,maxItems:Ie,uniqueItems:it,minimum:ne,maximum:oe,exclusiveMinimum:ce,exclusiveMaximum:pe,multipleOf:ye,minLength:ge,maxLength:he,pattern:Ae,__absolute_ref__:$e,__absolute_recursive_ref__:dt}=t,f=[];if(V===!0&&d===null)d=t;if(D==="#"){let b=d===null?s[dt]:d,m=`${u}/$recursiveRef`,I=E(e,d===null?t:d,r,s,i,b,o,m,x);if(!I.valid)f.push({instanceLocation:o,keyword:"$recursiveRef",keywordLocation:m,error:"A subschema had errors."},...I.errors)}if(B!==void 0){let m=s[$e||B];if(m===void 0){let a=`Unresolved $ref "${B}".`;if($e&&$e!==B)a+=` Absolute URI "${$e}".`;throw a+=`
2
+ Known schemas:
3
+ - ${Object.keys(s).join(`
4
+ - `)}`,Error(a)}let I=`${u}/$ref`,c=E(e,m,r,s,i,d,o,I,x);if(!c.valid)f.push({instanceLocation:o,keyword:"$ref",keywordLocation:I,error:"A subschema had errors."},...c.errors);if(r==="4"||r==="7")return{valid:f.length===0,errors:f}}if(Array.isArray(C)){let b=C.length,m=!1;for(let I=0;I<b;I++)if(v===C[I]||C[I]==="integer"&&v==="number"&&e%1===0&&e===e){m=!0;break}if(!m)f.push({instanceLocation:o,keyword:"type",keywordLocation:`${u}/type`,error:`Instance type "${v}" is invalid. Expected "${C.join('", "')}".`})}else if(C==="integer"){if(v!=="number"||e%1||e!==e)f.push({instanceLocation:o,keyword:"type",keywordLocation:`${u}/type`,error:`Instance type "${v}" is invalid. Expected "${C}".`})}else if(C!==void 0&&v!==C)f.push({instanceLocation:o,keyword:"type",keywordLocation:`${u}/type`,error:`Instance type "${v}" is invalid. Expected "${C}".`});if(G!==void 0){if(v==="object"||v==="array"){if(!ae(e,G))f.push({instanceLocation:o,keyword:"const",keywordLocation:`${u}/const`,error:`Instance does not match ${JSON.stringify(G)}.`})}else if(e!==G)f.push({instanceLocation:o,keyword:"const",keywordLocation:`${u}/const`,error:`Instance does not match ${JSON.stringify(G)}.`})}if(W!==void 0){if(v==="object"||v==="array"){if(!W.some((b)=>ae(e,b)))f.push({instanceLocation:o,keyword:"enum",keywordLocation:`${u}/enum`,error:`Instance does not match any of ${JSON.stringify(W)}.`})}else if(!W.some((b)=>e===b))f.push({instanceLocation:o,keyword:"enum",keywordLocation:`${u}/enum`,error:`Instance does not match any of ${JSON.stringify(W)}.`})}if(L!==void 0){let b=`${u}/not`;if(E(e,L,r,s,i,d,o,b).valid)f.push({instanceLocation:o,keyword:"not",keywordLocation:b,error:'Instance matched "not" schema.'})}let be=[];if(A!==void 0){let b=`${u}/anyOf`,m=f.length,I=!1;for(let c=0;c<A.length;c++){let a=A[c],k=Object.create(x),w=E(e,a,r,s,i,V===!0?d:null,o,`${b}/${c}`,k);if(f.push(...w.errors),I=I||w.valid,w.valid)be.push(k)}if(I)f.length=m;else f.splice(m,0,{instanceLocation:o,keyword:"anyOf",keywordLocation:b,error:"Instance does not match any subschemas."})}if(l!==void 0){let b=`${u}/allOf`,m=f.length,I=!0;for(let c=0;c<l.length;c++){let a=l[c],k=Object.create(x),w=E(e,a,r,s,i,V===!0?d:null,o,`${b}/${c}`,k);if(f.push(...w.errors),I=I&&w.valid,w.valid)be.push(k)}if(I)f.length=m;else f.splice(m,0,{instanceLocation:o,keyword:"allOf",keywordLocation:b,error:"Instance does not match every subschema."})}if(g!==void 0){let b=`${u}/oneOf`,m=f.length,I=g.filter((c,a)=>{let k=Object.create(x),w=E(e,c,r,s,i,V===!0?d:null,o,`${b}/${a}`,k);if(f.push(...w.errors),w.valid)be.push(k);return w.valid}).length;if(I===1)f.length=m;else f.splice(m,0,{instanceLocation:o,keyword:"oneOf",keywordLocation:b,error:`Instance does not match exactly one subschema (${I} matches).`})}if(v==="object"||v==="array")Object.assign(x,...be);if(R!==void 0){let b=`${u}/if`;if(E(e,R,r,s,i,d,o,b,x).valid){if(T!==void 0){let I=E(e,T,r,s,i,d,o,`${u}/then`,x);if(!I.valid)f.push({instanceLocation:o,keyword:"if",keywordLocation:b,error:'Instance does not match "then" schema.'},...I.errors)}}else if(y!==void 0){let I=E(e,y,r,s,i,d,o,`${u}/else`,x);if(!I.valid)f.push({instanceLocation:o,keyword:"if",keywordLocation:b,error:'Instance does not match "else" schema.'},...I.errors)}}if(v==="object"){if(Q!==void 0){for(let c of Q)if(!(c in e))f.push({instanceLocation:o,keyword:"required",keywordLocation:`${u}/required`,error:`Instance does not have required property "${c}".`})}let b=Object.keys(e);if(N!==void 0&&b.length<N)f.push({instanceLocation:o,keyword:"minProperties",keywordLocation:`${u}/minProperties`,error:`Instance does not have at least ${N} properties.`});if(P!==void 0&&b.length>P)f.push({instanceLocation:o,keyword:"maxProperties",keywordLocation:`${u}/maxProperties`,error:`Instance does not have at least ${P} properties.`});if(K!==void 0){let c=`${u}/propertyNames`;for(let a in e){let k=`${o}/${U(a)}`,w=E(a,K,r,s,i,d,k,c);if(!w.valid)f.push({instanceLocation:o,keyword:"propertyNames",keywordLocation:c,error:`Property name "${a}" does not match schema.`},...w.errors)}}if(z!==void 0){let c=`${u}/dependantRequired`;for(let a in z)if(a in e){let k=z[a];for(let w of k)if(!(w in e))f.push({instanceLocation:o,keyword:"dependentRequired",keywordLocation:c,error:`Instance has "${a}" but does not have "${w}".`})}}if(j!==void 0)for(let c in j){let a=`${u}/dependentSchemas`;if(c in e){let k=E(e,j[c],r,s,i,d,o,`${a}/${U(c)}`,x);if(!k.valid)f.push({instanceLocation:o,keyword:"dependentSchemas",keywordLocation:a,error:`Instance has "${c}" but does not match dependant schema.`},...k.errors)}}if(H!==void 0){let c=`${u}/dependencies`;for(let a in H)if(a in e){let k=H[a];if(Array.isArray(k)){for(let w of k)if(!(w in e))f.push({instanceLocation:o,keyword:"dependencies",keywordLocation:c,error:`Instance has "${a}" but does not have "${w}".`})}else{let w=E(e,k,r,s,i,d,o,`${c}/${U(a)}`);if(!w.valid)f.push({instanceLocation:o,keyword:"dependencies",keywordLocation:c,error:`Instance has "${a}" but does not match dependant schema.`},...w.errors)}}}let m=Object.create(null),I=!1;if(h!==void 0){let c=`${u}/properties`;for(let a in h){if(!(a in e))continue;let k=`${o}/${U(a)}`,w=E(e[a],h[a],r,s,i,d,k,`${c}/${U(a)}`);if(w.valid)x[a]=m[a]=!0;else if(I=i,f.push({instanceLocation:o,keyword:"properties",keywordLocation:c,error:`Property "${a}" does not match schema.`},...w.errors),I)break}}if(!I&&p!==void 0){let c=`${u}/patternProperties`;for(let a in p){let k=new RegExp(a,"u"),w=p[a];for(let J in e){if(!k.test(J))continue;let Pe=`${o}/${U(J)}`,Ce=E(e[J],w,r,s,i,d,Pe,`${c}/${U(a)}`);if(Ce.valid)x[J]=m[J]=!0;else I=i,f.push({instanceLocation:o,keyword:"patternProperties",keywordLocation:c,error:`Property "${J}" matches pattern "${a}" but does not match associated schema.`},...Ce.errors)}}}if(!I&&S!==void 0){let c=`${u}/additionalProperties`;for(let a in e){if(m[a])continue;let k=`${o}/${U(a)}`,w=E(e[a],S,r,s,i,d,k,c);if(w.valid)x[a]=!0;else I=i,f.push({instanceLocation:o,keyword:"additionalProperties",keywordLocation:c,error:`Property "${a}" does not match additional properties schema.`},...w.errors)}}else if(!I&&_!==void 0){let c=`${u}/unevaluatedProperties`;for(let a in e)if(!x[a]){let k=`${o}/${U(a)}`,w=E(e[a],_,r,s,i,d,k,c);if(w.valid)x[a]=!0;else f.push({instanceLocation:o,keyword:"unevaluatedProperties",keywordLocation:c,error:`Property "${a}" does not match unevaluated properties schema.`},...w.errors)}}}else if(v==="array"){if(Ie!==void 0&&e.length>Ie)f.push({instanceLocation:o,keyword:"maxItems",keywordLocation:`${u}/maxItems`,error:`Array has too many items (${e.length} > ${Ie}).`});if(Re!==void 0&&e.length<Re)f.push({instanceLocation:o,keyword:"minItems",keywordLocation:`${u}/minItems`,error:`Array has too few items (${e.length} < ${Re}).`});let b=e.length,m=0,I=!1;if(fe!==void 0){let c=`${u}/prefixItems`,a=Math.min(fe.length,b);for(;m<a;m++){let k=E(e[m],fe[m],r,s,i,d,`${o}/${m}`,`${c}/${m}`);if(x[m]=!0,!k.valid){if(I=i,f.push({instanceLocation:o,keyword:"prefixItems",keywordLocation:c,error:"Items did not match schema."},...k.errors),I)break}}}if(re!==void 0){let c=`${u}/items`;if(Array.isArray(re)){let a=Math.min(re.length,b);for(;m<a;m++){let k=E(e[m],re[m],r,s,i,d,`${o}/${m}`,`${c}/${m}`);if(x[m]=!0,!k.valid){if(I=i,f.push({instanceLocation:o,keyword:"items",keywordLocation:c,error:"Items did not match schema."},...k.errors),I)break}}}else for(;m<b;m++){let a=E(e[m],re,r,s,i,d,`${o}/${m}`,c);if(x[m]=!0,!a.valid){if(I=i,f.push({instanceLocation:o,keyword:"items",keywordLocation:c,error:"Items did not match schema."},...a.errors),I)break}}if(!I&&Me!==void 0){let a=`${u}/additionalItems`;for(;m<b;m++){let k=E(e[m],Me,r,s,i,d,`${o}/${m}`,a);if(x[m]=!0,!k.valid)I=i,f.push({instanceLocation:o,keyword:"additionalItems",keywordLocation:a,error:"Items did not match additional items schema."},...k.errors)}}}if(Oe!==void 0)if(b===0&&X===void 0)f.push({instanceLocation:o,keyword:"contains",keywordLocation:`${u}/contains`,error:"Array is empty. It must contain at least one item matching the schema."});else if(X!==void 0&&b<X)f.push({instanceLocation:o,keyword:"minContains",keywordLocation:`${u}/minContains`,error:`Array has less items (${b}) than minContains (${X}).`});else{let c=`${u}/contains`,a=f.length,k=0;for(let w=0;w<b;w++){let J=E(e[w],Oe,r,s,i,d,`${o}/${w}`,c);if(J.valid)x[w]=!0,k++;else f.push(...J.errors)}if(k>=(X||0))f.length=a;if(X===void 0&&me===void 0&&k===0)f.splice(a,0,{instanceLocation:o,keyword:"contains",keywordLocation:c,error:"Array does not contain item matching schema."});else if(X!==void 0&&k<X)f.push({instanceLocation:o,keyword:"minContains",keywordLocation:`${u}/minContains`,error:`Array must contain at least ${X} items matching schema. Only ${k} items were found.`});else if(me!==void 0&&k>me)f.push({instanceLocation:o,keyword:"maxContains",keywordLocation:`${u}/maxContains`,error:`Array may contain at most ${me} items matching schema. ${k} items were found.`})}if(!I&&Ee!==void 0){let c=`${u}/unevaluatedItems`;for(m;m<b;m++){if(x[m])continue;let a=E(e[m],Ee,r,s,i,d,`${o}/${m}`,c);if(x[m]=!0,!a.valid)f.push({instanceLocation:o,keyword:"unevaluatedItems",keywordLocation:c,error:"Items did not match unevaluated items schema."},...a.errors)}}if(it)for(let c=0;c<b;c++){let a=e[c],k=typeof a==="object"&&a!==null;for(let w=0;w<b;w++){if(c===w)continue;let J=e[w];if(a===J||k&&(typeof J==="object"&&J!==null)&&ae(a,J))f.push({instanceLocation:o,keyword:"uniqueItems",keywordLocation:`${u}/uniqueItems`,error:`Duplicate items at indexes ${c} and ${w}.`}),c=Number.MAX_SAFE_INTEGER,w=Number.MAX_SAFE_INTEGER}}}else if(v==="number"){if(r==="4"){if(ne!==void 0&&(ce===!0&&e<=ne||e<ne))f.push({instanceLocation:o,keyword:"minimum",keywordLocation:`${u}/minimum`,error:`${e} is less than ${ce?"or equal to ":""} ${ne}.`});if(oe!==void 0&&(pe===!0&&e>=oe||e>oe))f.push({instanceLocation:o,keyword:"maximum",keywordLocation:`${u}/maximum`,error:`${e} is greater than ${pe?"or equal to ":""} ${oe}.`})}else{if(ne!==void 0&&e<ne)f.push({instanceLocation:o,keyword:"minimum",keywordLocation:`${u}/minimum`,error:`${e} is less than ${ne}.`});if(oe!==void 0&&e>oe)f.push({instanceLocation:o,keyword:"maximum",keywordLocation:`${u}/maximum`,error:`${e} is greater than ${oe}.`});if(ce!==void 0&&e<=ce)f.push({instanceLocation:o,keyword:"exclusiveMinimum",keywordLocation:`${u}/exclusiveMinimum`,error:`${e} is less than ${ce}.`});if(pe!==void 0&&e>=pe)f.push({instanceLocation:o,keyword:"exclusiveMaximum",keywordLocation:`${u}/exclusiveMaximum`,error:`${e} is greater than or equal to ${pe}.`})}if(ye!==void 0){let b=e%ye;if(Math.abs(0-b)>=0.00000011920929&&Math.abs(ye-b)>=0.00000011920929)f.push({instanceLocation:o,keyword:"multipleOf",keywordLocation:`${u}/multipleOf`,error:`${e} is not a multiple of ${ye}.`})}}else if(v==="string"){let b=ge===void 0&&he===void 0?0:ze(e);if(ge!==void 0&&b<ge)f.push({instanceLocation:o,keyword:"minLength",keywordLocation:`${u}/minLength`,error:`String is too short (${b} < ${ge}).`});if(he!==void 0&&b>he)f.push({instanceLocation:o,keyword:"maxLength",keywordLocation:`${u}/maxLength`,error:`String is too long (${b} > ${he}).`});if(Ae!==void 0&&!new RegExp(Ae,"u").test(e))f.push({instanceLocation:o,keyword:"pattern",keywordLocation:`${u}/pattern`,error:"String does not match pattern."});if(n!==void 0&&Te[n]&&!Te[n](e))f.push({instanceLocation:o,keyword:"format",keywordLocation:`${u}/format`,error:`String does not match format "${n}".`})}return{valid:f.length===0,errors:f}}var Je="ch.ractive.tab-mcp/annotations",zt=["readOnlyHint","untrustedContentHint","consequentialHint","debugging"],Ht=["destructiveHint","idempotentHint","openWorldHint"];function Ue(e){let t={};if(e.readOnlyHint===!0)t.readOnlyHint=!0,t.destructiveHint=!1;else if(e.readOnlyHint===!1)t.readOnlyHint=!1;if(e.consequentialHint===!0)t.destructiveHint=!0;if(e.untrustedContentHint===!0)t.openWorldHint=!0;for(let i of Ht){let d=e[i];if(d!==void 0)t[i]=d}let r={};for(let i of zt){let d=e[i];if(d!==void 0)r[i]=d}let s={};if(Object.keys(t).length>0)s.annotations=t;if(Object.keys(r).length>0)s.meta=r;return s}function Z(e){return{content:[{type:"text",text:e}],isError:!0}}function He(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function Be(e){if(typeof e==="string")return{content:[{type:"text",text:e}]};if(e===void 0)return{content:[]};if(He(e)&&Array.isArray(e.content))return e;let t;try{t=JSON.stringify(e)}catch{}if(t===void 0)return Z("The tool returned a value that is not JSON.");let r={content:[{type:"text",text:t}]};if(He(e))r.structuredContent=e;return r}function De(e){let t=e instanceof Error?e.message:String(e);return Z(t||"The tool failed.")}var se="2026-07-28",te="io.modelcontextprotocol/protocolVersion",we="io.modelcontextprotocol/clientCapabilities",Ve="io.modelcontextprotocol/clientInfo",Ge="io.modelcontextprotocol/serverInfo",_e="io.modelcontextprotocol/subscriptionId",Jt=-32020,We=-32022,Ut=0,Ke=new WeakMap;function ve(e){let t=Ke.get(e);if(t!==void 0)return t;let r=e.inputSchema,s;try{s=ee(r)}catch(d){let o=d instanceof Error?d.message:String(d);throw Error(o.split(`
5
+ `)[0])}for(let d of Object.values(s)){if(typeof d!=="object"||d.$ref===void 0)continue;let o=d.__absolute_ref__;if(s[o??d.$ref]===void 0)throw Error(`$ref ${JSON.stringify(d.$ref)} does not resolve`)}let i=(d)=>E(d,r,"2020-12",s,!1);return Ke.set(e,i),i}function Ye(e,t,r=""){let s=t instanceof Error?t.message:String(t);return TypeError(`registerTool: the inputSchema of ${e}: ${s}${r}`)}function Bt(e){let t=[];for(let r of e.list())try{ve(r)}catch(s){e.remove(r),t.push(Ye(r.name,s,"; the tool was unregistered"))}return e.setCompiler((r)=>{try{ve(r)}catch(s){throw Ye(r.name,s)}}),t}function Fe(e){try{return structuredClone(e)}catch{return e}}var Dt=new TextEncoder;function ie(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function Se(e,t){return new Response(JSON.stringify(t),{status:e,headers:{"content-type":"application/json"}})}function q(e,t,r,s,i){let d={code:r,message:s};if(i!==void 0)d.data=i;return Se(e,{jsonrpc:"2.0",id:t,error:d})}function F(e,t,r){return q(400,e,Jt,`Bad Request: the request headers and body disagree: ${r}`,{mismatch:{header:t,body:r}})}function ue(e){return Dt.encode(`event: message
6
+ data: ${JSON.stringify(e)}
7
+
8
+ `)}var Xe={"content-type":"text/event-stream","cache-control":"no-cache"};function Vt(e){return(e??"").split(";")[0]?.trim().toLowerCase()==="application/json"}function Gt(e){if(!(e.startsWith("=?base64?")&&e.endsWith("?=")))return e;let t=e.slice(9,-2);if(!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(t))return;try{let r=atob(t),s=Uint8Array.from(r,(i)=>i.charCodeAt(0));return new TextDecoder("utf-8",{fatal:!0}).decode(s)}catch{return}}function Wt(e){if(!(te in e))return{key:te,problem:"missing"};if(!(we in e))return{key:we,problem:"missing"};if(typeof e[te]!=="string")return{key:te,problem:"expected a protocol version string"};if(!ie(e[we]))return{key:we,problem:"expected an object"};let t=e[Ve];if(t!==void 0&&!(ie(t)&&typeof t.name==="string"&&typeof t.version==="string"))return{key:Ve,problem:"expected {name, version}"};return}function Kt(e){let t=e.notifications;return ie(t)&&t.toolsListChanged===!0?{toolsListChanged:!0}:{}}function Ze(e){let{tools:t,server:r}=e,s={name:r.name,version:r.version};if(r.title!==void 0)s.title=r.title;let i=xe(r.icons??[]),d=i.length>0?{...s,icons:i}:s,o=new Set,u=!1,x=(l={})=>({...l,[Ge]:s});function O(l,g,R=x()){return{jsonrpc:"2.0",id:l,result:{...g,resultType:"complete",_meta:R}}}function v(l,g){let R;try{R=ve(l)(g)}catch(y){let n=y instanceof Error?y.message:String(y);return`The input schema of tool ${l.name} cannot be used: ${n}`}if(R.valid)return;let T=R.errors.filter((y)=>y.keyword!=="properties"&&y.keyword!=="$ref").map((y)=>`${y.instanceLocation} ${y.error}`).slice(0,5).join("; ");return`Input validation error: Invalid arguments for tool ${l.name}: ${T||"the arguments do not match the schema"}`}function B(){return t.list().map((l)=>{let g={name:l.name};if(l.title!==void 0)g.title=l.title;g.description=l.description,g.inputSchema=l.inputSchema;let{annotations:R,meta:T}=Ue(l.annotations);if(R!==void 0)g.annotations=R;if(T!==void 0)g._meta={[Je]:T};return g})}let D=(l)=>({kind:"invalid",message:l});async function V(l,g,R){let T=l.name;if(typeof T!=="string")return D("Invalid params: name must be a string");let y=t.get(T);if(y===void 0)return D(`Tool ${T} not found`);let n=l.arguments??{};if(!ie(n))return D("Invalid params: arguments must be an object");let h=e.client(R),p={id:++Ut,tool:y.name,arguments:Fe(n),client:{...h}};if(y.title!==void 0)p.title=y.title;let S=Date.now();e.observe?.start(p);let _="error",N=Z("Internal error");try{[_,N]=await C(y,n,g,h)}finally{e.observe?.end({id:p.id,tool:y.name,client:{...h},outcome:_,result:Fe(N),durationMs:Date.now()-S})}return{kind:"result",result:N}}async function C(l,g,R,T){let y=v(l,g);if(y!==void 0)return["error",Z(y)];if(l.annotations.consequentialHint===!0){let h={tool:{name:l.name,description:l.description},arguments:g,client:T,signal:R};if(l.title!==void 0)h.tool.title=l.title;let p=!1;try{p=await e.confirm(h)}catch{p=!1}if(!p)return[R.aborted?"cancelled":"declined",Z("The user declined")]}if(R.aborted)return["cancelled",Z("Cancelled")];if(t.get(l.name)!==l)return["error",Z("The tool is no longer available")];let n;try{n=Be(await l.execute(g,{signal:R,client:T}))}catch(h){n=De(h)}if(R.aborted)return["cancelled",n];return[n.isError===!0?"error":"ok",n]}function G(l,g,R,T){let y=new ReadableStream({start:(n)=>{let h=(p)=>{if(R.aborted)return;let S;try{S=ue(p)}catch{S=ue(O(l,Z("The tool returned a result that is not JSON.")))}try{n.enqueue(S),n.close()}catch{}};V(g,R,T).then((p)=>h(p.kind==="invalid"?{jsonrpc:"2.0",id:l,error:{code:-32602,message:p.message}}:O(l,p.result)),()=>h({jsonrpc:"2.0",id:l,error:{code:-32603,message:"Internal error"}}))}});return new Response(y,{status:200,headers:Xe})}function W(l,g,R){let T=Kt(g),y={jsonrpc:"2.0",id:l,result:{resultType:"complete",_meta:x({[_e]:l})}},n,h=new ReadableStream({start:(p)=>{if(p.enqueue(ue({jsonrpc:"2.0",method:"notifications/subscriptions/acknowledged",params:{notifications:T,_meta:{[_e]:l}}})),Object.keys(T).length===0){p.enqueue(ue(y)),p.close();return}let S={id:l,send:(_)=>{try{p.enqueue(ue(_))}catch{o.delete(S)}},end:()=>{o.delete(S);try{p.enqueue(ue(y)),p.close()}catch{}}};n=S,o.add(S),R.addEventListener("abort",()=>{o.delete(S);try{p.close()}catch{}})},cancel:()=>{if(n!==void 0)o.delete(n)}});return new Response(h,{status:200,headers:Xe})}function Q(l,g){if(Array.isArray(g))return q(400,null,-32600,"Bad Request: JSON-RPC batches are not supported by this endpoint");if(!ie(g)||g.jsonrpc!=="2.0")return q(400,null,-32600,"Bad Request: the request body is not a valid JSON-RPC message");let{method:R,id:T}=g;if(typeof R!=="string")return"result"in g||"error"in g?q(400,null,-32600,"Bad Request: JSON-RPC responses cannot be posted to this endpoint"):q(400,null,-32600,"Bad Request: the request body is not a valid JSON-RPC message");let y=l.headers.get("mcp-protocol-version"),n=l.headers.get("mcp-method"),h=ie(g.params)?g.params:{},p=ie(h._meta)?h._meta:void 0,S=p!==void 0&&te in p,_=typeof p?.[te]==="string"?p[te]:void 0,N=y!==null&&y>=se;if(T===void 0){if(_!==void 0&&y!==null&&y!==_)return F(null,y,`the notification envelope names protocol version ${_} but the MCP-Protocol-Version header names ${y}`);if((S||N)&&n!==null&&n!==R)return F(null,n,`the notification body names method ${R} but the Mcp-Method header names ${n}`);return"notification"}if(typeof T!=="string"&&typeof T!=="number")return q(400,null,-32600,"Bad Request: the request body is not a valid JSON-RPC message");let P=T;if(!S||R==="initialize"&&(_===void 0||_<se)){if(R==="initialize"){if(N)return F(P,y,"an initialize request (legacy handshake) was sent with a modern MCP-Protocol-Version header");let z=typeof h.protocolVersion==="string"?h.protocolVersion:void 0;return L(P,z)}if(N){let z=p===void 0?["_meta"]:[te];return q(400,P,-32602,`Invalid params: the MCP-Protocol-Version header names protocol revision ${y}, but the request is missing the required per-request envelope key(s): ${z.join(", ")}`,{envelope:{missing:z}})}return L(P,y??void 0)}let K=Wt(p);if(K!==void 0)return q(400,P,-32602,`Invalid _meta envelope for protocol revision ${se}: ${K.key}: ${K.problem}`,{envelope:K});if(y!==null&&_!==void 0&&y!==_)return F(P,y,`the body envelope names protocol version ${_} but the MCP-Protocol-Version header names ${y}`);if(n!==null&&n!==R)return F(P,n,`the body names method ${R} but the Mcp-Method header names ${n}`);if(_!==se)return L(P,_);if(y===null)return F(P,"(missing)",`the body envelope names protocol version ${_} but the required MCP-Protocol-Version header is absent`);if(n===null)return F(P,"(missing)",`the body names method ${R} but the required Mcp-Method header is absent`);if(R==="tools/call"&&typeof h.name==="string"){let z=h.name,j=l.headers.get("mcp-name");if(j===null)return F(P,"(missing)",`the body carries params.name="${z}" but the required Mcp-Name header is absent`);let H=Gt(j);if(H===void 0)return F(P,j,"the Mcp-Name header carries an invalid Base64 sentinel value");if(H!==z)return F(P,j,`the body carries params.name="${z}" but the Mcp-Name header names "${H}"`)}return{id:P,method:R,params:h}}function L(l,g){return g===void 0?q(400,l,We,"Unsupported protocol version: the request did not name a protocol version",{supported:[se]}):q(400,l,We,`Unsupported protocol version: ${g}`,{supported:[se],requested:g})}async function A(l,g){if(l.method.toUpperCase()!=="POST")return q(405,null,-32000,"Method not allowed.");if(!Vt(l.headers.get("content-type")))return q(415,null,-32000,"Unsupported Media Type: Content-Type must be application/json");let R;try{R=JSON.parse(g.body??await l.text())}catch{return q(400,null,-32700,"Parse error: the request body is not valid JSON")}let T=Q(l,R);if(T instanceof Response)return T;if(T==="notification")return new Response(null,{status:202});let{id:y,method:n,params:h}=T;switch(n){case"server/discover":{let p={supportedVersions:[se],capabilities:{tools:{listChanged:!0}}};if(r.instructions!==void 0)p.instructions=r.instructions;return p.ttlMs=0,p.cacheScope="private",Se(200,O(y,p,{[Ge]:d}))}case"tools/list":return Se(200,O(y,{tools:B(),ttlMs:0,cacheScope:"private"}));case"tools/call":return G(y,h,l.signal,g.grant);case"subscriptions/listen":return W(y,h,l.signal);default:return q(404,y,-32601,"Method not found")}}return{handle:(l,g)=>A(l,g).catch(()=>q(500,null,-32603,"Internal server error")),toolsChanged(){if(u)return;u=!0,queueMicrotask(()=>{u=!1;for(let l of[...o])l.send({jsonrpc:"2.0",method:"notifications/tools/list_changed",params:{_meta:{[_e]:l.id}}})})},close(){for(let l of[...o])l.end()}}}var ke="tab-mcp.v1";function le(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}var M=(e)=>typeof e==="string";function Qe(e){if(!le(e)||!M(e.grantId)||!M(e.createdAt))return!1;let t=e.client;return le(t)&&M(t.id)&&M(t.name)&&M(t.host)}function Yt(e){if(!le(e))return!1;return["maxMessageBytes","maxBodyBytes","requestTimeoutMs","idleTimeoutMs","heartbeatMs","keepAliveMs","maxConcurrentRequests"].every((t)=>typeof e[t]==="number")}function Ft(e){return le(e)&&Object.values(e).every(M)}function Le(e){let t;try{t=JSON.parse(e)}catch{return}if(!le(t))return;switch(t.type){case"session":return M(t.sessionId)&&M(t.address)&&M(t.origin)&&M(t.expiresAt)&&Yt(t.limits)&&Array.isArray(t.grants)&&t.grants.every(Qe)&&(t.appName===void 0||M(t.appName))&&(t.pairing===void 0||M(t.pairing))?t:void 0;case"ping":return typeof t.t==="number"?t:void 0;case"bye":return{type:"bye",reason:M(t.reason)?t.reason:""};case"http.request":return M(t.id)&&M(t.method)&&M(t.path)&&Ft(t.headers)&&M(t.body)&&le(t.grant)&&M(t.grant.grantId)&&M(t.grant.clientId)?t:void 0;case"http.cancel":return M(t.id)?t:void 0;case"pairing.code":return M(t.code)&&M(t.expiresAt)?t:void 0;case"grant.added":return Qe(t.grant)?t:void 0;case"grant.removed":return M(t.grantId)?{type:"grant.removed",grantId:t.grantId,reason:M(t.reason)?t.reason:""}:void 0;case"identity.bound":return typeof t.round==="number"?{type:"identity.bound",round:t.round}:{type:"identity.bound"};case"error":return M(t.code)?t:void 0;default:return}}function Xt(e){let t="",r=0,s=0;for(let i of e){r=r<<8|i,s+=8;while(s>=5)s-=5,t+="abcdefghijklmnopqrstuvwxyz234567"[r>>>s&31];r&=(1<<s)-1}if(s>0)t+="abcdefghijklmnopqrstuvwxyz234567"[r<<5-s&31];return t}async function Zt(e,t=globalThis.crypto?.subtle??null){if(t===null)return;try{let r=await t.digest("SHA-256",new TextEncoder().encode(e));return Xt(new Uint8Array(r))}catch{return}}function Qt(e,t){if(t===void 0)return e;let r=new URL(e);return r.searchParams.set("a",t),r.href}var Lt=15000,et={1000:"closed",1008:"policy",1009:"too_large",4001:"expired",4002:"idle",4003:"heartbeat",4004:"shutdown",4005:"replaced",4008:"rate_limited",4009:"policy"},tt={replaced:"replaced",expired:"expired",idle:"idle",shutdown:"shutdown"};function de(e,t){return Object.assign(Error(e),{reason:t})}var er=["content-type","cache-control"];function tr(){let e=globalThis.document?.title;return typeof e==="string"?e.slice(0,300):""}function rr(e){try{let t=JSON.parse(e);if(typeof t!=="object"||t===null||typeof t.type!=="string")return;return typeof t.id==="string"?{type:t.type,id:t.id}:{type:t.type}}catch{return}}var nr=new Set(["session","ping","bye","http.request","http.cancel","pairing.code","grant.added","grant.removed","identity.bound","error"]),nt=512,ot=6,st=64,or=nt+ot*st;function sr(e){let t=Math.floor((e-nt)/ot);return t>=st?t:void 0}function*rt(e,t){let r=0;while(r<e.length){let s=Math.min(r+t,e.length),i=e.charCodeAt(s-1);if(s<e.length&&i>=55296&&i<=56319)s+=s-1>r?-1:1;yield e.slice(r,s),r=s}}var ir=1e4,dr=1000;function ar(e){let t,r=Number.NEGATIVE_INFINITY,s;try{if(e!==void 0&&typeof BroadcastChannel==="function")t=new BroadcastChannel(e),t.onmessage=(i)=>{if(i.data?.type!=="claimed")return;r=Date.now(),s?.()}}catch{t=void 0}return{claimed(){try{t?.postMessage({type:"claimed"})}catch{}},heard(){if(Date.now()-r<=ir)return Promise.resolve(!0);if(t===void 0)return Promise.resolve(!1);return new Promise((i)=>{let d=setTimeout(()=>i(!1),dr);s=()=>{clearTimeout(d),i(!0)}})},close(){t?.close()}}}function Ar(e,t,r,s=!1){let i=new WebSocket(t,ke),d=new Map,o="opening",u,x=65536,O,v=0,B=ar(e.tabs),D,V,C,G=new Promise((n,h)=>{V=n,C=h});G.catch(()=>{});let W=setTimeout(()=>{g(de("The relay did not answer in time.","network"))},Lt),Q=Ze({tools:e.registry,server:{...e.server,icons:e.server.icons??Ne()},confirm:(n)=>e.confirm(n),client:(n)=>e.clientFor(n),observe:{start:(n)=>e.toolCallStarted(n),end:(n)=>e.toolCallEnded(n)}}),L=e.registry.onChange(()=>Q.toolsChanged());function A(n){if(i.readyState!==WebSocket.OPEN)return!1;try{return i.send(JSON.stringify(n)),!0}catch{return!1}}function l(){if(v<=0)return;clearTimeout(O),O=setTimeout(()=>{u??="heartbeat",R(4003);try{i.close()}catch{}},v*2.5)}function g(n){if(o!=="opening")return;R(0),C(n);try{i.close()}catch{}}function R(n){if(o==="closed")return;let h=o==="ready";o="closed",clearTimeout(W),clearTimeout(O),L();for(let p of d.values())p.abort();if(d.clear(),Q.close(),h){let p=u??et[n]??(n===1006?"network":"closed");if(C(de("The address was taken over again before its AI apps were disconnected.",p)),e.closed(p,n),p==="replaced"){B.heard().then((S)=>{B.close(),e.replaced({sibling:S})});return}}B.close()}async function T(n){let h=new AbortController;d.set(n.id,h);let p=()=>o==="ready"&&d.get(n.id)===h&&!h.signal.aborted;try{let S=new Request(`https://tab.invalid${n.path}`,{method:n.method,headers:n.headers,signal:h.signal}),_=await Q.handle(S,{grant:n.grant,body:n.body});if(!p()){await _.body?.cancel().catch(()=>{});return}let N={};for(let j of er){let H=_.headers.get(j);if(H!==null)N[j]=H}if(!(N["content-type"]??"").startsWith("text/event-stream")||_.body===null){let j=await _.text();if(!p())return;if(j.length<=x){A({type:"http.response",id:n.id,status:_.status,headers:N,body:j});return}A({type:"http.response.start",id:n.id,status:_.status,headers:N});for(let H of rt(j,x)){if(!p())break;A({type:"http.response.chunk",id:n.id,data:H})}if(p())A({type:"http.response.end",id:n.id});return}A({type:"http.response.start",id:n.id,status:_.status,headers:N});let K=_.body.getReader(),z=new TextDecoder;h.signal.addEventListener("abort",()=>{K.cancel().catch(()=>{})});for(;;){let{done:j,value:H}=await K.read();if(j||!p())break;let fe=z.decode(H,{stream:!0});for(let re of rt(fe,x))A({type:"http.response.chunk",id:n.id,data:re})}if(p())A({type:"http.response.end",id:n.id})}catch(S){if(p())e.error(S instanceof Error?S:Error(String(S))),A({type:"http.response",id:n.id,status:500,headers:{"content-type":"application/json"},body:JSON.stringify({jsonrpc:"2.0",id:null,error:{code:-32603,message:"Internal server error"}})})}finally{if(d.get(n.id)===h)d.delete(n.id)}}function y(n){if(o==="opening"){if(n.type==="session"){let h=sr(n.limits.maxMessageBytes);if(h===void 0){g(de(`The relay's message limit (${n.limits.maxMessageBytes} bytes) is too small; tab-mcp needs at least ${or}.`,"policy"));return}x=h,o="ready",clearTimeout(W),v=n.limits.heartbeatMs,l(),B.claimed();let p=e.sessionStarted(n);if(s&&n.grants.length>0){D={left:new Set(n.grants.map((S)=>S.grantId)),session:p},A({type:"grants.revokeAll"});return}V(p)}else if(n.type==="error")g(de(`The relay refused the connection: ${n.message||n.code}`,n.code==="rate_limited"?"rate_limited":"policy"));else if(n.type==="bye")g(de(`The relay ended the connection: ${n.reason}`,tt[n.reason]??"closed"));return}if(o!=="ready")return;switch(n.type){case"ping":l(),A({type:"pong",t:n.t});return;case"http.request":T(n);return;case"http.cancel":d.get(n.id)?.abort(),d.delete(n.id);return;case"pairing.code":e.pairingCode({code:n.code,expiresAt:n.expiresAt});return;case"grant.added":e.grantAdded(n.grant);return;case"grant.removed":if(e.grantRemoved(n.grantId),D?.left.delete(n.grantId),D?.left.size===0)V(D.session);return;case"identity.bound":e.identityResult(!0,n.round);return;case"bye":if(u=tt[n.reason]??"closed",u==="replaced")R(4005);return;case"error":if(n.code==="identity_refused"){e.identityResult(!1,typeof n.round==="number"?n.round:void 0,n.message);return}e.error(Error(`Relay error ${n.code}: ${n.message}`));return;case"session":return}}return i.addEventListener("open",()=>{if(i.protocol!==""&&i.protocol!==ke){g(de(`The relay speaks ${i.protocol}, not ${ke}.`,"policy"));return}let n={type:"hello",library:e.library,page:{title:tr()},secret:r};if(e.appName!==void 0)n.app={name:e.appName};if(s)n.revokeAll=!0;A(n)}),i.addEventListener("message",(n)=>{if(typeof n.data!=="string")return;let h=Le(n.data);if(h!==void 0){if(o==="ready")l();y(h);return}let p=rr(n.data);if(p?.id!==void 0)A(nr.has(p.type)?{type:"error",code:"bad_message",message:`malformed ${p.type}`,id:p.id}:{type:"error",code:"unknown_type",message:`unknown type ${p.type}`,id:p.id})}),i.addEventListener("close",(n)=>{if(o==="opening"){R(n.code);let h=n.code===1006||n.code===1002;C(de(h?"Could not connect to the relay (refused, unreachable, or this page's origin is not allowed).":`The relay closed the connection (${n.code}${n.reason?`: ${n.reason}`:""}).`,et[n.code]??(h?"network":"closed")));return}R(n.code)}),{ready:G,send:A,close(n){if(o==="closed")return;if(o==="opening"){g(new DOMException("The connection was cancelled","AbortError"));return}u=n,A({type:"bye",reason:"user"}),R(1000);try{i.close(1000,"bye")}catch{}}}}export{Zt as addressIdOf,Bt as compileRegistry,Ar as openConnection,Qt as withAddress};
9
+
10
+ //# debugId=0B1EE263FE9616FD64756E2164756E21
11
+ //# sourceMappingURL=connection-0x5mr3te.min.js.map