@ractive-ch/tab-mcp-client 0.22.0 → 0.23.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/skill/SKILL.md CHANGED
@@ -1,13 +1,13 @@
1
1
  ---
2
2
  name: tab-mcp
3
- description: Add tab-mcp to a web app so that AI apps (Claude, ChatGPT, Claude Code, Codex) can call the page's functions as MCP tools while it is open in a browser tab. Covers installing @ractive-ch/tab-mcp-client, registering tools WebMCP-style, the React bindings, the connect and pairing flow (by code or by sign-in), confirmation for consequential tools, registering the same tools with the browser's WebMCP (`webmcp: true`), serving them to the site's own assistant without a relay (`serve`), security defaults and running a tab-mcp relay. Use when the user wants to expose a web page's features to AI apps over MCP, mentions tab-mcp, WebMCP or registerTool, "Connect your AI app", or needs to self-host the tab-mcp relay.
3
+ description: Add tab-mcp to a web app so that AI apps (Claude, ChatGPT, Claude Code, Codex) can call the page's functions as MCP tools while it is open in a browser tab. Covers installing @ractive-ch/tab-mcp-client, registering tools WebMCP-style, the React bindings, the connect and pairing flow (by code or by sign-in), confirmation for consequential tools, registering the same tools with the browser's WebMCP (on by default; `webmcp: false`), serving them to the site's own assistant without a relay (`serve`), security defaults and running a tab-mcp relay. Use when the user wants to expose a web page's features to AI apps over MCP, mentions tab-mcp, WebMCP or registerTool, "Connect your AI app", or needs to self-host the tab-mcp relay.
4
4
  license: MIT
5
5
  compatibility: Browser library for any web page (ES modules); the relay needs Bun 1.4.4+ or Docker.
6
6
  ---
7
7
 
8
8
  # Add tab-mcp to a web app
9
9
 
10
- This skill describes `@ractive-ch/tab-mcp-client` 0.22.0. The package's
10
+ This skill describes `@ractive-ch/tab-mcp-client` 0.23.0. The package's
11
11
  [README](../README.md)
12
12
  is the full reference; read the section you need there when this skill is not enough. Its
13
13
  [CHANGELOG](../CHANGELOG.md)
@@ -33,8 +33,8 @@ Facts to keep in mind:
33
33
  - The page needs a relay that allows its origin; run one (section 7).
34
34
  - [WebMCP](https://webmachinelearning.github.io/webmcp/) (`document.modelContext`) is the
35
35
  browser's own API for tools that agents in the browser call. tab-mcp is for AI apps
36
- outside the browser. With `webmcp: true` the library offers the page's tools both ways
37
- (section 5). A page that only registers WebMCP tools natively needs no library: the tab-mcp browser extension passes them on to an AI app through a relay.
36
+ outside the browser. Unless `webmcp: false`, the library offers the page's tools both
37
+ ways (section 5). A page that only registers WebMCP tools natively needs no library: the tab-mcp browser extension passes them on to an AI app through a relay.
38
38
  - tab-mcp fits state that lives only in the browser, and acting as the signed-in user in
39
39
  their open tab. If the state lives on the site's server, suggest an MCP server on that
40
40
  backend instead: it works without an open tab and without a relay.
@@ -49,7 +49,7 @@ Without a bundler, import the self-contained build from a CDN:
49
49
 
50
50
  ```html
51
51
  <script type="module">
52
- import { TabMcp } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.22.0/cdn/tab-mcp-client.min.js";
52
+ import { TabMcp } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.23.0/cdn/tab-mcp-client.min.js";
53
53
  </script>
54
54
  ```
55
55
 
@@ -261,7 +261,7 @@ const served = await mcp.serve(port, {
261
261
  - `served.close()` (or `options.signal`) ends it; close it when the channel is gone.
262
262
  Without `relay`, `connect()`, `showConnectDialog()` and `disconnectAll()` reject with a
263
263
  `TypeError` and React's `ConnectButton` renders nothing. `serve`, the relay and
264
- `webmcp: true` can be used together: one registration reaches all three.
264
+ the WebMCP mirror can be used together: one registration reaches all three.
265
265
 
266
266
  ## 4. Consequential tools
267
267
 
@@ -314,7 +314,7 @@ calls are declined.
314
314
  ## 5. WebMCP: agents in the browser
315
315
 
316
316
  ```ts
317
- const mcp = new TabMcp({ relay, server, webmcp: true });
317
+ const mcp = new TabMcp({ relay, server }); // the mirror is on unless webmcp: false
318
318
  await mcp.registerTool(deleteNoteTool); // an AI app is asked; an unvouched WebMCP call is not
319
319
  ```
320
320
 
@@ -330,11 +330,13 @@ Whether anyone asks before a tool that asks runs, and who, depends on the caller
330
330
  | Another extension passing on an AI app's calls | no, unless that extension lets it | that extension, if it asks; the page's `onConfirm` if any; never the library's dialog |
331
331
  | A document of an origin in the tool's `exposedTo` | no, not in the page | only the page's `onConfirm`, if any |
332
332
 
333
- - `webmcp: true` (off by default) also registers each tool with the browser's native
334
- `document.modelContext.registerTool()`, where the browser has it (in Chrome: sites in
335
- the WebMCP origin trial, or `chrome://flags/#enable-webmcp-testing`). Agents in the
336
- browser (built in, or an extension) then call the tools without pairing. It is a
337
- change in what the page exposes: turn it on only when the user wants that.
333
+ - The library also registers each tool with the browser's native
334
+ `document.modelContext.registerTool()`, where the tab has it (in Chrome: sites in
335
+ the WebMCP origin trial, or `chrome://flags/#enable-webmcp-testing`; where the
336
+ browser has none, the tab-mcp browser extension's own). On by default (since client
337
+ 0.23, DEC-222); `webmcp: false` turns it off. Agents in the
338
+ browser (built in, or an extension) call the mirrored tools without pairing: ask the
339
+ user whether that is wanted, and set `webmcp: false` when it is not.
338
340
  - Every tool goes there, tools with `consequentialHint` or `destructiveHint` included
339
341
  (since client 0.20, DEC-209): hiding them did not stop an agent that drives the tab, it
340
342
  clicked the page's own controls instead, with no question. `callers` without
@@ -350,8 +352,8 @@ Whether anyone asks before a tool that asks runs, and who, depends on the caller
350
352
  caller's word leaves `"webmcp"` out of `callers`, and gets no `exposedTo` (the library
351
353
  warns in the console about a tool that asks with `exposedTo` on a page without
352
354
  `onConfirm`).
353
- - **The tab-mcp browser extension.** With `webmcp: true` the page and the extension
354
- shake hands. A call the user has just allowed in the extension (asked in its side
355
+ - **The tab-mcp browser extension.** Unless `webmcp: false`, the page and the extension
356
+ shake hands; it sees the page's tools only through the mirror. A call the user has just allowed in the extension (asked in its side
355
357
  panel, or covered by its "Always allow" switch; the same tool, equal arguments, within
356
358
  2 seconds) runs without `onConfirm`, so `onConfirm` is not a hook that sees every
357
359
  call; its caller is `{ kind: "webmcp", via: "tab-mcp-extension", name, host }`.
@@ -373,10 +375,12 @@ Whether anyone asks before a tool that asks runs, and who, depends on the caller
373
375
  bare `UnknownError`. Two cases still reject: a call the browser cancelled
374
376
  (`AbortError`), and a call when the library's lazily loaded part cannot be loaded (a
375
377
  new deploy while the page stays open, the network); reloading the page fixes that.
376
- - Only the native object is used, never a polyfill such as `@mcp-b/global`. A failed
378
+ - Only the object behind `Document.prototype`'s getter is used (the browser's, or the
379
+ one a browser extension such as tab-mcp's put there), never a `document.modelContext`
380
+ a page script defines (a polyfill such as `@mcp-b/global`). A failed
377
381
  native registration (a name already registered natively, a frame without
378
382
  `allow="tools"`) only warns in the console; the tool stays offered through the relay.
379
- A page that registers tools natively itself leaves `webmcp` off or uses other names.
383
+ A page that registers tools natively itself sets `webmcp: false` or uses other names.
380
384
  - The tab-mcp browser extension offers mirrored tools like any page tool, so an AI app connected to
381
385
  both the page and the extension sees them twice.
382
386
 
@@ -47,13 +47,13 @@ function TodoList() {
47
47
  Keep the state in a store, or the current value in a ref beside the state, changed by
48
48
  one function that the page's own UI uses too
49
49
  ([Tools in a `useState` app](../../README.md#tools-in-a-usestate-app)).
50
- - `webmcp` on the provider registers the tools with the browser's WebMCP too, tools that
51
- ask included; the library shows an unvouched WebMCP call no question (the provider's
50
+ - The provider registers the tools with the browser's WebMCP too (unless `webmcp: false`),
51
+ tools that ask included; the library shows an unvouched WebMCP call no question (the provider's
52
52
  `onConfirm`, if given, still decides in code); `useTool(tool, { callers: ["relay",
53
53
  "local"] })` keeps one out (SKILL.md, section 5).
54
54
  - `useToolCalls({ limit })` lists the AI app's recent calls; `ConnectButton` opens the
55
55
  dialog and labels itself by state.
56
56
  - The module starts with `"use client"`: in Next.js's app router the provider renders on
57
57
  the client and never connects on the server.
58
- [examples/react-todo](https://github.com/ractive/tab-mcp/tree/client-v0.22.0/examples/react-todo)
58
+ [examples/react-todo](https://github.com/ractive/tab-mcp/tree/client-v0.23.0/examples/react-todo)
59
59
  is a complete app.
package/tab-mcp.d.ts CHANGED
@@ -48,7 +48,7 @@ type Listener<K extends keyof TabMcpEventMap> = (event: TabMcpEventMap[K]) => vo
48
48
  export declare class TabMcp extends EventTarget {
49
49
  #private;
50
50
  /**
51
- * With `webmcp: true`: the tab-mcp browser extension while it serves this
51
+ * Unless `webmcp: false`: the tab-mcp browser extension while it serves this
52
52
  * page, with the AI apps that reach the page's tools through it (DEC-207);
53
53
  * `extensionchange` says when it changes. `undefined` without it, while
54
54
  * its AI access is off, and without WebMCP. Declared only: the mirror's
package/types.d.ts CHANGED
@@ -42,7 +42,7 @@ export interface RelayClient {
42
42
  }
43
43
  /**
44
44
  * Whatever calls a mirrored tool through the browser's WebMCP
45
- * (`webmcp: true`): an agent in the browser, which may drive the tab,
45
+ * (unless `webmcp: false`): an agent in the browser, which may drive the tab,
46
46
  * another extension that passes on an AI app's calls, or a document of an
47
47
  * origin in the tool's `exposedTo`. Not paired and not identified: nothing
48
48
  * more is known, and the page cannot tell these apart, unless the tab-mcp
@@ -204,7 +204,7 @@ export interface RegisterToolOptions {
204
204
  /**
205
205
  * Which callers see the tool: `"relay"` (AI apps through the relay),
206
206
  * `"local"` (this site's own assistant over `serve`), `"webmcp"` (whatever
207
- * calls through the browser's WebMCP, with `TabMcpOptions.webmcp` on). Others neither list nor
207
+ * calls through the browser's WebMCP, unless `TabMcpOptions.webmcp` is `false`). Others neither list nor
208
208
  * call it: for them it does not exist. By default all of them, tools that
209
209
  * ask included (DEC-209). Leave a caller out for privacy or identity, e.g.
210
210
  * `["local"]` for data the site's own assistant may read but an AI app
@@ -407,7 +407,8 @@ export interface TabMcpOptions {
407
407
  /**
408
408
  * Also register the tools with the browser's own WebMCP
409
409
  * (`document.modelContext.registerTool()`), where it has it, so that agents
410
- * in the browser can call them, without pairing. Off by default. Every
410
+ * in the browser can call them, without pairing. On by default; `false`
411
+ * keeps every tool out of WebMCP and the page out of the handshake. Every
411
412
  * tool goes there unless its `callers` leave `"webmcp"` out, tools that ask
412
413
  * included, marked `consequentialHint` (a tool marked only
413
414
  * `destructiveHint` too: WebMCP has no `destructiveHint`; DEC-209), so
@@ -423,7 +424,7 @@ export interface TabMcpOptions {
423
424
  */
424
425
  webmcp?: boolean;
425
426
  /**
426
- * With `webmcp: true`: a WebMCP call the tab-mcp browser extension vouches
427
+ * Unless `webmcp: false`: a WebMCP call the tab-mcp browser extension vouches
427
428
  * for runs without `onConfirm` (the user allowed exactly that call there,
428
429
  * a moment before). On by default; `false` treats it as any other WebMCP
429
430
  * call: `onConfirm` decides, without one it runs (DEC-215). `extension`
@@ -41,10 +41,7 @@ class Handshake {
41
41
  type,
42
42
  library: page.version,
43
43
  app: page.app,
44
- apps: page.mcp.grants.slice(0, MAX_APPS).map((g) => ({
45
- name: g.client.name,
46
- host: g.client.host
47
- }))
44
+ apps: this.#pages.filter((p) => p.app === page.app).flatMap((p) => p.mcp.grants).slice(0, MAX_APPS).map((g) => ({ name: g.client.name, host: g.client.host }))
48
45
  })
49
46
  }));
50
47
  }
@@ -237,5 +234,5 @@ export {
237
234
  mirror
238
235
  };
239
236
 
240
- //# debugId=9DAD2DB75032006364756E2164756E21
241
- //# sourceMappingURL=webmcp-7yspbk3q.js.map
237
+ //# debugId=0783E0FC892E363C64756E2164756E21
238
+ //# sourceMappingURL=webmcp-wwma7nps.js.map
@@ -0,0 +1,11 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/handshake.ts", "../src/webmcp.ts"],
4
+ "sourcesContent": [
5
+ "/**\n * The page's side of the handshake with the tab-mcp browser extension\n * (DEC-207), in the WebMCP mirror's chunk: only a page that mirrors its\n * tools into WebMCP (unless `webmcp: false`) takes part.\n *\n * Plain DOM events on `document`, each with a JSON string as `detail`\n * (objects do not cross between a content script's world and the page's in\n * every browser): `tab-mcp-page` from the page, `tab-mcp-extension` from\n * the extension. Every message has `v: 1` and a `type`; a message of\n * another version, an unknown type or a malformed one is ignored, and so\n * are unknown fields.\n *\n * - The page announces itself (`hello`: the library's version, the app id,\n * the AI apps connected to it directly) when it starts, again (`update`)\n * when those apps change, and answers the extension's `hello` with an\n * `update`. It marks `<html data-tab-mcp-handshake>`, so that an\n * extension that starts later (its content script comes at\n * `document_idle`, or with a click) knows it may speak without having\n * heard the `hello`.\n * - The extension says what it is and which AI apps are connected to it\n * (`hello`, `update`), and, right before it runs a page tool the user\n * allowed there, `vouch`: the tool, the exact arguments, a nonce and the\n * AI app; once that call ended or failed, `withdraw` with the nonce, and\n * a vouch still unused is dropped. It speaks only while it serves the\n * page (DEC-221): while its AI access is off the page hears nothing, as\n * without the extension, except `on: false` once if it was told \"on\".\n * - Each side cuts the other's list of AI apps to 64 and sends no more.\n *\n * No proof of who sent what: anything that could fake the extension runs in\n * the page already, where it could skip any check. A convenience between\n * two parts the user trusts, not a security boundary.\n */\n\nimport type { RegisteredTool, ToolRegistry } from \"./registry.ts\";\nimport type { BrowserExtension, Grant } from \"./types.ts\";\n\n/** From the page to the extension. */\nexport const PAGE_EVENT = \"tab-mcp-page\";\n/** From the extension to the page. */\nexport const EXTENSION_EVENT = \"tab-mcp-extension\";\n/** On `<html>`: this page takes part (for an extension that starts later). */\nexport const MARK = \"data-tab-mcp-handshake\";\n/** A vouch is kept this long (milliseconds), then dropped unused. */\nexport const VOUCH_MS = 2_000;\n/** At most this many vouches wait; beyond, the oldest goes. */\nconst MAX_VOUCHES = 16;\n/** Texts from the extension are taken up to these lengths, apps up to this count either way. */\nconst MAX_TEXT = 256;\nconst MAX_APPS = 64;\n\n/** One `TabMcp` of the page, as the handshake sees it. */\nexport interface HandshakePage {\n\t/** The library's version. */\n\treadonly version: string;\n\treadonly app: string;\n\treadonly registry: ToolRegistry;\n\t/** Vouches are taken for its tools (`trustExtension`). */\n\treadonly trust: boolean;\n\t/** The `TabMcp`: its `grants` and `grantschange`. */\n\treadonly mcp: EventTarget & { readonly grants: readonly Grant[] };\n\t/** The extension's state changed. */\n\tset(extension: BrowserExtension | undefined): void;\n}\n\n/** The AI app a vouched call came from. */\nexport interface VouchedBy {\n\tname: string;\n\thost: string;\n}\n\ninterface Vouch {\n\ttool: RegisteredTool;\n\t/** The arguments, canonical (`canonical`). */\n\targs: string;\n\tnonce: string;\n\tapp: VouchedBy;\n\tat: number;\n}\n\nconst isObject = (value: unknown): value is Record<string, unknown> =>\n\ttypeof value === \"object\" && value !== null && !Array.isArray(value);\n\nconst text = (value: unknown): value is string =>\n\ttypeof value === \"string\" && value.length <= MAX_TEXT;\n\n/** An AI app as the extension names it; `undefined` if it is malformed. */\nfunction appOf(value: unknown): VouchedBy | undefined {\n\treturn isObject(value) && text(value[\"name\"]) && text(value[\"host\"])\n\t\t? { name: value[\"name\"], host: value[\"host\"] }\n\t\t: undefined;\n}\n\n/**\n * `value` as JSON with the keys of every object sorted: two argument\n * objects are equal when their canonical forms are.\n */\nexport function canonical(value: unknown): string {\n\treturn (\n\t\tJSON.stringify(value, (_key, v: unknown) =>\n\t\t\tisObject(v)\n\t\t\t\t? Object.fromEntries(\n\t\t\t\t\t\tObject.entries(v).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)),\n\t\t\t\t\t)\n\t\t\t\t: v,\n\t\t) ?? \"\"\n\t);\n}\n\n/** Monotonic milliseconds: a vouch's age must not follow the wall clock. */\nconst now = () => performance.now();\n\nclass Handshake {\n\treadonly #doc: Document;\n\treadonly #pages: HandshakePage[] = [];\n\t#extension: BrowserExtension | undefined;\n\t#vouches: Vouch[] = [];\n\n\tconstructor(doc: Document) {\n\t\tthis.#doc = doc;\n\t\tdoc.addEventListener(EXTENSION_EVENT, (event) =>\n\t\t\tthis.#heard((event as CustomEvent).detail),\n\t\t);\n\t\tdoc.documentElement?.setAttribute(MARK, \"1\");\n\t}\n\n\tjoin(page: HandshakePage): void {\n\t\tthis.#pages.push(page);\n\t\tif (this.#extension !== undefined) page.set(this.#extension);\n\t\tpage.mcp.addEventListener(\"grantschange\", () => this.#say(page, \"update\"));\n\t\tthis.#say(page, \"hello\");\n\t}\n\n\t#say(page: HandshakePage, type: \"hello\" | \"update\"): void {\n\t\t// The document's own `CustomEvent`: a document may take only events\n\t\t// of its realm.\n\t\tconst Custom = this.#doc.defaultView?.CustomEvent ?? CustomEvent;\n\t\tthis.#doc.dispatchEvent(\n\t\t\tnew Custom(PAGE_EVENT, {\n\t\t\t\tdetail: JSON.stringify({\n\t\t\t\t\tv: 1,\n\t\t\t\t\ttype,\n\t\t\t\t\tlibrary: page.version,\n\t\t\t\t\tapp: page.app,\n\t\t\t\t\t// Of every `TabMcp` of this app: the extension keeps one list\n\t\t\t\t\t// per app, and one made and dropped (React's strict mode, a\n\t\t\t\t\t// provider whose relay changed) has none. Capped as the\n\t\t\t\t\t// extension cuts what it hears: more would not be heard anyway.\n\t\t\t\t\tapps: this.#pages\n\t\t\t\t\t\t.filter((p) => p.app === page.app)\n\t\t\t\t\t\t.flatMap((p) => p.mcp.grants)\n\t\t\t\t\t\t.slice(0, MAX_APPS)\n\t\t\t\t\t\t.map((g) => ({ name: g.client.name, host: g.client.host })),\n\t\t\t\t}),\n\t\t\t}),\n\t\t);\n\t}\n\n\t#heard(detail: unknown): void {\n\t\tlet m: unknown;\n\t\ttry {\n\t\t\tm = typeof detail === \"string\" ? JSON.parse(detail) : undefined;\n\t\t} catch {\n\t\t\treturn;\n\t\t}\n\t\tif (!isObject(m) || m[\"v\"] !== 1) return;\n\t\tif (m[\"type\"] === \"vouch\") this.#vouch(m);\n\t\t// The call it was for ended or never reached the page: an unused vouch\n\t\t// must not wait its 2 s for another caller.\n\t\telse if (m[\"type\"] === \"withdraw\")\n\t\t\tthis.#vouches = this.#vouches.filter((v) => v.nonce !== m[\"nonce\"]);\n\t\telse if (m[\"type\"] === \"hello\" || m[\"type\"] === \"update\") {\n\t\t\tconst extension = extensionOf(m);\n\t\t\tif (extension === null) return;\n\t\t\tif (canonical(extension) !== canonical(this.#extension)) {\n\t\t\t\tthis.#extension = extension;\n\t\t\t\tfor (const page of this.#pages) page.set(extension);\n\t\t\t}\n\t\t\tif (m[\"type\"] === \"hello\")\n\t\t\t\tfor (const page of this.#pages) this.#say(page, \"update\");\n\t\t}\n\t}\n\n\t/**\n\t * A vouch, kept for the tool registered under its name now, by a page\n\t * that takes vouches: a tool registered anew after this does not get it.\n\t */\n\t#vouch(m: Record<string, unknown>): void {\n\t\tconst app = appOf(m[\"app\"]);\n\t\tconst name = m[\"tool\"];\n\t\tconst nonce = m[\"nonce\"];\n\t\tif (\n\t\t\tapp === undefined ||\n\t\t\ttypeof name !== \"string\" ||\n\t\t\ttypeof nonce !== \"string\" ||\n\t\t\t!isObject(m[\"arguments\"])\n\t\t)\n\t\t\treturn;\n\t\tthis.#drop();\n\t\t// The same vouch heard twice counts once.\n\t\tif (this.#vouches.some((v) => v.nonce === nonce)) return;\n\t\tfor (const page of this.#pages) {\n\t\t\tconst tool = page.trust ? page.registry.get(name) : undefined;\n\t\t\tif (tool === undefined) continue;\n\t\t\tthis.#vouches.push({\n\t\t\t\ttool,\n\t\t\t\targs: canonical(m[\"arguments\"]),\n\t\t\t\tnonce,\n\t\t\t\tapp,\n\t\t\t\tat: now(),\n\t\t\t});\n\t\t\tif (this.#vouches.length > MAX_VOUCHES) this.#vouches.shift();\n\t\t\treturn;\n\t\t}\n\t}\n\n\t/** Forget the vouches older than `VOUCH_MS`. */\n\t#drop(): void {\n\t\tconst t = now();\n\t\tthis.#vouches = this.#vouches.filter((v) => t - v.at <= VOUCH_MS);\n\t}\n\n\t/**\n\t * The vouch for this call of `tool` with `input`, used up; `undefined`\n\t * if there is none (the call is asked as without the extension).\n\t */\n\ttake(tool: RegisteredTool, input: unknown): VouchedBy | undefined {\n\t\tthis.#drop();\n\t\tconst args = canonical(input);\n\t\tconst i = this.#vouches.findIndex(\n\t\t\t(v) => v.tool === tool && v.args === args,\n\t\t);\n\t\treturn i < 0 ? undefined : this.#vouches.splice(i, 1)[0]?.app;\n\t}\n}\n\n/**\n * The extension's state from its `hello` or `update`: `undefined` when it\n * does not serve the page now, `null` when the message is malformed.\n */\nfunction extensionOf(\n\tm: Record<string, unknown>,\n): BrowserExtension | undefined | null {\n\tif (m[\"on\"] !== true) return m[\"on\"] === false ? undefined : null;\n\tconst { name, apps } = m;\n\tif (!text(name) || !Array.isArray(apps)) return null;\n\tconst list = apps.slice(0, MAX_APPS).map(appOf);\n\tif (list.some((a) => a === undefined)) return null;\n\treturn Object.freeze({\n\t\tname,\n\t\tapps: Object.freeze(list.map((a) => Object.freeze(a as VouchedBy))),\n\t\twhileInFront: m[\"whileInFront\"] !== false,\n\t});\n}\n\nconst handshakes = new WeakMap<Document, Handshake>();\n\n/**\n * The handshake of the page's top-level document, which `page` joins; the\n * extension speaks only to the top frame. `undefined` in a frame or\n * without a document.\n */\nexport function joinHandshake(page: HandshakePage): Handshake | undefined {\n\tconst doc = globalThis.document;\n\tif (doc === undefined || globalThis.top !== globalThis.window)\n\t\treturn undefined;\n\tlet handshake = handshakes.get(doc);\n\tif (handshake === undefined) {\n\t\thandshake = new Handshake(doc);\n\t\thandshakes.set(doc, handshake);\n\t}\n\thandshake.join(page);\n\treturn handshake;\n}\n",
6
+ "/**\n * Mirroring the tools into the browser's own WebMCP (iteration 25, DEC-115,\n * DEC-119, DEC-143): unless `webmcp: false`, each tool that is offered there is\n * also registered with `document.modelContext.registerTool()`, under its own\n * `AbortController`, aborted when the tool leaves the registry. A chunk of\n * its own (DEC-171), loaded by a `TabMcp` whose constructor found native\n * WebMCP (`nativeContext` in the core); a call loads the connection chunk,\n * which checks and runs it. The handshake with the tab-mcp browser\n * extension (`handshake.ts`, DEC-207) is here too: only a page that mirrors\n * takes part.\n */\n\nimport {\n\ttype HandshakePage,\n\tjoinHandshake,\n\ttype VouchedBy,\n} from \"./handshake.ts\";\nimport type { RegisteredTool, ToolRegistry } from \"./registry.ts\";\nimport type { BrowserExtension } from \"./types.ts\";\n\n/** What the library uses of the browser's `ModelContext`. */\nexport interface ModelContext {\n\tregisterTool(\n\t\ttool: object,\n\t\toptions: { signal: AbortSignal; exposedTo: string[] | undefined },\n\t): unknown;\n}\n\n/**\n * Runs a call of a mirrored tool; `signal` is the browser's, if it gives\n * one; `by`: the AI app the tab-mcp browser extension vouched for it.\n */\nexport type WebMcpCall = (\n\ttool: RegisteredTool,\n\tinput: unknown,\n\tsignal: unknown,\n\tby: VouchedBy | undefined,\n) => Promise<unknown>;\n\n/** The WebMCP hints; the MCP-only ones are left out. */\nconst HINTS = [\n\t\"readOnlyHint\",\n\t\"untrustedContentHint\",\n\t\"consequentialHint\",\n\t\"debugging\",\n] as const;\n\n/**\n * Mirror `registry`'s tools into `context`, now and whenever the registry\n * changes: every tool, unless its `callers` leave `\"webmcp\"` out (DEC-165,\n * DEC-209). A tool that asks is marked `consequentialHint`, so that the agent\n * asks its user; MCP's `destructiveHint` counts as `consequentialHint`\n * (DEC-143). The page's `onConfirm` decides such a call, never the library's\n * dialog (DEC-215). Every failure of the native `registerTool()`\n * stays here: warned once per name, the tool still offered through the relay.\n * The page joins the handshake with the tab-mcp browser extension: `mcp`\n * is its `TabMcp`, `app` its app id, `options` its options\n * (`trustExtension`, and `onConfirm` for the warning below), `version` the\n * library's. A tool that asks, mirrored with an `exposedTo` that names\n * other origins on a page without `onConfirm`, is warned about once per\n * name (`warnUnasked`): documents of those origins can run it, and the\n * library asks no WebMCP caller (DEC-215). The extension's state is `mcp.extension`, defined\n * here on the instance (the core only declares it, for its bytes), and\n * `extensionchange` is sent here.\n */\nexport function mirror(\n\tregistry: ToolRegistry,\n\tcontext: ModelContext,\n\tcall: WebMcpCall,\n\tmcp: HandshakePage[\"mcp\"],\n\tapp: string,\n\toptions: { trustExtension?: boolean; onConfirm?: unknown },\n\tversion: string,\n): void {\n\tlet state: BrowserExtension | undefined;\n\tObject.defineProperty(mcp, \"extension\", {\n\t\tget: () => state,\n\t\tconfigurable: true,\n\t});\n\tlet handshake: ReturnType<typeof joinHandshake>;\n\ttry {\n\t\thandshake = joinHandshake({\n\t\t\tversion,\n\t\t\tapp,\n\t\t\tregistry,\n\t\t\ttrust: options.trustExtension !== false,\n\t\t\tmcp,\n\t\t\tset: (extension) => {\n\t\t\t\tstate = extension;\n\t\t\t\tmcp.dispatchEvent(\n\t\t\t\t\tnew CustomEvent(\"extensionchange\", { detail: { extension } }),\n\t\t\t\t);\n\t\t\t},\n\t\t});\n\t} catch (error) {\n\t\t// The tools are mirrored all the same; no call is vouched for.\n\t\tconsole.warn(\"tab-mcp: no handshake with the browser extension:\", error);\n\t}\n\tconst mirrors = new Map<RegisteredTool, AbortController>();\n\tconst warned = new Set<string>();\n\tconst unasked = new Set<string>();\n\t/**\n\t * The warning about a tool that asks with `exposedTo` (DEC-215), once its\n\t * native registration succeeded (so Chrome accepted every origin), once\n\t * per name. Decided then: a handler the page removes later is not\n\t * caught. Never throws, whatever `exposedTo` holds.\n\t */\n\tconst warnUnasked = (tool: RegisteredTool, asks: boolean | undefined) => {\n\t\ttry {\n\t\t\t// React's provider always passes a handler; `own` says whether the\n\t\t\t// page gave one.\n\t\t\tconst ask = options.onConfirm as { own?: boolean } | undefined;\n\t\t\tconst page = globalThis.document?.location?.origin;\n\t\t\tconst others = (\n\t\t\t\tArray.isArray(tool.exposedTo) ? tool.exposedTo : []\n\t\t\t).filter((entry: unknown) => {\n\t\t\t\ttry {\n\t\t\t\t\treturn new URL(String(entry)).origin !== page;\n\t\t\t\t} catch {\n\t\t\t\t\treturn false; // the browser refuses it anyway\n\t\t\t\t}\n\t\t\t});\n\t\t\tif (\n\t\t\t\tasks !== true ||\n\t\t\t\tothers.length === 0 ||\n\t\t\t\t(ask && ask.own !== false) ||\n\t\t\t\tunasked.has(tool.name)\n\t\t\t)\n\t\t\t\treturn;\n\t\t\tunasked.add(tool.name);\n\t\t\tconsole.warn(\n\t\t\t\t`tab-mcp: ${tool.name} asks before it runs, but documents of ${others.join(\", \")} (its exposedTo) can call it through WebMCP without a question: the library asks no WebMCP caller. Refuse such calls in onConfirm, or leave exposedTo off.`,\n\t\t\t);\n\t\t} catch {\n\t\t\t// a warning never stops the mirror\n\t\t}\n\t};\n\tconst sync = (): void => {\n\t\tfor (const [tool, controller] of mirrors) {\n\t\t\tif (registry.get(tool.name) === tool) continue;\n\t\t\tcontroller.abort();\n\t\t\tmirrors.delete(tool);\n\t\t}\n\t\tfor (const tool of registry.list()) {\n\t\t\tconst { annotations, callers } = tool;\n\t\t\tconst consequential =\n\t\t\t\tannotations.consequentialHint ?? annotations.destructiveHint;\n\t\t\t// The one place of the rule for WebMCP (the relay and a port: `toolsFor`).\n\t\t\tif (mirrors.has(tool) || !(callers?.includes(\"webmcp\") ?? true)) continue;\n\t\t\tconst controller = new AbortController();\n\t\t\tmirrors.set(tool, controller);\n\t\t\tconst hints: Record<string, boolean | undefined> = {\n\t\t\t\tconsequentialHint: consequential,\n\t\t\t};\n\t\t\tfor (const key of HINTS) hints[key] ??= annotations[key];\n\t\t\tconst { signal } = controller;\n\t\t\tPromise.resolve()\n\t\t\t\t// Not once unmirrored: whatever the browser does with an aborted\n\t\t\t\t// signal.\n\t\t\t\t.then(\n\t\t\t\t\t() =>\n\t\t\t\t\t\tsignal.aborted ||\n\t\t\t\t\t\tcontext.registerTool(\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: tool.name,\n\t\t\t\t\t\t\t\t// WebIDL dictionaries: `undefined` is the same as left out.\n\t\t\t\t\t\t\t\ttitle: tool.title,\n\t\t\t\t\t\t\t\tdescription: tool.description,\n\t\t\t\t\t\t\t\tinputSchema: tool.inputSchema,\n\t\t\t\t\t\t\t\toutputSchema: tool.outputSchema,\n\t\t\t\t\t\t\t\tannotations: hints,\n\t\t\t\t\t\t\t\t// The vouch is looked up as the call arrives: it was\n\t\t\t\t\t\t\t\t// sent right before the extension made the call.\n\t\t\t\t\t\t\t\texecute: (input: unknown, options?: { signal?: unknown }) =>\n\t\t\t\t\t\t\t\t\tcall(\n\t\t\t\t\t\t\t\t\t\ttool,\n\t\t\t\t\t\t\t\t\t\tinput,\n\t\t\t\t\t\t\t\t\t\toptions?.signal,\n\t\t\t\t\t\t\t\t\t\thandshake?.take(tool, input),\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{ signal, exposedTo: tool.exposedTo },\n\t\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t\t.then(() => {\n\t\t\t\t\tif (!signal.aborted) warnUnasked(tool, consequential);\n\t\t\t\t})\n\t\t\t\t.catch((error: unknown) => {\n\t\t\t\t\tif (signal.aborted) return; // unmirrored meanwhile\n\t\t\t\t\tif (warned.has(tool.name)) return;\n\t\t\t\t\twarned.add(tool.name);\n\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t`tab-mcp: ${tool.name} is not offered through WebMCP:`,\n\t\t\t\t\t\terror,\n\t\t\t\t\t);\n\t\t\t\t});\n\t\t}\n\t};\n\tregistry.onChange(sync);\n\tsync();\n}\n"
7
+ ],
8
+ "mappings": ";AAqCO,IAAM,aAAa;AAEnB,IAAM,kBAAkB;AAExB,IAAM,OAAO;AAEb,IAAM,WAAW;AAExB,IAAM,cAAc;AAEpB,IAAM,WAAW;AACjB,IAAM,WAAW;AA+BjB,IAAM,WAAW,CAAC,UACjB,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAEpE,IAAM,OAAO,CAAC,UACb,OAAO,UAAU,YAAY,MAAM,UAAU;AAG9C,SAAS,KAAK,CAAC,OAAuC;AAAA,EACrD,OAAO,SAAS,KAAK,KAAK,KAAK,MAAM,OAAO,KAAK,KAAK,MAAM,OAAO,IAChE,EAAE,MAAM,MAAM,SAAS,MAAM,MAAM,QAAQ,IAC3C;AAAA;AAOG,SAAS,SAAS,CAAC,OAAwB;AAAA,EACjD,OACC,KAAK,UAAU,OAAO,CAAC,MAAM,MAC5B,SAAS,CAAC,IACP,OAAO,YACP,OAAO,QAAQ,CAAC,EAAE,KAAK,EAAE,KAAK,OAAQ,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,CAAE,CAClE,IACC,CACJ,KAAK;AAAA;AAKP,IAAM,MAAM,MAAM,YAAY,IAAI;AAAA;AAElC,MAAM,UAAU;A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X,IAAI,CAAC,OAAO;AAAA,UAAS,YAAY,MAAM,aAAa;AAAA,OACpD,EACA,MAAM,CAAC,UAAmB;AAAA,QAC1B,IAAI,OAAO;AAAA,UAAS;AAAA,QACpB,IAAI,OAAO,IAAI,KAAK,IAAI;AAAA,UAAG;AAAA,QAC3B,OAAO,IAAI,KAAK,IAAI;AAAA,QACpB,QAAQ,KACP,YAAY,KAAK,uCACjB,KACD;AAAA,OACA;AAAA,IACH;AAAA;AAAA,EAED,SAAS,SAAS,IAAI;AAAA,EACtB,KAAK;AAAA;",
9
+ "debugId": "0783E0FC892E363C64756E2164756E21",
10
+ "names": []
11
+ }
package/webmcp.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Mirroring the tools into the browser's own WebMCP (iteration 25, DEC-115,
3
- * DEC-119, DEC-143): with `webmcp: true`, each tool that is offered there is
3
+ * DEC-119, DEC-143): unless `webmcp: false`, each tool that is offered there is
4
4
  * also registered with `document.modelContext.registerTool()`, under its own
5
5
  * `AbortController`, aborted when the tool leaves the registry. A chunk of
6
6
  * its own (DEC-171), loaded by a `TabMcp` whose constructor found native
@@ -1,4 +0,0 @@
1
- var m=(e)=>typeof e==="object"&&e!==null&&!Array.isArray(e),y=(e)=>typeof e==="string"&&e.length<=256;function C(e){return m(e)&&y(e.name)&&y(e.host)?{name:e.name,host:e.host}:void 0}function g(e){return JSON.stringify(e,(n,o)=>m(o)?Object.fromEntries(Object.entries(o).sort(([s],[r])=>s<r?-1:s>r?1:0)):o)??""}var T=()=>performance.now();class H{#o;#n=[];#t;#e=[];constructor(e){this.#o=e,e.addEventListener("tab-mcp-extension",(n)=>this.#i(n.detail)),e.documentElement?.setAttribute("data-tab-mcp-handshake","1")}join(e){if(this.#n.push(e),this.#t!==void 0)e.set(this.#t);e.mcp.addEventListener("grantschange",()=>this.#s(e,"update")),this.#s(e,"hello")}#s(e,n){let o=this.#o.defaultView?.CustomEvent??CustomEvent;this.#o.dispatchEvent(new o("tab-mcp-page",{detail:JSON.stringify({v:1,type:n,library:e.version,app:e.app,apps:e.mcp.grants.slice(0,64).map((s)=>({name:s.client.name,host:s.client.host}))})}))}#i(e){let n;try{n=typeof e==="string"?JSON.parse(e):void 0}catch{return}if(!m(n)||n.v!==1)return;if(n.type==="vouch")this.#a(n);else if(n.type==="withdraw")this.#e=this.#e.filter((o)=>o.nonce!==n.nonce);else if(n.type==="hello"||n.type==="update"){let o=v(n);if(o===null)return;if(g(o)!==g(this.#t)){this.#t=o;for(let s of this.#n)s.set(o)}if(n.type==="hello")for(let s of this.#n)this.#s(s,"update")}}#a(e){let n=C(e.app),{tool:o,nonce:s}=e;if(n===void 0||typeof o!=="string"||typeof s!=="string"||!m(e.arguments))return;if(this.#r(),this.#e.some((r)=>r.nonce===s))return;for(let r of this.#n){let c=r.trust?r.registry.get(o):void 0;if(c===void 0)continue;if(this.#e.push({tool:c,args:g(e.arguments),nonce:s,app:n,at:T()}),this.#e.length>16)this.#e.shift();return}}#r(){let e=T();this.#e=this.#e.filter((n)=>e-n.at<=2000)}take(e,n){this.#r();let o=g(n),s=this.#e.findIndex((r)=>r.tool===e&&r.args===o);return s<0?void 0:this.#e.splice(s,1)[0]?.app}}function v(e){if(e.on!==!0)return e.on===!1?void 0:null;let{name:n,apps:o}=e;if(!y(n)||!Array.isArray(o))return null;let s=o.slice(0,64).map(C);if(s.some((r)=>r===void 0))return null;return Object.freeze({name:n,apps:Object.freeze(s.map((r)=>Object.freeze(r))),whileInFront:e.whileInFront!==!1})}var A=new WeakMap;function P(e){let n=globalThis.document;if(n===void 0||globalThis.top!==globalThis.window)return;let o=A.get(n);if(o===void 0)o=new H(n),A.set(n,o);return o.join(e),o}var O=["readOnlyHint","untrustedContentHint","consequentialHint","debugging"];function _(e,n,o,s,r,c,S){let w;Object.defineProperty(s,"extension",{get:()=>w,configurable:!0});let k;try{k=P({version:S,app:r,registry:e,trust:c.trustExtension!==!1,mcp:s,set:(t)=>{w=t,s.dispatchEvent(new CustomEvent("extensionchange",{detail:{extension:t}}))}})}catch(t){console.warn("tab-mcp: no handshake with the browser extension:",t)}let u=new Map,b=new Set,x=new Set,M=(t,i)=>{try{let l=c.onConfirm,h=globalThis.document?.location?.origin,d=(Array.isArray(t.exposedTo)?t.exposedTo:[]).filter((f)=>{try{return new URL(String(f)).origin!==h}catch{return!1}});if(i!==!0||d.length===0||l&&l.own!==!1||x.has(t.name))return;x.add(t.name),console.warn(`tab-mcp: ${t.name} asks before it runs, but documents of ${d.join(", ")} (its exposedTo) can call it through WebMCP without a question: the library asks no WebMCP caller. Refuse such calls in onConfirm, or leave exposedTo off.`)}catch{}},E=()=>{for(let[t,i]of u){if(e.get(t.name)===t)continue;i.abort(),u.delete(t)}for(let t of e.list()){let{annotations:i,callers:l}=t,h=i.consequentialHint??i.destructiveHint;if(u.has(t)||!(l?.includes("webmcp")??!0))continue;let d=new AbortController;u.set(t,d);let f={consequentialHint:h};for(let a of O)f[a]??=i[a];let{signal:p}=d;Promise.resolve().then(()=>p.aborted||n.registerTool({name:t.name,title:t.title,description:t.description,inputSchema:t.inputSchema,outputSchema:t.outputSchema,annotations:f,execute:(a,R)=>o(t,a,R?.signal,k?.take(t,a))},{signal:p,exposedTo:t.exposedTo})).then(()=>{if(!p.aborted)M(t,h)}).catch((a)=>{if(p.aborted)return;if(b.has(t.name))return;b.add(t.name),console.warn(`tab-mcp: ${t.name} is not offered through WebMCP:`,a)})}};e.onChange(E),E()}export{_ as mirror};
2
-
3
- //# debugId=3CC1FE038CA43E8F64756E2164756E21
4
- //# sourceMappingURL=webmcp-vqs5smxj.min.js.map
@@ -1,11 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/handshake.ts", "../../src/webmcp.ts"],
4
- "sourcesContent": [
5
- "/**\n * The page's side of the handshake with the tab-mcp browser extension\n * (DEC-207), in the WebMCP mirror's chunk: only a page that offers its tools\n * to agents in the browser (`webmcp: true`) takes part.\n *\n * Plain DOM events on `document`, each with a JSON string as `detail`\n * (objects do not cross between a content script's world and the page's in\n * every browser): `tab-mcp-page` from the page, `tab-mcp-extension` from\n * the extension. Every message has `v: 1` and a `type`; a message of\n * another version, an unknown type or a malformed one is ignored, and so\n * are unknown fields.\n *\n * - The page announces itself (`hello`: the library's version, the app id,\n * the AI apps connected to it directly) when it starts, again (`update`)\n * when those apps change, and answers the extension's `hello` with an\n * `update`. It marks `<html data-tab-mcp-handshake>`, so that an\n * extension that starts later (its content script comes at\n * `document_idle`, or with a click) knows it may speak without having\n * heard the `hello`.\n * - The extension says what it is and which AI apps are connected to it\n * (`hello`, `update`), and, right before it runs a page tool the user\n * allowed there, `vouch`: the tool, the exact arguments, a nonce and the\n * AI app; once that call ended or failed, `withdraw` with the nonce, and\n * a vouch still unused is dropped. It speaks only while it serves the\n * page (DEC-221): while its AI access is off the page hears nothing, as\n * without the extension, except `on: false` once if it was told \"on\".\n * - Each side cuts the other's list of AI apps to 64 and sends no more.\n *\n * No proof of who sent what: anything that could fake the extension runs in\n * the page already, where it could skip any check. A convenience between\n * two parts the user trusts, not a security boundary.\n */\n\nimport type { RegisteredTool, ToolRegistry } from \"./registry.ts\";\nimport type { BrowserExtension, Grant } from \"./types.ts\";\n\n/** From the page to the extension. */\nexport const PAGE_EVENT = \"tab-mcp-page\";\n/** From the extension to the page. */\nexport const EXTENSION_EVENT = \"tab-mcp-extension\";\n/** On `<html>`: this page takes part (for an extension that starts later). */\nexport const MARK = \"data-tab-mcp-handshake\";\n/** A vouch is kept this long (milliseconds), then dropped unused. */\nexport const VOUCH_MS = 2_000;\n/** At most this many vouches wait; beyond, the oldest goes. */\nconst MAX_VOUCHES = 16;\n/** Texts from the extension are taken up to these lengths, apps up to this count either way. */\nconst MAX_TEXT = 256;\nconst MAX_APPS = 64;\n\n/** One `TabMcp` of the page, as the handshake sees it. */\nexport interface HandshakePage {\n\t/** The library's version. */\n\treadonly version: string;\n\treadonly app: string;\n\treadonly registry: ToolRegistry;\n\t/** Vouches are taken for its tools (`trustExtension`). */\n\treadonly trust: boolean;\n\t/** The `TabMcp`: its `grants` and `grantschange`. */\n\treadonly mcp: EventTarget & { readonly grants: readonly Grant[] };\n\t/** The extension's state changed. */\n\tset(extension: BrowserExtension | undefined): void;\n}\n\n/** The AI app a vouched call came from. */\nexport interface VouchedBy {\n\tname: string;\n\thost: string;\n}\n\ninterface Vouch {\n\ttool: RegisteredTool;\n\t/** The arguments, canonical (`canonical`). */\n\targs: string;\n\tnonce: string;\n\tapp: VouchedBy;\n\tat: number;\n}\n\nconst isObject = (value: unknown): value is Record<string, unknown> =>\n\ttypeof value === \"object\" && value !== null && !Array.isArray(value);\n\nconst text = (value: unknown): value is string =>\n\ttypeof value === \"string\" && value.length <= MAX_TEXT;\n\n/** An AI app as the extension names it; `undefined` if it is malformed. */\nfunction appOf(value: unknown): VouchedBy | undefined {\n\treturn isObject(value) && text(value[\"name\"]) && text(value[\"host\"])\n\t\t? { name: value[\"name\"], host: value[\"host\"] }\n\t\t: undefined;\n}\n\n/**\n * `value` as JSON with the keys of every object sorted: two argument\n * objects are equal when their canonical forms are.\n */\nexport function canonical(value: unknown): string {\n\treturn (\n\t\tJSON.stringify(value, (_key, v: unknown) =>\n\t\t\tisObject(v)\n\t\t\t\t? Object.fromEntries(\n\t\t\t\t\t\tObject.entries(v).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)),\n\t\t\t\t\t)\n\t\t\t\t: v,\n\t\t) ?? \"\"\n\t);\n}\n\n/** Monotonic milliseconds: a vouch's age must not follow the wall clock. */\nconst now = () => performance.now();\n\nclass Handshake {\n\treadonly #doc: Document;\n\treadonly #pages: HandshakePage[] = [];\n\t#extension: BrowserExtension | undefined;\n\t#vouches: Vouch[] = [];\n\n\tconstructor(doc: Document) {\n\t\tthis.#doc = doc;\n\t\tdoc.addEventListener(EXTENSION_EVENT, (event) =>\n\t\t\tthis.#heard((event as CustomEvent).detail),\n\t\t);\n\t\tdoc.documentElement?.setAttribute(MARK, \"1\");\n\t}\n\n\tjoin(page: HandshakePage): void {\n\t\tthis.#pages.push(page);\n\t\tif (this.#extension !== undefined) page.set(this.#extension);\n\t\tpage.mcp.addEventListener(\"grantschange\", () => this.#say(page, \"update\"));\n\t\tthis.#say(page, \"hello\");\n\t}\n\n\t#say(page: HandshakePage, type: \"hello\" | \"update\"): void {\n\t\t// The document's own `CustomEvent`: a document may take only events\n\t\t// of its realm.\n\t\tconst Custom = this.#doc.defaultView?.CustomEvent ?? CustomEvent;\n\t\tthis.#doc.dispatchEvent(\n\t\t\tnew Custom(PAGE_EVENT, {\n\t\t\t\tdetail: JSON.stringify({\n\t\t\t\t\tv: 1,\n\t\t\t\t\ttype,\n\t\t\t\t\tlibrary: page.version,\n\t\t\t\t\tapp: page.app,\n\t\t\t\t\t// Capped as the extension cuts what it hears: more would\n\t\t\t\t\t// not be heard anyway.\n\t\t\t\t\tapps: page.mcp.grants.slice(0, MAX_APPS).map((g) => ({\n\t\t\t\t\t\tname: g.client.name,\n\t\t\t\t\t\thost: g.client.host,\n\t\t\t\t\t})),\n\t\t\t\t}),\n\t\t\t}),\n\t\t);\n\t}\n\n\t#heard(detail: unknown): void {\n\t\tlet m: unknown;\n\t\ttry {\n\t\t\tm = typeof detail === \"string\" ? JSON.parse(detail) : undefined;\n\t\t} catch {\n\t\t\treturn;\n\t\t}\n\t\tif (!isObject(m) || m[\"v\"] !== 1) return;\n\t\tif (m[\"type\"] === \"vouch\") this.#vouch(m);\n\t\t// The call it was for ended or never reached the page: an unused vouch\n\t\t// must not wait its 2 s for another caller.\n\t\telse if (m[\"type\"] === \"withdraw\")\n\t\t\tthis.#vouches = this.#vouches.filter((v) => v.nonce !== m[\"nonce\"]);\n\t\telse if (m[\"type\"] === \"hello\" || m[\"type\"] === \"update\") {\n\t\t\tconst extension = extensionOf(m);\n\t\t\tif (extension === null) return;\n\t\t\tif (canonical(extension) !== canonical(this.#extension)) {\n\t\t\t\tthis.#extension = extension;\n\t\t\t\tfor (const page of this.#pages) page.set(extension);\n\t\t\t}\n\t\t\tif (m[\"type\"] === \"hello\")\n\t\t\t\tfor (const page of this.#pages) this.#say(page, \"update\");\n\t\t}\n\t}\n\n\t/**\n\t * A vouch, kept for the tool registered under its name now, by a page\n\t * that takes vouches: a tool registered anew after this does not get it.\n\t */\n\t#vouch(m: Record<string, unknown>): void {\n\t\tconst app = appOf(m[\"app\"]);\n\t\tconst name = m[\"tool\"];\n\t\tconst nonce = m[\"nonce\"];\n\t\tif (\n\t\t\tapp === undefined ||\n\t\t\ttypeof name !== \"string\" ||\n\t\t\ttypeof nonce !== \"string\" ||\n\t\t\t!isObject(m[\"arguments\"])\n\t\t)\n\t\t\treturn;\n\t\tthis.#drop();\n\t\t// The same vouch heard twice counts once.\n\t\tif (this.#vouches.some((v) => v.nonce === nonce)) return;\n\t\tfor (const page of this.#pages) {\n\t\t\tconst tool = page.trust ? page.registry.get(name) : undefined;\n\t\t\tif (tool === undefined) continue;\n\t\t\tthis.#vouches.push({\n\t\t\t\ttool,\n\t\t\t\targs: canonical(m[\"arguments\"]),\n\t\t\t\tnonce,\n\t\t\t\tapp,\n\t\t\t\tat: now(),\n\t\t\t});\n\t\t\tif (this.#vouches.length > MAX_VOUCHES) this.#vouches.shift();\n\t\t\treturn;\n\t\t}\n\t}\n\n\t/** Forget the vouches older than `VOUCH_MS`. */\n\t#drop(): void {\n\t\tconst t = now();\n\t\tthis.#vouches = this.#vouches.filter((v) => t - v.at <= VOUCH_MS);\n\t}\n\n\t/**\n\t * The vouch for this call of `tool` with `input`, used up; `undefined`\n\t * if there is none (the call is asked as without the extension).\n\t */\n\ttake(tool: RegisteredTool, input: unknown): VouchedBy | undefined {\n\t\tthis.#drop();\n\t\tconst args = canonical(input);\n\t\tconst i = this.#vouches.findIndex(\n\t\t\t(v) => v.tool === tool && v.args === args,\n\t\t);\n\t\treturn i < 0 ? undefined : this.#vouches.splice(i, 1)[0]?.app;\n\t}\n}\n\n/**\n * The extension's state from its `hello` or `update`: `undefined` when it\n * does not serve the page now, `null` when the message is malformed.\n */\nfunction extensionOf(\n\tm: Record<string, unknown>,\n): BrowserExtension | undefined | null {\n\tif (m[\"on\"] !== true) return m[\"on\"] === false ? undefined : null;\n\tconst { name, apps } = m;\n\tif (!text(name) || !Array.isArray(apps)) return null;\n\tconst list = apps.slice(0, MAX_APPS).map(appOf);\n\tif (list.some((a) => a === undefined)) return null;\n\treturn Object.freeze({\n\t\tname,\n\t\tapps: Object.freeze(list.map((a) => Object.freeze(a as VouchedBy))),\n\t\twhileInFront: m[\"whileInFront\"] !== false,\n\t});\n}\n\nconst handshakes = new WeakMap<Document, Handshake>();\n\n/**\n * The handshake of the page's top-level document, which `page` joins; the\n * extension speaks only to the top frame. `undefined` in a frame or\n * without a document.\n */\nexport function joinHandshake(page: HandshakePage): Handshake | undefined {\n\tconst doc = globalThis.document;\n\tif (doc === undefined || globalThis.top !== globalThis.window)\n\t\treturn undefined;\n\tlet handshake = handshakes.get(doc);\n\tif (handshake === undefined) {\n\t\thandshake = new Handshake(doc);\n\t\thandshakes.set(doc, handshake);\n\t}\n\thandshake.join(page);\n\treturn handshake;\n}\n",
6
- "/**\n * Mirroring the tools into the browser's own WebMCP (iteration 25, DEC-115,\n * DEC-119, DEC-143): with `webmcp: true`, each tool that is offered there is\n * also registered with `document.modelContext.registerTool()`, under its own\n * `AbortController`, aborted when the tool leaves the registry. A chunk of\n * its own (DEC-171), loaded by a `TabMcp` whose constructor found native\n * WebMCP (`nativeContext` in the core); a call loads the connection chunk,\n * which checks and runs it. The handshake with the tab-mcp browser\n * extension (`handshake.ts`, DEC-207) is here too: only a page that mirrors\n * takes part.\n */\n\nimport {\n\ttype HandshakePage,\n\tjoinHandshake,\n\ttype VouchedBy,\n} from \"./handshake.ts\";\nimport type { RegisteredTool, ToolRegistry } from \"./registry.ts\";\nimport type { BrowserExtension } from \"./types.ts\";\n\n/** What the library uses of the browser's `ModelContext`. */\nexport interface ModelContext {\n\tregisterTool(\n\t\ttool: object,\n\t\toptions: { signal: AbortSignal; exposedTo: string[] | undefined },\n\t): unknown;\n}\n\n/**\n * Runs a call of a mirrored tool; `signal` is the browser's, if it gives\n * one; `by`: the AI app the tab-mcp browser extension vouched for it.\n */\nexport type WebMcpCall = (\n\ttool: RegisteredTool,\n\tinput: unknown,\n\tsignal: unknown,\n\tby: VouchedBy | undefined,\n) => Promise<unknown>;\n\n/** The WebMCP hints; the MCP-only ones are left out. */\nconst HINTS = [\n\t\"readOnlyHint\",\n\t\"untrustedContentHint\",\n\t\"consequentialHint\",\n\t\"debugging\",\n] as const;\n\n/**\n * Mirror `registry`'s tools into `context`, now and whenever the registry\n * changes: every tool, unless its `callers` leave `\"webmcp\"` out (DEC-165,\n * DEC-209). A tool that asks is marked `consequentialHint`, so that the agent\n * asks its user; MCP's `destructiveHint` counts as `consequentialHint`\n * (DEC-143). The page's `onConfirm` decides such a call, never the library's\n * dialog (DEC-215). Every failure of the native `registerTool()`\n * stays here: warned once per name, the tool still offered through the relay.\n * The page joins the handshake with the tab-mcp browser extension: `mcp`\n * is its `TabMcp`, `app` its app id, `options` its options\n * (`trustExtension`, and `onConfirm` for the warning below), `version` the\n * library's. A tool that asks, mirrored with an `exposedTo` that names\n * other origins on a page without `onConfirm`, is warned about once per\n * name (`warnUnasked`): documents of those origins can run it, and the\n * library asks no WebMCP caller (DEC-215). The extension's state is `mcp.extension`, defined\n * here on the instance (the core only declares it, for its bytes), and\n * `extensionchange` is sent here.\n */\nexport function mirror(\n\tregistry: ToolRegistry,\n\tcontext: ModelContext,\n\tcall: WebMcpCall,\n\tmcp: HandshakePage[\"mcp\"],\n\tapp: string,\n\toptions: { trustExtension?: boolean; onConfirm?: unknown },\n\tversion: string,\n): void {\n\tlet state: BrowserExtension | undefined;\n\tObject.defineProperty(mcp, \"extension\", {\n\t\tget: () => state,\n\t\tconfigurable: true,\n\t});\n\tlet handshake: ReturnType<typeof joinHandshake>;\n\ttry {\n\t\thandshake = joinHandshake({\n\t\t\tversion,\n\t\t\tapp,\n\t\t\tregistry,\n\t\t\ttrust: options.trustExtension !== false,\n\t\t\tmcp,\n\t\t\tset: (extension) => {\n\t\t\t\tstate = extension;\n\t\t\t\tmcp.dispatchEvent(\n\t\t\t\t\tnew CustomEvent(\"extensionchange\", { detail: { extension } }),\n\t\t\t\t);\n\t\t\t},\n\t\t});\n\t} catch (error) {\n\t\t// The tools are mirrored all the same; no call is vouched for.\n\t\tconsole.warn(\"tab-mcp: no handshake with the browser extension:\", error);\n\t}\n\tconst mirrors = new Map<RegisteredTool, AbortController>();\n\tconst warned = new Set<string>();\n\tconst unasked = new Set<string>();\n\t/**\n\t * The warning about a tool that asks with `exposedTo` (DEC-215), once its\n\t * native registration succeeded (so Chrome accepted every origin), once\n\t * per name. Decided then: a handler the page removes later is not\n\t * caught. Never throws, whatever `exposedTo` holds.\n\t */\n\tconst warnUnasked = (tool: RegisteredTool, asks: boolean | undefined) => {\n\t\ttry {\n\t\t\t// React's provider always passes a handler; `own` says whether the\n\t\t\t// page gave one.\n\t\t\tconst ask = options.onConfirm as { own?: boolean } | undefined;\n\t\t\tconst page = globalThis.document?.location?.origin;\n\t\t\tconst others = (\n\t\t\t\tArray.isArray(tool.exposedTo) ? tool.exposedTo : []\n\t\t\t).filter((entry: unknown) => {\n\t\t\t\ttry {\n\t\t\t\t\treturn new URL(String(entry)).origin !== page;\n\t\t\t\t} catch {\n\t\t\t\t\treturn false; // the browser refuses it anyway\n\t\t\t\t}\n\t\t\t});\n\t\t\tif (\n\t\t\t\tasks !== true ||\n\t\t\t\tothers.length === 0 ||\n\t\t\t\t(ask && ask.own !== false) ||\n\t\t\t\tunasked.has(tool.name)\n\t\t\t)\n\t\t\t\treturn;\n\t\t\tunasked.add(tool.name);\n\t\t\tconsole.warn(\n\t\t\t\t`tab-mcp: ${tool.name} asks before it runs, but documents of ${others.join(\", \")} (its exposedTo) can call it through WebMCP without a question: the library asks no WebMCP caller. Refuse such calls in onConfirm, or leave exposedTo off.`,\n\t\t\t);\n\t\t} catch {\n\t\t\t// a warning never stops the mirror\n\t\t}\n\t};\n\tconst sync = (): void => {\n\t\tfor (const [tool, controller] of mirrors) {\n\t\t\tif (registry.get(tool.name) === tool) continue;\n\t\t\tcontroller.abort();\n\t\t\tmirrors.delete(tool);\n\t\t}\n\t\tfor (const tool of registry.list()) {\n\t\t\tconst { annotations, callers } = tool;\n\t\t\tconst consequential =\n\t\t\t\tannotations.consequentialHint ?? annotations.destructiveHint;\n\t\t\t// The one place of the rule for WebMCP (the relay and a port: `toolsFor`).\n\t\t\tif (mirrors.has(tool) || !(callers?.includes(\"webmcp\") ?? true)) continue;\n\t\t\tconst controller = new AbortController();\n\t\t\tmirrors.set(tool, controller);\n\t\t\tconst hints: Record<string, boolean | undefined> = {\n\t\t\t\tconsequentialHint: consequential,\n\t\t\t};\n\t\t\tfor (const key of HINTS) hints[key] ??= annotations[key];\n\t\t\tconst { signal } = controller;\n\t\t\tPromise.resolve()\n\t\t\t\t// Not once unmirrored: whatever the browser does with an aborted\n\t\t\t\t// signal.\n\t\t\t\t.then(\n\t\t\t\t\t() =>\n\t\t\t\t\t\tsignal.aborted ||\n\t\t\t\t\t\tcontext.registerTool(\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: tool.name,\n\t\t\t\t\t\t\t\t// WebIDL dictionaries: `undefined` is the same as left out.\n\t\t\t\t\t\t\t\ttitle: tool.title,\n\t\t\t\t\t\t\t\tdescription: tool.description,\n\t\t\t\t\t\t\t\tinputSchema: tool.inputSchema,\n\t\t\t\t\t\t\t\toutputSchema: tool.outputSchema,\n\t\t\t\t\t\t\t\tannotations: hints,\n\t\t\t\t\t\t\t\t// The vouch is looked up as the call arrives: it was\n\t\t\t\t\t\t\t\t// sent right before the extension made the call.\n\t\t\t\t\t\t\t\texecute: (input: unknown, options?: { signal?: unknown }) =>\n\t\t\t\t\t\t\t\t\tcall(\n\t\t\t\t\t\t\t\t\t\ttool,\n\t\t\t\t\t\t\t\t\t\tinput,\n\t\t\t\t\t\t\t\t\t\toptions?.signal,\n\t\t\t\t\t\t\t\t\t\thandshake?.take(tool, input),\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{ signal, exposedTo: tool.exposedTo },\n\t\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t\t.then(() => {\n\t\t\t\t\tif (!signal.aborted) warnUnasked(tool, consequential);\n\t\t\t\t})\n\t\t\t\t.catch((error: unknown) => {\n\t\t\t\t\tif (signal.aborted) return; // unmirrored meanwhile\n\t\t\t\t\tif (warned.has(tool.name)) return;\n\t\t\t\t\twarned.add(tool.name);\n\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t`tab-mcp: ${tool.name} is not offered through WebMCP:`,\n\t\t\t\t\t\terror,\n\t\t\t\t\t);\n\t\t\t\t});\n\t\t}\n\t};\n\tregistry.onChange(sync);\n\tsync();\n}\n"
7
- ],
8
- "mappings": "AA+EA,IAAM,EAAW,CAAC,IACjB,OAAO,IAAU,UAAY,IAAU,MAAQ,CAAC,MAAM,QAAQ,CAAK,EAE9D,EAAO,CAAC,IACb,OAAO,IAAU,UAAY,EAAM,QApCnB,IAuCjB,SAAS,CAAK,CAAC,EAAuC,CACrD,OAAO,EAAS,CAAK,GAAK,EAAK,EAAM,IAAO,GAAK,EAAK,EAAM,IAAO,EAChE,CAAE,KAAM,EAAM,KAAS,KAAM,EAAM,IAAQ,EAC3C,OAOG,SAAS,CAAS,CAAC,EAAwB,CACjD,OACC,KAAK,UAAU,EAAO,CAAC,EAAM,IAC5B,EAAS,CAAC,EACP,OAAO,YACP,OAAO,QAAQ,CAAC,EAAE,KAAK,EAAE,IAAK,KAAQ,EAAI,EAAI,GAAK,EAAI,EAAI,EAAI,CAAE,CAClE,EACC,CACJ,GAAK,GAKP,IAAM,EAAM,IAAM,YAAY,IAAI,EAElC,MAAM,CAAU,CACN,GACA,GAA0B,CAAC,EACpC,GACA,GAAoB,CAAC,EAErB,WAAW,CAAC,EAAe,CAC1B,KAAK,GAAO,EACZ,EAA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Q,KACP,YAAY,EAAK,sCACjB,CACD,EACA,IAGJ,EAAS,SAAS,CAAI,EACtB,EAAK",
9
- "debugId": "3CC1FE038CA43E8F64756E2164756E21",
10
- "names": []
11
- }
@@ -1,11 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/handshake.ts", "../src/webmcp.ts"],
4
- "sourcesContent": [
5
- "/**\n * The page's side of the handshake with the tab-mcp browser extension\n * (DEC-207), in the WebMCP mirror's chunk: only a page that offers its tools\n * to agents in the browser (`webmcp: true`) takes part.\n *\n * Plain DOM events on `document`, each with a JSON string as `detail`\n * (objects do not cross between a content script's world and the page's in\n * every browser): `tab-mcp-page` from the page, `tab-mcp-extension` from\n * the extension. Every message has `v: 1` and a `type`; a message of\n * another version, an unknown type or a malformed one is ignored, and so\n * are unknown fields.\n *\n * - The page announces itself (`hello`: the library's version, the app id,\n * the AI apps connected to it directly) when it starts, again (`update`)\n * when those apps change, and answers the extension's `hello` with an\n * `update`. It marks `<html data-tab-mcp-handshake>`, so that an\n * extension that starts later (its content script comes at\n * `document_idle`, or with a click) knows it may speak without having\n * heard the `hello`.\n * - The extension says what it is and which AI apps are connected to it\n * (`hello`, `update`), and, right before it runs a page tool the user\n * allowed there, `vouch`: the tool, the exact arguments, a nonce and the\n * AI app; once that call ended or failed, `withdraw` with the nonce, and\n * a vouch still unused is dropped. It speaks only while it serves the\n * page (DEC-221): while its AI access is off the page hears nothing, as\n * without the extension, except `on: false` once if it was told \"on\".\n * - Each side cuts the other's list of AI apps to 64 and sends no more.\n *\n * No proof of who sent what: anything that could fake the extension runs in\n * the page already, where it could skip any check. A convenience between\n * two parts the user trusts, not a security boundary.\n */\n\nimport type { RegisteredTool, ToolRegistry } from \"./registry.ts\";\nimport type { BrowserExtension, Grant } from \"./types.ts\";\n\n/** From the page to the extension. */\nexport const PAGE_EVENT = \"tab-mcp-page\";\n/** From the extension to the page. */\nexport const EXTENSION_EVENT = \"tab-mcp-extension\";\n/** On `<html>`: this page takes part (for an extension that starts later). */\nexport const MARK = \"data-tab-mcp-handshake\";\n/** A vouch is kept this long (milliseconds), then dropped unused. */\nexport const VOUCH_MS = 2_000;\n/** At most this many vouches wait; beyond, the oldest goes. */\nconst MAX_VOUCHES = 16;\n/** Texts from the extension are taken up to these lengths, apps up to this count either way. */\nconst MAX_TEXT = 256;\nconst MAX_APPS = 64;\n\n/** One `TabMcp` of the page, as the handshake sees it. */\nexport interface HandshakePage {\n\t/** The library's version. */\n\treadonly version: string;\n\treadonly app: string;\n\treadonly registry: ToolRegistry;\n\t/** Vouches are taken for its tools (`trustExtension`). */\n\treadonly trust: boolean;\n\t/** The `TabMcp`: its `grants` and `grantschange`. */\n\treadonly mcp: EventTarget & { readonly grants: readonly Grant[] };\n\t/** The extension's state changed. */\n\tset(extension: BrowserExtension | undefined): void;\n}\n\n/** The AI app a vouched call came from. */\nexport interface VouchedBy {\n\tname: string;\n\thost: string;\n}\n\ninterface Vouch {\n\ttool: RegisteredTool;\n\t/** The arguments, canonical (`canonical`). */\n\targs: string;\n\tnonce: string;\n\tapp: VouchedBy;\n\tat: number;\n}\n\nconst isObject = (value: unknown): value is Record<string, unknown> =>\n\ttypeof value === \"object\" && value !== null && !Array.isArray(value);\n\nconst text = (value: unknown): value is string =>\n\ttypeof value === \"string\" && value.length <= MAX_TEXT;\n\n/** An AI app as the extension names it; `undefined` if it is malformed. */\nfunction appOf(value: unknown): VouchedBy | undefined {\n\treturn isObject(value) && text(value[\"name\"]) && text(value[\"host\"])\n\t\t? { name: value[\"name\"], host: value[\"host\"] }\n\t\t: undefined;\n}\n\n/**\n * `value` as JSON with the keys of every object sorted: two argument\n * objects are equal when their canonical forms are.\n */\nexport function canonical(value: unknown): string {\n\treturn (\n\t\tJSON.stringify(value, (_key, v: unknown) =>\n\t\t\tisObject(v)\n\t\t\t\t? Object.fromEntries(\n\t\t\t\t\t\tObject.entries(v).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)),\n\t\t\t\t\t)\n\t\t\t\t: v,\n\t\t) ?? \"\"\n\t);\n}\n\n/** Monotonic milliseconds: a vouch's age must not follow the wall clock. */\nconst now = () => performance.now();\n\nclass Handshake {\n\treadonly #doc: Document;\n\treadonly #pages: HandshakePage[] = [];\n\t#extension: BrowserExtension | undefined;\n\t#vouches: Vouch[] = [];\n\n\tconstructor(doc: Document) {\n\t\tthis.#doc = doc;\n\t\tdoc.addEventListener(EXTENSION_EVENT, (event) =>\n\t\t\tthis.#heard((event as CustomEvent).detail),\n\t\t);\n\t\tdoc.documentElement?.setAttribute(MARK, \"1\");\n\t}\n\n\tjoin(page: HandshakePage): void {\n\t\tthis.#pages.push(page);\n\t\tif (this.#extension !== undefined) page.set(this.#extension);\n\t\tpage.mcp.addEventListener(\"grantschange\", () => this.#say(page, \"update\"));\n\t\tthis.#say(page, \"hello\");\n\t}\n\n\t#say(page: HandshakePage, type: \"hello\" | \"update\"): void {\n\t\t// The document's own `CustomEvent`: a document may take only events\n\t\t// of its realm.\n\t\tconst Custom = this.#doc.defaultView?.CustomEvent ?? CustomEvent;\n\t\tthis.#doc.dispatchEvent(\n\t\t\tnew Custom(PAGE_EVENT, {\n\t\t\t\tdetail: JSON.stringify({\n\t\t\t\t\tv: 1,\n\t\t\t\t\ttype,\n\t\t\t\t\tlibrary: page.version,\n\t\t\t\t\tapp: page.app,\n\t\t\t\t\t// Capped as the extension cuts what it hears: more would\n\t\t\t\t\t// not be heard anyway.\n\t\t\t\t\tapps: page.mcp.grants.slice(0, MAX_APPS).map((g) => ({\n\t\t\t\t\t\tname: g.client.name,\n\t\t\t\t\t\thost: g.client.host,\n\t\t\t\t\t})),\n\t\t\t\t}),\n\t\t\t}),\n\t\t);\n\t}\n\n\t#heard(detail: unknown): void {\n\t\tlet m: unknown;\n\t\ttry {\n\t\t\tm = typeof detail === \"string\" ? JSON.parse(detail) : undefined;\n\t\t} catch {\n\t\t\treturn;\n\t\t}\n\t\tif (!isObject(m) || m[\"v\"] !== 1) return;\n\t\tif (m[\"type\"] === \"vouch\") this.#vouch(m);\n\t\t// The call it was for ended or never reached the page: an unused vouch\n\t\t// must not wait its 2 s for another caller.\n\t\telse if (m[\"type\"] === \"withdraw\")\n\t\t\tthis.#vouches = this.#vouches.filter((v) => v.nonce !== m[\"nonce\"]);\n\t\telse if (m[\"type\"] === \"hello\" || m[\"type\"] === \"update\") {\n\t\t\tconst extension = extensionOf(m);\n\t\t\tif (extension === null) return;\n\t\t\tif (canonical(extension) !== canonical(this.#extension)) {\n\t\t\t\tthis.#extension = extension;\n\t\t\t\tfor (const page of this.#pages) page.set(extension);\n\t\t\t}\n\t\t\tif (m[\"type\"] === \"hello\")\n\t\t\t\tfor (const page of this.#pages) this.#say(page, \"update\");\n\t\t}\n\t}\n\n\t/**\n\t * A vouch, kept for the tool registered under its name now, by a page\n\t * that takes vouches: a tool registered anew after this does not get it.\n\t */\n\t#vouch(m: Record<string, unknown>): void {\n\t\tconst app = appOf(m[\"app\"]);\n\t\tconst name = m[\"tool\"];\n\t\tconst nonce = m[\"nonce\"];\n\t\tif (\n\t\t\tapp === undefined ||\n\t\t\ttypeof name !== \"string\" ||\n\t\t\ttypeof nonce !== \"string\" ||\n\t\t\t!isObject(m[\"arguments\"])\n\t\t)\n\t\t\treturn;\n\t\tthis.#drop();\n\t\t// The same vouch heard twice counts once.\n\t\tif (this.#vouches.some((v) => v.nonce === nonce)) return;\n\t\tfor (const page of this.#pages) {\n\t\t\tconst tool = page.trust ? page.registry.get(name) : undefined;\n\t\t\tif (tool === undefined) continue;\n\t\t\tthis.#vouches.push({\n\t\t\t\ttool,\n\t\t\t\targs: canonical(m[\"arguments\"]),\n\t\t\t\tnonce,\n\t\t\t\tapp,\n\t\t\t\tat: now(),\n\t\t\t});\n\t\t\tif (this.#vouches.length > MAX_VOUCHES) this.#vouches.shift();\n\t\t\treturn;\n\t\t}\n\t}\n\n\t/** Forget the vouches older than `VOUCH_MS`. */\n\t#drop(): void {\n\t\tconst t = now();\n\t\tthis.#vouches = this.#vouches.filter((v) => t - v.at <= VOUCH_MS);\n\t}\n\n\t/**\n\t * The vouch for this call of `tool` with `input`, used up; `undefined`\n\t * if there is none (the call is asked as without the extension).\n\t */\n\ttake(tool: RegisteredTool, input: unknown): VouchedBy | undefined {\n\t\tthis.#drop();\n\t\tconst args = canonical(input);\n\t\tconst i = this.#vouches.findIndex(\n\t\t\t(v) => v.tool === tool && v.args === args,\n\t\t);\n\t\treturn i < 0 ? undefined : this.#vouches.splice(i, 1)[0]?.app;\n\t}\n}\n\n/**\n * The extension's state from its `hello` or `update`: `undefined` when it\n * does not serve the page now, `null` when the message is malformed.\n */\nfunction extensionOf(\n\tm: Record<string, unknown>,\n): BrowserExtension | undefined | null {\n\tif (m[\"on\"] !== true) return m[\"on\"] === false ? undefined : null;\n\tconst { name, apps } = m;\n\tif (!text(name) || !Array.isArray(apps)) return null;\n\tconst list = apps.slice(0, MAX_APPS).map(appOf);\n\tif (list.some((a) => a === undefined)) return null;\n\treturn Object.freeze({\n\t\tname,\n\t\tapps: Object.freeze(list.map((a) => Object.freeze(a as VouchedBy))),\n\t\twhileInFront: m[\"whileInFront\"] !== false,\n\t});\n}\n\nconst handshakes = new WeakMap<Document, Handshake>();\n\n/**\n * The handshake of the page's top-level document, which `page` joins; the\n * extension speaks only to the top frame. `undefined` in a frame or\n * without a document.\n */\nexport function joinHandshake(page: HandshakePage): Handshake | undefined {\n\tconst doc = globalThis.document;\n\tif (doc === undefined || globalThis.top !== globalThis.window)\n\t\treturn undefined;\n\tlet handshake = handshakes.get(doc);\n\tif (handshake === undefined) {\n\t\thandshake = new Handshake(doc);\n\t\thandshakes.set(doc, handshake);\n\t}\n\thandshake.join(page);\n\treturn handshake;\n}\n",
6
- "/**\n * Mirroring the tools into the browser's own WebMCP (iteration 25, DEC-115,\n * DEC-119, DEC-143): with `webmcp: true`, each tool that is offered there is\n * also registered with `document.modelContext.registerTool()`, under its own\n * `AbortController`, aborted when the tool leaves the registry. A chunk of\n * its own (DEC-171), loaded by a `TabMcp` whose constructor found native\n * WebMCP (`nativeContext` in the core); a call loads the connection chunk,\n * which checks and runs it. The handshake with the tab-mcp browser\n * extension (`handshake.ts`, DEC-207) is here too: only a page that mirrors\n * takes part.\n */\n\nimport {\n\ttype HandshakePage,\n\tjoinHandshake,\n\ttype VouchedBy,\n} from \"./handshake.ts\";\nimport type { RegisteredTool, ToolRegistry } from \"./registry.ts\";\nimport type { BrowserExtension } from \"./types.ts\";\n\n/** What the library uses of the browser's `ModelContext`. */\nexport interface ModelContext {\n\tregisterTool(\n\t\ttool: object,\n\t\toptions: { signal: AbortSignal; exposedTo: string[] | undefined },\n\t): unknown;\n}\n\n/**\n * Runs a call of a mirrored tool; `signal` is the browser's, if it gives\n * one; `by`: the AI app the tab-mcp browser extension vouched for it.\n */\nexport type WebMcpCall = (\n\ttool: RegisteredTool,\n\tinput: unknown,\n\tsignal: unknown,\n\tby: VouchedBy | undefined,\n) => Promise<unknown>;\n\n/** The WebMCP hints; the MCP-only ones are left out. */\nconst HINTS = [\n\t\"readOnlyHint\",\n\t\"untrustedContentHint\",\n\t\"consequentialHint\",\n\t\"debugging\",\n] as const;\n\n/**\n * Mirror `registry`'s tools into `context`, now and whenever the registry\n * changes: every tool, unless its `callers` leave `\"webmcp\"` out (DEC-165,\n * DEC-209). A tool that asks is marked `consequentialHint`, so that the agent\n * asks its user; MCP's `destructiveHint` counts as `consequentialHint`\n * (DEC-143). The page's `onConfirm` decides such a call, never the library's\n * dialog (DEC-215). Every failure of the native `registerTool()`\n * stays here: warned once per name, the tool still offered through the relay.\n * The page joins the handshake with the tab-mcp browser extension: `mcp`\n * is its `TabMcp`, `app` its app id, `options` its options\n * (`trustExtension`, and `onConfirm` for the warning below), `version` the\n * library's. A tool that asks, mirrored with an `exposedTo` that names\n * other origins on a page without `onConfirm`, is warned about once per\n * name (`warnUnasked`): documents of those origins can run it, and the\n * library asks no WebMCP caller (DEC-215). The extension's state is `mcp.extension`, defined\n * here on the instance (the core only declares it, for its bytes), and\n * `extensionchange` is sent here.\n */\nexport function mirror(\n\tregistry: ToolRegistry,\n\tcontext: ModelContext,\n\tcall: WebMcpCall,\n\tmcp: HandshakePage[\"mcp\"],\n\tapp: string,\n\toptions: { trustExtension?: boolean; onConfirm?: unknown },\n\tversion: string,\n): void {\n\tlet state: BrowserExtension | undefined;\n\tObject.defineProperty(mcp, \"extension\", {\n\t\tget: () => state,\n\t\tconfigurable: true,\n\t});\n\tlet handshake: ReturnType<typeof joinHandshake>;\n\ttry {\n\t\thandshake = joinHandshake({\n\t\t\tversion,\n\t\t\tapp,\n\t\t\tregistry,\n\t\t\ttrust: options.trustExtension !== false,\n\t\t\tmcp,\n\t\t\tset: (extension) => {\n\t\t\t\tstate = extension;\n\t\t\t\tmcp.dispatchEvent(\n\t\t\t\t\tnew CustomEvent(\"extensionchange\", { detail: { extension } }),\n\t\t\t\t);\n\t\t\t},\n\t\t});\n\t} catch (error) {\n\t\t// The tools are mirrored all the same; no call is vouched for.\n\t\tconsole.warn(\"tab-mcp: no handshake with the browser extension:\", error);\n\t}\n\tconst mirrors = new Map<RegisteredTool, AbortController>();\n\tconst warned = new Set<string>();\n\tconst unasked = new Set<string>();\n\t/**\n\t * The warning about a tool that asks with `exposedTo` (DEC-215), once its\n\t * native registration succeeded (so Chrome accepted every origin), once\n\t * per name. Decided then: a handler the page removes later is not\n\t * caught. Never throws, whatever `exposedTo` holds.\n\t */\n\tconst warnUnasked = (tool: RegisteredTool, asks: boolean | undefined) => {\n\t\ttry {\n\t\t\t// React's provider always passes a handler; `own` says whether the\n\t\t\t// page gave one.\n\t\t\tconst ask = options.onConfirm as { own?: boolean } | undefined;\n\t\t\tconst page = globalThis.document?.location?.origin;\n\t\t\tconst others = (\n\t\t\t\tArray.isArray(tool.exposedTo) ? tool.exposedTo : []\n\t\t\t).filter((entry: unknown) => {\n\t\t\t\ttry {\n\t\t\t\t\treturn new URL(String(entry)).origin !== page;\n\t\t\t\t} catch {\n\t\t\t\t\treturn false; // the browser refuses it anyway\n\t\t\t\t}\n\t\t\t});\n\t\t\tif (\n\t\t\t\tasks !== true ||\n\t\t\t\tothers.length === 0 ||\n\t\t\t\t(ask && ask.own !== false) ||\n\t\t\t\tunasked.has(tool.name)\n\t\t\t)\n\t\t\t\treturn;\n\t\t\tunasked.add(tool.name);\n\t\t\tconsole.warn(\n\t\t\t\t`tab-mcp: ${tool.name} asks before it runs, but documents of ${others.join(\", \")} (its exposedTo) can call it through WebMCP without a question: the library asks no WebMCP caller. Refuse such calls in onConfirm, or leave exposedTo off.`,\n\t\t\t);\n\t\t} catch {\n\t\t\t// a warning never stops the mirror\n\t\t}\n\t};\n\tconst sync = (): void => {\n\t\tfor (const [tool, controller] of mirrors) {\n\t\t\tif (registry.get(tool.name) === tool) continue;\n\t\t\tcontroller.abort();\n\t\t\tmirrors.delete(tool);\n\t\t}\n\t\tfor (const tool of registry.list()) {\n\t\t\tconst { annotations, callers } = tool;\n\t\t\tconst consequential =\n\t\t\t\tannotations.consequentialHint ?? annotations.destructiveHint;\n\t\t\t// The one place of the rule for WebMCP (the relay and a port: `toolsFor`).\n\t\t\tif (mirrors.has(tool) || !(callers?.includes(\"webmcp\") ?? true)) continue;\n\t\t\tconst controller = new AbortController();\n\t\t\tmirrors.set(tool, controller);\n\t\t\tconst hints: Record<string, boolean | undefined> = {\n\t\t\t\tconsequentialHint: consequential,\n\t\t\t};\n\t\t\tfor (const key of HINTS) hints[key] ??= annotations[key];\n\t\t\tconst { signal } = controller;\n\t\t\tPromise.resolve()\n\t\t\t\t// Not once unmirrored: whatever the browser does with an aborted\n\t\t\t\t// signal.\n\t\t\t\t.then(\n\t\t\t\t\t() =>\n\t\t\t\t\t\tsignal.aborted ||\n\t\t\t\t\t\tcontext.registerTool(\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: tool.name,\n\t\t\t\t\t\t\t\t// WebIDL dictionaries: `undefined` is the same as left out.\n\t\t\t\t\t\t\t\ttitle: tool.title,\n\t\t\t\t\t\t\t\tdescription: tool.description,\n\t\t\t\t\t\t\t\tinputSchema: tool.inputSchema,\n\t\t\t\t\t\t\t\toutputSchema: tool.outputSchema,\n\t\t\t\t\t\t\t\tannotations: hints,\n\t\t\t\t\t\t\t\t// The vouch is looked up as the call arrives: it was\n\t\t\t\t\t\t\t\t// sent right before the extension made the call.\n\t\t\t\t\t\t\t\texecute: (input: unknown, options?: { signal?: unknown }) =>\n\t\t\t\t\t\t\t\t\tcall(\n\t\t\t\t\t\t\t\t\t\ttool,\n\t\t\t\t\t\t\t\t\t\tinput,\n\t\t\t\t\t\t\t\t\t\toptions?.signal,\n\t\t\t\t\t\t\t\t\t\thandshake?.take(tool, input),\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{ signal, exposedTo: tool.exposedTo },\n\t\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t\t.then(() => {\n\t\t\t\t\tif (!signal.aborted) warnUnasked(tool, consequential);\n\t\t\t\t})\n\t\t\t\t.catch((error: unknown) => {\n\t\t\t\t\tif (signal.aborted) return; // unmirrored meanwhile\n\t\t\t\t\tif (warned.has(tool.name)) return;\n\t\t\t\t\twarned.add(tool.name);\n\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t`tab-mcp: ${tool.name} is not offered through WebMCP:`,\n\t\t\t\t\t\terror,\n\t\t\t\t\t);\n\t\t\t\t});\n\t\t}\n\t};\n\tregistry.onChange(sync);\n\tsync();\n}\n"
7
- ],
8
- "mappings": ";AAqCO,IAAM,aAAa;AAEnB,IAAM,kBAAkB;AAExB,IAAM,OAAO;AAEb,IAAM,WAAW;AAExB,IAAM,cAAc;AAEpB,IAAM,WAAW;AACjB,IAAM,WAAW;AA+BjB,IAAM,WAAW,CAAC,UACjB,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAEpE,IAAM,OAAO,CAAC,UACb,OAAO,UAAU,YAAY,MAAM,UAAU;AAG9C,SAAS,KAAK,CAAC,O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