@ractive-ch/tab-mcp-client 0.13.0 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -19
- package/cdn/connection-jk28y9f6.min.js +12 -0
- package/cdn/{connection-bjvxzxer.min.js.map → connection-jk28y9f6.min.js.map} +3 -3
- package/cdn/tab-mcp-client.min.js +3 -3
- package/cdn/tab-mcp-client.min.js.map +3 -3
- package/{connection-axx7m1x0.js → connection-h2ct4x47.js} +19 -16
- package/{connection-axx7m1x0.js.map → connection-h2ct4x47.js.map} +3 -3
- package/index.js +5 -3
- package/index.js.map +3 -3
- package/mcp.d.ts +10 -11
- package/package.json +1 -1
- package/version.d.ts +1 -2
- package/cdn/connection-bjvxzxer.min.js +0 -12
package/README.md
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
# @ractive-ch/tab-mcp-client
|
|
2
2
|
|
|
3
3
|
Offer a web page's functions as [MCP](https://modelcontextprotocol.io) tools to AI apps
|
|
4
|
-
(Claude, ChatGPT, Claude Code) through a
|
|
5
|
-
relay. The page connects to the relay and
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
(Claude, ChatGPT, Claude Code, Codex) through a
|
|
5
|
+
[tab-mcp](https://github.com/ractive/tab-mcp) relay. The page connects to the relay and
|
|
6
|
+
gets an address. The user adds that address to their AI app and types a pairing code
|
|
7
|
+
from the page; the AI app then calls the page's tools while the tab stays open. Nothing
|
|
8
|
+
is installed on the user's computer. With `webmcp: true` the library also registers the
|
|
9
|
+
tools with the browser's own [WebMCP](#webmcp), for agents in the browser.
|
|
10
|
+
|
|
11
|
+
**Status: 0.13.1.** Until 1.0, a new minor version can still change the API. Which AI apps
|
|
10
12
|
work is listed in [compatibility](https://github.com/ractive/tab-mcp/blob/main/docs/compatibility.md).
|
|
11
13
|
|
|
12
14
|
## You need a relay
|
|
@@ -38,7 +40,7 @@ Or without a bundler, from a CDN as an ES module:
|
|
|
38
40
|
|
|
39
41
|
```html
|
|
40
42
|
<script type="module">
|
|
41
|
-
import { TabMcp } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.13.
|
|
43
|
+
import { TabMcp } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.13.1/cdn/tab-mcp-client.min.js";
|
|
42
44
|
</script>
|
|
43
45
|
```
|
|
44
46
|
|
|
@@ -81,8 +83,8 @@ PNG, JPEG, GIF, WebP or ICO `data:` URIs up to 16 KiB (no inline SVG). They go o
|
|
|
81
83
|
|
|
82
84
|
### Tools
|
|
83
85
|
|
|
84
|
-
`registerTool(tool, { signal })` takes a tool in the shape of the WebMCP draft's
|
|
85
|
-
`registerTool`:
|
|
86
|
+
`registerTool(tool, { signal, webmcp })` takes a tool in the shape of the WebMCP draft's
|
|
87
|
+
`registerTool` (`webmcp`: see [WebMCP](#webmcp)):
|
|
86
88
|
|
|
87
89
|
- `name` (1-128 characters of `A-Z a-z 0-9 _ - .`), `title`, `description` (not empty);
|
|
88
90
|
- `inputSchema`: a JSON Schema with `"type": "object"`. Arguments are checked against it
|
|
@@ -115,10 +117,15 @@ added and removed tools.
|
|
|
115
117
|
|
|
116
118
|
`new TabMcp({ ..., webmcp: true })` also registers the tools with the browser's own
|
|
117
119
|
WebMCP (`document.modelContext.registerTool()`, the
|
|
118
|
-
[WebMCP draft](https://webmachinelearning.github.io/webmcp/)
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
120
|
+
[WebMCP draft](https://webmachinelearning.github.io/webmcp/) of the W3C Web Machine
|
|
121
|
+
Learning Community Group; [explainer](https://github.com/webmachinelearning/webmcp)),
|
|
122
|
+
where the browser has it, so that agents in the browser can call them: an agent built
|
|
123
|
+
into the browser, or an extension. Off by default. Turning it on is a change in what the
|
|
124
|
+
page exposes: any agent in the browser can then call the mirrored tools without pairing.
|
|
125
|
+
Chrome has WebMCP for sites in its
|
|
126
|
+
[origin trial](https://developer.chrome.com/blog/ai-webmcp-origin-trial) (from Chrome
|
|
127
|
+
149) and with `chrome://flags/#enable-webmcp-testing`
|
|
128
|
+
([Chrome's WebMCP docs](https://developer.chrome.com/docs/ai/webmcp)).
|
|
122
129
|
|
|
123
130
|
- Tools marked `consequentialHint` are left out unless their registration says
|
|
124
131
|
`{ webmcp: true }`: an agent in the browser often drives the very tab it calls into,
|
|
@@ -129,12 +136,17 @@ agent in the browser can then call the mirrored tools without pairing.
|
|
|
129
136
|
the library's dialog, which names the caller "An agent in this browser"), and
|
|
130
137
|
`toolcall` and `toolcallend` fire with `client: { kind: "webmcp" }`. "Always allow" is
|
|
131
138
|
never offered or applied for these calls: there is no identity to remember it for.
|
|
132
|
-
- The call resolves with what `execute` returned.
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
139
|
+
- The call resolves with what `execute` returned. A failure resolves too, as
|
|
140
|
+
`{ error: "<message>" }`, so that the agent can read it: invalid arguments (the same
|
|
141
|
+
message as for an AI app), "Don't allow" (`The user did not allow <tool> to run.`), a
|
|
142
|
+
tool that is gone, an error thrown by `execute` (its message) and an MCP result with
|
|
143
|
+
`isError: true` (its text). A rejection would not help: Chrome 156 hands the agent
|
|
144
|
+
every rejection as a bare `UnknownError`, without its message. Two cases still
|
|
145
|
+
reject: a call the browser cancelled (`AbortError`), since its caller no longer waits
|
|
146
|
+
for an answer, and a call made when the library's lazily loaded part cannot be loaded
|
|
147
|
+
(a new deploy with other chunk names while the page stays open, the network, a
|
|
148
|
+
Content Security Policy); reloading the page fixes the latter.
|
|
149
|
+
`toolcallend` reports the outcome as for an AI app (`error`, `declined`, `cancelled`).
|
|
138
150
|
- Only the native object is used, read through `Document.prototype`'s getter: an own
|
|
139
151
|
`document.modelContext` (a polyfill such as `@mcp-b/global`, or a page script) is
|
|
140
152
|
passed by, and with native WebMCP and the polyfill both present the tools go to the
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
var ht=/^(?:\d{1,4}x\d{1,4}|any)$/;function $t(e){let{src:t,mimeType:n,sizes:o,theme:s}=e;if(typeof t!=="string")return;let i=/^https?:/i.test(t)&&t.length<=2048,r=/^data:image\/(?:png|jpeg|gif|webp|x-icon|vnd\.microsoft\.icon)[;,]/i.test(t)&&t.length<=16384;if(!i&&!r)return;let a={src:t};if(typeof n==="string"&&/^image\/[\w.+-]+$/i.test(n))a.mimeType=n.toLowerCase();let c=Array.isArray(o)?o.map((_)=>String(_).toLowerCase()).filter((_)=>ht.test(_)):[];if(c.length>0)a.sizes=c;if(s==="light"||s==="dark")a.theme=s;return a}function ve(e){let t=[];for(let n of e){let o=typeof n==="object"&&n!==null?$t(n):void 0;if(o!==void 0)t.push(o);if(t.length===8)break}return t}function qe(e=globalThis.document){try{let t=e?.querySelectorAll('link[rel~="icon" i], link[rel~="apple-touch-icon" i]');return ve([...t??[]].filter((n)=>n.getAttribute("href")?.trim()).map((n)=>{let o={src:n.href};if(n.type)o.mimeType=n.type;let s=n.getAttribute("sizes");if(s)o.sizes=s.trim().split(/\s+/);let i=/prefers-color-scheme:\s*(light|dark)/i.exec(n.media);if(i)o.theme=i[1]?.toLowerCase();return o}))}catch{return[]}}function ae(e,t){let n=typeof e;if(n!==typeof t)return!1;let o=Array.isArray(e),s=Array.isArray(t);if(o!==s)return!1;if(o){let i=e.length;if(i!==t.length)return!1;for(let r=0;r<i;r++)if(!ae(e[r],t[r]))return!1;return!0}if(n==="object"){if(!e||!t)return e===t;let i=Object.keys(e),r=Object.keys(t);if(i.length!==r.length)return!1;for(let c of i){if(!Object.prototype.hasOwnProperty.call(t,c))return!1;if(!ae(e[c],t[c]))return!1}return!0}return e===t}function J(e){return encodeURI(bt(e)).replace(/#/g,"%23")}function bt(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}var wt=/^[A-Za-z0-9._~!$&'()*+,;=:@/?-]$/,xt=/^%[0-9A-Fa-f]{2}$/,Rt=/^[A-Za-z0-9._~-]$/;function kt(e){let t="";for(let n=0;n<e.length;){let o=e[n],s=e.slice(n,n+3);if(o==="%"&&xt.test(s)){let r=String.fromCharCode(parseInt(s.slice(1),16));t+=Rt.test(r)?r:s.toUpperCase(),n+=3;continue}let i=String.fromCodePoint(e.codePointAt(n));t+=wt.test(i)?i:encodeURIComponent(i),n+=i.length}return t}function be(e,t){let n=new URL(e,t.href);return n.hash=n.hash?kt(n.hash.slice(1)):"",n}var It={prefixItems:!0,items:!0,allOf:!0,anyOf:!0,oneOf:!0},Tt={$defs:!0,definitions:!0,properties:!0,patternProperties:!0,dependentSchemas:!0},vt={id:!0,$id:!0,$ref:!0,$schema:!0,$anchor:!0,$vocabulary:!0,$comment:!0,default:!0,enum:!0,const:!0,required:!0,dependentRequired:!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},_t=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),n=_t,o=""){if(e&&typeof e==="object"&&!Array.isArray(e)){let i=e.$id||e.id;if(i){let r=be(i,n);if(r.hash.length>1)t[r.href]=e;else if(r.hash="",o==="")n=r;else ee(e,t,n)}}else if(e!==!0&&e!==!1)return t;let s=n.href+(o?"#"+o:"");if(t[s]!==void 0&&t[s]!==e)throw Error(`Duplicate schema URI "${s}".`);if(t[s]=e,e===!0||e===!1)return t;if(e.__absolute_uri__===void 0)Object.defineProperty(e,"__absolute_uri__",{enumerable:!1,value:s});if(e.$ref&&e.__absolute_ref__===void 0){let i=be(e.$ref,n);Object.defineProperty(e,"__absolute_ref__",{enumerable:!1,value:i.href})}if(e.$recursiveRef&&e.__absolute_recursive_ref__===void 0){let i=be(e.$recursiveRef,n);Object.defineProperty(e,"__absolute_recursive_ref__",{enumerable:!1,value:i.href})}if(e.$anchor){let i=be("#"+e.$anchor,n);t[i.href]=e}for(let i in e){if(vt[i])continue;let r=`${o}/${J(i)}`,a=e[i];if(Array.isArray(a)){if(It[i]){let c=a.length;for(let _=0;_<c;_++)ee(a[_],t,n,`${r}/${_}`)}}else if(Tt[i])for(let c in a)ee(a[c],t,n,`${r}/${J(c)}`);else ee(a,t,n,r)}return t}var St=/^(\d\d\d\d)-(\d\d)-(\d\d)$/,Mt=[0,31,28,31,30,31,30,31,31,30,31,30,31],Ot=/^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|([+-])(\d\d):(\d\d))?$/i,ze=/^(?=.{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,Et=/^(?:[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,At=/^(?:(?:[^\x00-\x20\x7f"<>%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?:\.(?:[a-z0-9_]|%[0-9a-f]{2})+)*(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?:\.(?:[a-z0-9_]|%[0-9a-f]{2})+)*(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i,Ct=/^(?:(?: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,Pt=/^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i,Nt=/^(?:\/(?:[^~/]|~0|~1)*)*$/,jt=/^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i,qt=/^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/,zt=/^("(?:[\x20-\x21\x23-\x5b\x5d-\x7e]|\\[\x20-\x7e])*"|[a-z0-9.!#$%&'*+/=?^_`{|}~-]+)@(.+)$/i,Ht=(e)=>{let t=e.match(zt);if(!t)return!1;let n=t[1],o=t[2];if(!n||!o||n.length>64||o.length>253)return!1;if(n[0]!=='"'&&(n[0]==="."||n.endsWith(".")||n.includes("..")))return!1;if(o.startsWith("[")&&o.endsWith("]")){let s=o.slice(1,-1);if(/^ipv6:/i.test(s))return Je.test(s.slice(5));return He.test(s)}return ze.test(o)},He=/^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,Je=/^((([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,Jt=(e)=>/^P(?:\d+W|(?:(?:\d+Y(?:\d+M(?:\d+D)?)?|\d+M(?:\d+D)?|\d+D)(?:T(?:\d+H(?:\d+M(?:\d+S)?)?|\d+M(?:\d+S)?|\d+S))?|T(?:\d+H(?:\d+M(?:\d+S)?)?|\d+M(?:\d+S)?|\d+S)))$/.test(e);function K(e){return e.test.bind(e)}var _e={date:Ue,time:Be.bind(void 0,!0),"date-time":Dt,duration:Jt,uri:Wt,"uri-reference":K(Et),"uri-template":K(At),url:K(Ct),email:Ht,hostname:K(ze),ipv4:K(He),ipv6:K(Je),regex:Kt,uuid:K(Pt),"json-pointer":K(Nt),"json-pointer-uri-fragment":K(jt),"relative-json-pointer":K(qt)};function Ut(e){return e%4===0&&(e%100!==0||e%400===0)}function Ue(e){let t=e.match(St);if(!t)return!1;let n=t[1],o=t[2],s=t[3];if(!n||!o||!s)return!1;let i=+n,r=+o,a=+s,c=r==2&&Ut(i)?29:Mt[r];return r>=1&&r<=12&&a>=1&&c!==void 0&&a<=c}function Be(e,t){let n=t.match(Ot);if(!n)return!1;let o=n[1],s=n[2],i=n[3];if(!o||!s||!i)return!1;let r=+o,a=+s,c=+i,_=n[5],I=n[6],N=+(n[7]??0),D=+(n[8]??0);if(r>23||a>59||c>60||N>23||D>59||e&&_===void 0)return!1;if(c<60)return!0;let U=I==="+"?1:I==="-"?-1:0;return(r*60+a-U*(N*60+D)+1440)%1440===1439}var Bt=/t|\s/i;function Dt(e){let[t,n,o]=e.split(Bt);return t!==void 0&&n!==void 0&&o===void 0&&Ue(t)&&Be(!0,n)}var Vt=/\/|:/,Gt=/^(?:[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 Wt(e){return Vt.test(e)&&Gt.test(e)}var Ft=/[^\\]\\Z/;function Kt(e){if(Ft.test(e))return!1;try{return new RegExp(e,"u"),!0}catch(t){return!1}}function De(e){let t=0,n=e.length,o=0,s;while(o<n)if(t++,s=e.charCodeAt(o++),s>=55296&&s<=56319&&o<n){if(s=e.charCodeAt(o),(s&64512)==56320)o++}return t}function se(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Ve(e){let t=Math.abs(e).toString().split("e"),n=t[0],o=t[1]??"0",s=n.indexOf("."),i=s===-1?0:n.length-s-1;return[BigInt(n.replace(".","")),Number(o)-i]}function Yt(e,t){if(!Number.isFinite(e)||!Number.isFinite(t)||t<=0)return!1;let[n,o]=Ve(e),[s,i]=Ve(t),r=o-i;if(r>=0)return n*10n**BigInt(r)%s===0n;return n%(s*10n**BigInt(-r))===0n}function E(e,t,n="2019-09",o=ee(t),s=!0,i=null,r="#",a="#",c=Object.create(null)){if(t===!0)return{valid:!0,errors:[]};if(t===!1)return{valid:!1,errors:[{instanceLocation:r,keyword:"false",keywordLocation:r,error:"False boolean schema."}]};let _=typeof e,I;switch(_){case"boolean":case"number":case"string":I=_;break;case"object":if(e===null)I="null";else if(Array.isArray(e))I="array";else I="object";break;default:throw Error(`Instances of "${_}" type are not supported.`)}let{$ref:N,$recursiveRef:D,$recursiveAnchor:U,type:C,const:G,enum:B,required:L,not:m,anyOf:y,allOf:T,oneOf:v,if:R,then:S,else:A,format:d,properties:k,patternProperties:w,additionalProperties:j,unevaluatedProperties:M,minProperties:z,maxProperties:H,propertyNames:W,dependentRequired:Z,dependentSchemas:V,dependencies:F,prefixItems:ce,items:ne,additionalItems:Ee,unevaluatedItems:Ae,contains:Ce,minContains:X,maxContains:Re,minItems:ke,maxItems:Ie,uniqueItems:yt,minimum:re,maximum:oe,exclusiveMinimum:pe,exclusiveMaximum:me,multipleOf:Te,minLength:ye,maxLength:ge,pattern:Pe,__absolute_ref__:he,__absolute_recursive_ref__:gt}=t,l=[];if(U===!0&&i===null)i=t;if(D==="#"){let b=i===null?o[gt]:i,p=`${a}/$recursiveRef`,x=E(e,i===null?t:i,n,o,s,b,r,p,c);if(!x.valid)l.push({instanceLocation:r,keyword:"$recursiveRef",keywordLocation:p,error:"A subschema had errors."},...x.errors)}if(N!==void 0){let p=o[he||N];if(p===void 0){let u=`Unresolved $ref "${N}".`;if(he&&he!==N)u+=` Absolute URI "${he}".`;throw u+=`
|
|
2
|
+
Known schemas:
|
|
3
|
+
- ${Object.keys(o).join(`
|
|
4
|
+
- `)}`,Error(u)}let x=`${a}/$ref`,f=E(e,p,n,o,s,i,r,x,c);if(!f.valid)l.push({instanceLocation:r,keyword:"$ref",keywordLocation:x,error:"A subschema had errors."},...f.errors);if(n==="4"||n==="7")return{valid:l.length===0,errors:l}}if(Array.isArray(C)){let b=C.length,p=!1;for(let x=0;x<b;x++)if(I===C[x]||C[x]==="integer"&&I==="number"&&e%1===0&&e===e){p=!0;break}if(!p)l.push({instanceLocation:r,keyword:"type",keywordLocation:`${a}/type`,error:`Instance type "${I}" is invalid. Expected "${C.join('", "')}".`})}else if(C==="integer"){if(I!=="number"||e%1||e!==e)l.push({instanceLocation:r,keyword:"type",keywordLocation:`${a}/type`,error:`Instance type "${I}" is invalid. Expected "${C}".`})}else if(C!==void 0&&I!==C)l.push({instanceLocation:r,keyword:"type",keywordLocation:`${a}/type`,error:`Instance type "${I}" is invalid. Expected "${C}".`});if(G!==void 0){if(I==="object"||I==="array"){if(!ae(e,G))l.push({instanceLocation:r,keyword:"const",keywordLocation:`${a}/const`,error:`Instance does not match ${JSON.stringify(G)}.`})}else if(e!==G)l.push({instanceLocation:r,keyword:"const",keywordLocation:`${a}/const`,error:`Instance does not match ${JSON.stringify(G)}.`})}if(B!==void 0){if(I==="object"||I==="array"){if(!B.some((b)=>ae(e,b)))l.push({instanceLocation:r,keyword:"enum",keywordLocation:`${a}/enum`,error:`Instance does not match any of ${JSON.stringify(B)}.`})}else if(!B.some((b)=>e===b))l.push({instanceLocation:r,keyword:"enum",keywordLocation:`${a}/enum`,error:`Instance does not match any of ${JSON.stringify(B)}.`})}if(m!==void 0){let b=`${a}/not`;if(E(e,m,n,o,s,i,r,b).valid)l.push({instanceLocation:r,keyword:"not",keywordLocation:b,error:'Instance matched "not" schema.'})}let $e=[];if(y!==void 0){let b=`${a}/anyOf`,p=l.length,x=!1;for(let[f,u]of y.entries()){let h=Object.create(c),g=E(e,u,n,o,s,U===!0?i:null,r,`${b}/${f}`,h);if(l.push(...g.errors),x=x||g.valid,g.valid)$e.push(h)}if(x)l.length=p;else l.splice(p,0,{instanceLocation:r,keyword:"anyOf",keywordLocation:b,error:"Instance does not match any subschemas."})}if(T!==void 0){let b=`${a}/allOf`,p=l.length,x=!0;for(let[f,u]of T.entries()){let h=Object.create(c),g=E(e,u,n,o,s,U===!0?i:null,r,`${b}/${f}`,h);if(l.push(...g.errors),x=x&&g.valid,g.valid)$e.push(h)}if(x)l.length=p;else l.splice(p,0,{instanceLocation:r,keyword:"allOf",keywordLocation:b,error:"Instance does not match every subschema."})}if(v!==void 0){let b=`${a}/oneOf`,p=l.length,x=v.filter((f,u)=>{let h=Object.create(c),g=E(e,f,n,o,s,U===!0?i:null,r,`${b}/${u}`,h);if(l.push(...g.errors),g.valid)$e.push(h);return g.valid}).length;if(x===1)l.length=p;else l.splice(p,0,{instanceLocation:r,keyword:"oneOf",keywordLocation:b,error:`Instance does not match exactly one subschema (${x} matches).`})}if(I==="object"||I==="array")Object.assign(c,...$e);if(R!==void 0){let b=`${a}/if`,p=Object.create(null);if(E(e,R,n,o,s,i,r,b,p).valid){if(Object.assign(c,p),S!==void 0){let f=E(e,S,n,o,s,i,r,`${a}/then`,c);if(!f.valid)l.push({instanceLocation:r,keyword:"if",keywordLocation:b,error:'Instance does not match "then" schema.'},...f.errors)}}else if(A!==void 0){let f=E(e,A,n,o,s,i,r,`${a}/else`,c);if(!f.valid)l.push({instanceLocation:r,keyword:"if",keywordLocation:b,error:'Instance does not match "else" schema.'},...f.errors)}}if(I==="object"){if(L!==void 0){for(let f of L)if(!se(e,f))l.push({instanceLocation:r,keyword:"required",keywordLocation:`${a}/required`,error:`Instance does not have required property "${f}".`})}let b=Object.keys(e);if(z!==void 0&&b.length<z)l.push({instanceLocation:r,keyword:"minProperties",keywordLocation:`${a}/minProperties`,error:`Instance does not have at least ${z} properties.`});if(H!==void 0&&b.length>H)l.push({instanceLocation:r,keyword:"maxProperties",keywordLocation:`${a}/maxProperties`,error:`Instance does not have at least ${H} properties.`});if(W!==void 0){let f=`${a}/propertyNames`;for(let u in e){let h=`${r}/${J(u)}`,g=E(u,W,n,o,s,i,h,f);if(!g.valid)l.push({instanceLocation:r,keyword:"propertyNames",keywordLocation:f,error:`Property name "${u}" does not match schema.`},...g.errors)}}if(Z!==void 0){let f=`${a}/dependantRequired`;for(let u in Z)if(se(e,u)){let h=Z[u];for(let g of h)if(!se(e,g))l.push({instanceLocation:r,keyword:"dependentRequired",keywordLocation:f,error:`Instance has "${u}" but does not have "${g}".`})}}if(V!==void 0)for(let[f,u]of Object.entries(V)){let h=`${a}/dependentSchemas`;if(se(e,f)){let g=E(e,u,n,o,s,i,r,`${h}/${J(f)}`,c);if(!g.valid)l.push({instanceLocation:r,keyword:"dependentSchemas",keywordLocation:h,error:`Instance has "${f}" but does not match dependant schema.`},...g.errors)}}if(F!==void 0){let f=`${a}/dependencies`;for(let u in F)if(se(e,u)){let h=F[u];if(Array.isArray(h)){for(let g of h)if(!se(e,g))l.push({instanceLocation:r,keyword:"dependencies",keywordLocation:f,error:`Instance has "${u}" but does not have "${g}".`})}else{let g=E(e,h,n,o,s,i,r,`${f}/${J(u)}`);if(!g.valid)l.push({instanceLocation:r,keyword:"dependencies",keywordLocation:f,error:`Instance has "${u}" but does not match dependant schema.`},...g.errors)}}}let p=Object.create(null),x=!1;if(k!==void 0){let f=`${a}/properties`;for(let[u,h]of Object.entries(k)){if(!se(e,u))continue;let g=`${r}/${J(u)}`,P=E(e[u],h,n,o,s,i,g,`${f}/${J(u)}`);if(p[u]=!0,P.valid)c[u]=!0;else if(x=s,l.push({instanceLocation:r,keyword:"properties",keywordLocation:f,error:`Property "${u}" does not match schema.`},...P.errors),x)break}}if(!x&&w!==void 0){let f=`${a}/patternProperties`;for(let[u,h]of Object.entries(w)){let g=new RegExp(u,"u");for(let P in e){if(!g.test(P))continue;let Ne=`${r}/${J(P)}`,je=E(e[P],h,n,o,s,i,Ne,`${f}/${J(u)}`);if(p[P]=!0,je.valid)c[P]=!0;else x=s,l.push({instanceLocation:r,keyword:"patternProperties",keywordLocation:f,error:`Property "${P}" matches pattern "${u}" but does not match associated schema.`},...je.errors)}}}if(!x&&j!==void 0){let f=`${a}/additionalProperties`;for(let u in e){if(p[u])continue;let h=`${r}/${J(u)}`,g=E(e[u],j,n,o,s,i,h,f);if(g.valid)c[u]=!0;else x=s,l.push({instanceLocation:r,keyword:"additionalProperties",keywordLocation:f,error:`Property "${u}" does not match additional properties schema.`},...g.errors)}}else if(!x&&M!==void 0){let f=`${a}/unevaluatedProperties`;for(let u in e)if(!c[u]){let h=`${r}/${J(u)}`,g=E(e[u],M,n,o,s,i,h,f);if(g.valid)c[u]=!0;else l.push({instanceLocation:r,keyword:"unevaluatedProperties",keywordLocation:f,error:`Property "${u}" does not match unevaluated properties schema.`},...g.errors)}}}else if(I==="array"){if(Ie!==void 0&&e.length>Ie)l.push({instanceLocation:r,keyword:"maxItems",keywordLocation:`${a}/maxItems`,error:`Array has too many items (${e.length} > ${Ie}).`});if(ke!==void 0&&e.length<ke)l.push({instanceLocation:r,keyword:"minItems",keywordLocation:`${a}/minItems`,error:`Array has too few items (${e.length} < ${ke}).`});let b=e.length,p=0,x=!1;if(ce!==void 0){let f=`${a}/prefixItems`,u=Math.min(ce.length,b);for(;p<u;p++){let h=E(e[p],ce[p],n,o,s,i,`${r}/${p}`,`${f}/${p}`);if(c[p]=!0,!h.valid){if(x=s,l.push({instanceLocation:r,keyword:"prefixItems",keywordLocation:f,error:"Items did not match schema."},...h.errors),x)break}}}if(ne!==void 0){let f=`${a}/items`;if(Array.isArray(ne)){let u=Math.min(ne.length,b);for(;p<u;p++){let h=E(e[p],ne[p],n,o,s,i,`${r}/${p}`,`${f}/${p}`);if(c[p]=!0,!h.valid){if(x=s,l.push({instanceLocation:r,keyword:"items",keywordLocation:f,error:"Items did not match schema."},...h.errors),x)break}}}else for(;p<b;p++){let u=E(e[p],ne,n,o,s,i,`${r}/${p}`,f);if(c[p]=!0,!u.valid){if(x=s,l.push({instanceLocation:r,keyword:"items",keywordLocation:f,error:"Items did not match schema."},...u.errors),x)break}}if(!x&&Ee!==void 0){let u=`${a}/additionalItems`;for(;p<b;p++){let h=E(e[p],Ee,n,o,s,i,`${r}/${p}`,u);if(c[p]=!0,!h.valid)x=s,l.push({instanceLocation:r,keyword:"additionalItems",keywordLocation:u,error:"Items did not match additional items schema."},...h.errors)}}}if(Ce!==void 0)if(b===0&&X===void 0)l.push({instanceLocation:r,keyword:"contains",keywordLocation:`${a}/contains`,error:"Array is empty. It must contain at least one item matching the schema."});else if(X!==void 0&&b<X)l.push({instanceLocation:r,keyword:"minContains",keywordLocation:`${a}/minContains`,error:`Array has less items (${b}) than minContains (${X}).`});else{let f=`${a}/contains`,u=l.length,h=0;for(let g=0;g<b;g++){let P=E(e[g],Ce,n,o,s,i,`${r}/${g}`,f);if(P.valid)c[g]=!0,h++;else l.push(...P.errors)}if(h>=(X||0))l.length=u;if(X===void 0&&h===0)l.splice(u,0,{instanceLocation:r,keyword:"contains",keywordLocation:f,error:"Array does not contain item matching schema."});else if(X!==void 0&&h<X)l.push({instanceLocation:r,keyword:"minContains",keywordLocation:`${a}/minContains`,error:`Array must contain at least ${X} items matching schema. Only ${h} items were found.`});else if(Re!==void 0&&h>Re)l.push({instanceLocation:r,keyword:"maxContains",keywordLocation:`${a}/maxContains`,error:`Array may contain at most ${Re} items matching schema. ${h} items were found.`})}if(!x&&Ae!==void 0){let f=`${a}/unevaluatedItems`;for(p;p<b;p++){if(c[p])continue;let u=E(e[p],Ae,n,o,s,i,`${r}/${p}`,f);if(c[p]=!0,!u.valid)l.push({instanceLocation:r,keyword:"unevaluatedItems",keywordLocation:f,error:"Items did not match unevaluated items schema."},...u.errors)}}if(yt)for(let f=0;f<b;f++){let u=e[f],h=typeof u==="object"&&u!==null;for(let g=0;g<b;g++){if(f===g)continue;let P=e[g];if(u===P||h&&(typeof P==="object"&&P!==null)&&ae(u,P))l.push({instanceLocation:r,keyword:"uniqueItems",keywordLocation:`${a}/uniqueItems`,error:`Duplicate items at indexes ${f} and ${g}.`}),f=Number.MAX_SAFE_INTEGER,g=Number.MAX_SAFE_INTEGER}}}else if(I==="number"){if(n==="4"){if(re!==void 0&&(pe===!0&&e<=re||e<re))l.push({instanceLocation:r,keyword:"minimum",keywordLocation:`${a}/minimum`,error:`${e} is less than ${pe?"or equal to ":""} ${re}.`});if(oe!==void 0&&(me===!0&&e>=oe||e>oe))l.push({instanceLocation:r,keyword:"maximum",keywordLocation:`${a}/maximum`,error:`${e} is greater than ${me?"or equal to ":""} ${oe}.`})}else{if(re!==void 0&&e<re)l.push({instanceLocation:r,keyword:"minimum",keywordLocation:`${a}/minimum`,error:`${e} is less than ${re}.`});if(oe!==void 0&&e>oe)l.push({instanceLocation:r,keyword:"maximum",keywordLocation:`${a}/maximum`,error:`${e} is greater than ${oe}.`});if(pe!==void 0&&e<=pe)l.push({instanceLocation:r,keyword:"exclusiveMinimum",keywordLocation:`${a}/exclusiveMinimum`,error:`${e} is less than ${pe}.`});if(me!==void 0&&e>=me)l.push({instanceLocation:r,keyword:"exclusiveMaximum",keywordLocation:`${a}/exclusiveMaximum`,error:`${e} is greater than or equal to ${me}.`})}if(Te!==void 0){if(!Yt(e,Te))l.push({instanceLocation:r,keyword:"multipleOf",keywordLocation:`${a}/multipleOf`,error:`${e} is not a multiple of ${Te}.`})}}else if(I==="string"){let b=ye===void 0&&ge===void 0?0:De(e);if(ye!==void 0&&b<ye)l.push({instanceLocation:r,keyword:"minLength",keywordLocation:`${a}/minLength`,error:`String is too short (${b} < ${ye}).`});if(ge!==void 0&&b>ge)l.push({instanceLocation:r,keyword:"maxLength",keywordLocation:`${a}/maxLength`,error:`String is too long (${b} > ${ge}).`});if(Pe!==void 0&&!new RegExp(Pe,"u").test(e))l.push({instanceLocation:r,keyword:"pattern",keywordLocation:`${a}/pattern`,error:"String does not match pattern."});if(d!==void 0&&_e[d]&&!_e[d](e))l.push({instanceLocation:r,keyword:"format",keywordLocation:`${a}/format`,error:`String does not match format "${d}".`})}return{valid:l.length===0,errors:l}}var We="ch.ractive.tab-mcp/annotations",Zt=["readOnlyHint","untrustedContentHint","consequentialHint","debugging"],Xt=["destructiveHint","idempotentHint","openWorldHint"];function Fe(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 s of Xt){let i=e[s];if(i!==void 0)t[s]=i}let n={};for(let s of Zt){let i=e[s];if(i!==void 0)n[s]=i}let o={};if(Object.keys(t).length>0)o.annotations=t;if(Object.keys(n).length>0)o.meta=n;return o}function ue(e){return{content:[{type:"text",text:e}],isError:!0}}function Ge(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function Ke(e){if(typeof e==="string")return{content:[{type:"text",text:e}]};if(e===void 0)return{content:[]};if(Ge(e)&&Array.isArray(e.content))return e;let t;try{t=JSON.stringify(e)}catch{}if(t===void 0)return ue("The tool returned a value that is not JSON.");let n={content:[{type:"text",text:t}]};if(Ge(e))n.structuredContent=e;return n}function Ye(e){let t=e instanceof Error?e.message:String(e);return ue(t||"The tool failed.")}var ie="2026-07-28",te="io.modelcontextprotocol/protocolVersion",we="io.modelcontextprotocol/clientCapabilities",Ze="io.modelcontextprotocol/clientInfo",Xe="io.modelcontextprotocol/serverInfo",Se="io.modelcontextprotocol/subscriptionId",Qt=-32020,Qe=-32022,Lt=0,Le=new WeakMap;function Me(e){let t=Le.get(e);if(t!==void 0)return t;let n=e.inputSchema,o;try{o=ee(n)}catch(i){let r=i instanceof Error?i.message:String(i);throw Error(r.split(`
|
|
5
|
+
`)[0])}for(let i of Object.values(o)){if(typeof i!=="object"||i.$ref===void 0)continue;let r=i.__absolute_ref__;if(o[r??i.$ref]===void 0)throw Error(`$ref ${JSON.stringify(i.$ref)} does not resolve`)}let s=(i)=>E(i,n,"2020-12",o,!1);return Le.set(e,s),s}function et(e,t,n=""){let o=t instanceof Error?t.message:String(t);return TypeError(`registerTool: the inputSchema of ${e}: ${o}${n}`)}function en(e){let t=[];for(let n of e.list())try{Me(n)}catch(o){e.remove(n),t.push(et(n.name,o,"; the tool was unregistered"))}return e.setCompiler((n)=>{try{Me(n)}catch(o){throw et(n.name,o)}}),t}function tt(e){try{return structuredClone(e)}catch{return e}}var tn=new TextEncoder;function Q(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function Oe(e,t){return new Response(JSON.stringify(t),{status:e,headers:{"content-type":"application/json"}})}function q(e,t,n,o,s){let i={code:n,message:o};if(s!==void 0)i.data=s;return Oe(e,{jsonrpc:"2.0",id:t,error:i})}function Y(e,t,n){return q(400,e,Qt,`Bad Request: the request headers and body disagree: ${n}`,{mismatch:{header:t,body:n}})}function le(e){return tn.encode(`event: message
|
|
6
|
+
data: ${JSON.stringify(e)}
|
|
7
|
+
|
|
8
|
+
`)}var nt={"content-type":"text/event-stream","cache-control":"no-cache"};function nn(e){return(e??"").split(";")[0]?.trim().toLowerCase()==="application/json"}function rn(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 n=atob(t),o=Uint8Array.from(n,(s)=>s.charCodeAt(0));return new TextDecoder("utf-8",{fatal:!0}).decode(o)}catch{return}}function on(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(!Q(e[we]))return{key:we,problem:"expected an object"};let t=e[Ze];if(t!==void 0&&!(Q(t)&&typeof t.name==="string"&&typeof t.version==="string"))return{key:Ze,problem:"expected {name, version}"};return}function sn(e){let t=e.notifications;return Q(t)&&t.toolsListChanged===!0?{toolsListChanged:!0}:{}}function dn(e,t){let n;try{n=Me(e)(t)}catch(s){let i=s instanceof Error?s.message:String(s);return`The input schema of tool ${e.name} cannot be used: ${i}`}if(n.valid)return;let o=n.errors.filter((s)=>s.keyword!=="properties"&&s.keyword!=="$ref").map((s)=>`${s.instanceLocation} ${s.error}`).slice(0,5).join("; ");return`Input validation error: Invalid arguments for tool ${e.name}: ${o||"the arguments do not match the schema"}`}async function rt(e,t,n,o,s){let i={id:++Lt,tool:t.name,arguments:tt(n),client:{...s}};if(t.title!==void 0)i.title=t.title;let r=Date.now();e.observe?.start(i);let a={outcome:"error",result:ue("Internal error")};try{a=await an(e,t,n,o,s)}finally{e.observe?.end({id:i.id,tool:t.name,client:{...s},outcome:a.outcome,result:tt(a.result),durationMs:Date.now()-r})}return a}async function an(e,t,n,o,s){let i=(c,_,I)=>({outcome:c,result:ue(_),stop:I}),r=dn(t,n);if(r!==void 0)return i("error",r,"invalid");if(t.annotations.consequentialHint===!0){let c={tool:{name:t.name,description:t.description},arguments:n,client:s,signal:o};if(t.title!==void 0)c.tool.title=t.title;let _=!1;try{_=await e.confirm(c)}catch{_=!1}if(!_)return o.aborted?i("cancelled","The user declined","cancelled"):i("declined","The user declined","declined")}if(o.aborted)return i("cancelled","Cancelled","cancelled");if(e.tools.get(t.name)!==t)return i("error","The tool is no longer available","gone");let a;try{let c=await t.execute(n,{signal:o,client:s});a={outcome:"ok",result:Ke(c),returned:{value:c}}}catch(c){a={outcome:"error",result:Ye(c)}}if(o.aborted)return{...a,outcome:"cancelled",stop:"cancelled"};if(a.result.isError===!0)a.outcome="error";return a}async function ot(e,t,n,o){let s=(a)=>({error:a}),i=`The tool ${t.name} is no longer available.`;if(e.tools.get(t.name)!==t)return s(i);if(!Q(n))return s("The input must be an object.");let r=await rt(e,t,n,o instanceof AbortSignal?o:new AbortController().signal,{kind:"webmcp"});if(r.stop==="cancelled")throw new DOMException("Cancelled","AbortError");if(r.stop==="declined")return s(`The user did not allow ${t.name} to run.`);if(r.stop==="gone")return s(i);if(r.result.isError===!0)return s(un(r.result)||"The tool failed.");return r.returned?.value}function un(e){return e.content.map((t)=>Q(t)&&t.type==="text"&&typeof t.text==="string"?t.text:"").filter((t)=>t!=="").join(`
|
|
9
|
+
`)}function st(e){let{tools:t,server:n}=e,o={name:n.name,version:n.version};if(n.title!==void 0)o.title=n.title;let s=ve(n.icons??[]),i=s.length>0?{...o,icons:s}:o,r=new Set,a=!1,c=(m={})=>({...m,[Xe]:o});function _(m,y,T=c()){return{jsonrpc:"2.0",id:m,result:{...y,resultType:"complete",_meta:T}}}function I(){return t.list().map((m)=>{let y={name:m.name};if(m.title!==void 0)y.title=m.title;y.description=m.description,y.inputSchema=m.inputSchema;let{annotations:T,meta:v}=Fe(m.annotations);if(T!==void 0)y.annotations=T;if(v!==void 0)y._meta={[We]:v};return y})}let N=(m)=>({kind:"invalid",message:m});async function D(m,y,T){let v=m.name;if(typeof v!=="string")return N("Invalid params: name must be a string");let R=t.get(v);if(R===void 0)return N(`Tool ${v} not found`);let S=m.arguments??{};if(!Q(S))return N("Invalid params: arguments must be an object");return{kind:"result",result:(await rt(e,R,S,y,e.client(T))).result}}function U(m,y,T,v){let R=new ReadableStream({start:(S)=>{let A=(d)=>{if(T.aborted)return;let k;try{k=le(d)}catch{k=le(_(m,ue("The tool returned a result that is not JSON.")))}try{S.enqueue(k),S.close()}catch{}};D(y,T,v).then((d)=>A(d.kind==="invalid"?{jsonrpc:"2.0",id:m,error:{code:-32602,message:d.message}}:_(m,d.result)),()=>A({jsonrpc:"2.0",id:m,error:{code:-32603,message:"Internal error"}}))}});return new Response(R,{status:200,headers:nt})}function C(m,y,T){let v=sn(y),R={jsonrpc:"2.0",id:m,result:{resultType:"complete",_meta:c({[Se]:m})}},S,A=new ReadableStream({start:(d)=>{if(d.enqueue(le({jsonrpc:"2.0",method:"notifications/subscriptions/acknowledged",params:{notifications:v,_meta:{[Se]:m}}})),Object.keys(v).length===0){d.enqueue(le(R)),d.close();return}let k={id:m,send:(w)=>{try{d.enqueue(le(w))}catch{r.delete(k)}},end:()=>{r.delete(k);try{d.enqueue(le(R)),d.close()}catch{}}};S=k,r.add(k),T.addEventListener("abort",()=>{r.delete(k);try{d.close()}catch{}})},cancel:()=>{if(S!==void 0)r.delete(S)}});return new Response(A,{status:200,headers:nt})}function G(m,y){if(Array.isArray(y))return q(400,null,-32600,"Bad Request: JSON-RPC batches are not supported by this endpoint");if(!Q(y)||y.jsonrpc!=="2.0")return q(400,null,-32600,"Bad Request: the request body is not a valid JSON-RPC message");let{method:T,id:v}=y;if(typeof T!=="string")return"result"in y||"error"in y?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 R=m.headers.get("mcp-protocol-version"),S=m.headers.get("mcp-method"),A=Q(y.params)?y.params:{},d=Q(A._meta)?A._meta:void 0,k=d!==void 0&&te in d,w=typeof d?.[te]==="string"?d[te]:void 0,j=R!==null&&R>=ie;if(v===void 0){if(w!==void 0&&R!==null&&R!==w)return Y(null,R,`the notification envelope names protocol version ${w} but the MCP-Protocol-Version header names ${R}`);if((k||j)&&S!==null&&S!==T)return Y(null,S,`the notification body names method ${T} but the Mcp-Method header names ${S}`);return"notification"}if(typeof v!=="string"&&typeof v!=="number")return q(400,null,-32600,"Bad Request: the request body is not a valid JSON-RPC message");let M=v;if(!k||T==="initialize"&&(w===void 0||w<ie)){if(T==="initialize"){if(j)return Y(M,R,"an initialize request (legacy handshake) was sent with a modern MCP-Protocol-Version header");let H=typeof A.protocolVersion==="string"?A.protocolVersion:void 0;return B(M,H)}if(j){let H=d===void 0?["_meta"]:[te];return q(400,M,-32602,`Invalid params: the MCP-Protocol-Version header names protocol revision ${R}, but the request is missing the required per-request envelope key(s): ${H.join(", ")}`,{envelope:{missing:H}})}return B(M,R??void 0)}let z=on(d);if(z!==void 0)return q(400,M,-32602,`Invalid _meta envelope for protocol revision ${ie}: ${z.key}: ${z.problem}`,{envelope:z});if(R!==null&&w!==void 0&&R!==w)return Y(M,R,`the body envelope names protocol version ${w} but the MCP-Protocol-Version header names ${R}`);if(S!==null&&S!==T)return Y(M,S,`the body names method ${T} but the Mcp-Method header names ${S}`);if(w!==ie)return B(M,w);if(R===null)return Y(M,"(missing)",`the body envelope names protocol version ${w} but the required MCP-Protocol-Version header is absent`);if(S===null)return Y(M,"(missing)",`the body names method ${T} but the required Mcp-Method header is absent`);if(T==="tools/call"&&typeof A.name==="string"){let H=A.name,W=m.headers.get("mcp-name");if(W===null)return Y(M,"(missing)",`the body carries params.name="${H}" but the required Mcp-Name header is absent`);let Z=rn(W);if(Z===void 0)return Y(M,W,"the Mcp-Name header carries an invalid Base64 sentinel value");if(Z!==H)return Y(M,W,`the body carries params.name="${H}" but the Mcp-Name header names "${Z}"`)}return{id:M,method:T,params:A}}function B(m,y){return y===void 0?q(400,m,Qe,"Unsupported protocol version: the request did not name a protocol version",{supported:[ie]}):q(400,m,Qe,`Unsupported protocol version: ${y}`,{supported:[ie],requested:y})}async function L(m,y){if(m.method.toUpperCase()!=="POST")return q(405,null,-32000,"Method not allowed.");if(!nn(m.headers.get("content-type")))return q(415,null,-32000,"Unsupported Media Type: Content-Type must be application/json");let T;try{T=JSON.parse(y.body??await m.text())}catch{return q(400,null,-32700,"Parse error: the request body is not valid JSON")}let v=G(m,T);if(v instanceof Response)return v;if(v==="notification")return new Response(null,{status:202});let{id:R,method:S,params:A}=v;switch(S){case"server/discover":{let d={supportedVersions:[ie],capabilities:{tools:{listChanged:!0}}};if(n.instructions!==void 0)d.instructions=n.instructions;return d.ttlMs=0,d.cacheScope="private",Oe(200,_(R,d,{[Xe]:i}))}case"tools/list":return Oe(200,_(R,{tools:I(),ttlMs:0,cacheScope:"private"}));case"tools/call":return U(R,A,m.signal,y.grant);case"subscriptions/listen":return C(R,A,m.signal);default:return q(404,R,-32601,"Method not found")}}return{handle:(m,y)=>L(m,y).catch(()=>q(500,null,-32603,"Internal server error")),toolsChanged(){if(a)return;a=!0,queueMicrotask(()=>{a=!1;for(let m of[...r])m.send({jsonrpc:"2.0",method:"notifications/tools/list_changed",params:{_meta:{[Se]:m.id}}})})},close(){for(let m of[...r])m.end()}}}var xe="tab-mcp.v1",ln=new Set(["start","used","locked","expired"]);function fe(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}var O=(e)=>typeof e==="string";function it(e){if(!fe(e)||!O(e.grantId)||!O(e.createdAt))return!1;let t=e.client;return fe(t)&&O(t.id)&&O(t.name)&&O(t.host)}function fn(e){if(!fe(e))return!1;return["maxMessageBytes","maxBodyBytes","requestTimeoutMs","idleTimeoutMs","heartbeatMs","keepAliveMs","maxConcurrentRequests"].every((t)=>typeof e[t]==="number")}function cn(e){return fe(e)&&Object.values(e).every(O)}function dt(e){let t;try{t=JSON.parse(e)}catch{return}if(!fe(t))return;switch(t.type){case"session":return O(t.sessionId)&&O(t.address)&&O(t.origin)&&O(t.expiresAt)&&fn(t.limits)&&Array.isArray(t.grants)&&t.grants.every(it)&&(t.appName===void 0||O(t.appName))&&(t.pairing===void 0||O(t.pairing))?t:void 0;case"ping":return typeof t.t==="number"?t:void 0;case"bye":return{type:"bye",reason:O(t.reason)?t.reason:""};case"http.request":return O(t.id)&&O(t.method)&&O(t.path)&&cn(t.headers)&&O(t.body)&&fe(t.grant)&&O(t.grant.grantId)&&O(t.grant.clientId)?t:void 0;case"http.cancel":return O(t.id)?t:void 0;case"pairing.code":{if(!O(t.code)||!O(t.expiresAt))return;let n={type:"pairing.code",code:t.code,expiresAt:t.expiresAt},o=t.reason;if(typeof o==="string"&&ln.has(o))n.reason=o;return n}case"grant.added":return it(t.grant)?t:void 0;case"grant.removed":return O(t.grantId)?{type:"grant.removed",grantId:t.grantId,reason:O(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 O(t.code)?t:void 0;default:return}}function pn(e){let t="",n=0,o=0;for(let s of e){n=n<<8|s,o+=8;while(o>=5)o-=5,t+="abcdefghijklmnopqrstuvwxyz234567"[n>>>o&31];n&=(1<<o)-1}if(o>0)t+="abcdefghijklmnopqrstuvwxyz234567"[n<<5-o&31];return t}async function mn(e,t=globalThis.crypto?.subtle??null){if(t===null)return;try{let n=await t.digest("SHA-256",new TextEncoder().encode(e));return pn(new Uint8Array(n))}catch{return}}function yn(e,t){if(t===void 0)return e;let n=new URL(e);return n.searchParams.set("a",t),n.href}function ft(e){return{tools:e.registry,confirm:(t)=>e.confirm(t),observe:{start:(t)=>e.toolCallStarted(t),end:(t)=>e.toolCallEnded(t)}}}function Yn(e,t,n,o){return ot(ft(e),t,n,o)}var gn=15000,at={1000:"closed",1008:"policy",1009:"too_large",4001:"expired",4002:"idle",4003:"heartbeat",4004:"shutdown",4005:"replaced",4008:"rate_limited",4009:"policy"},ut={replaced:"replaced",expired:"expired",idle:"idle",shutdown:"shutdown"};function de(e,t){return Object.assign(Error(e),{reason:t})}var hn=["content-type","cache-control"];function $n(){let e=globalThis.document?.title;return typeof e==="string"?e.slice(0,300):""}function bn(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 wn=new Set(["session","ping","bye","http.request","http.cancel","pairing.code","grant.added","grant.removed","identity.bound","error"]),ct=512,pt=6,mt=64,xn=ct+pt*mt;function Rn(e){let t=Math.floor((e-ct)/pt);return t>=mt?t:void 0}function*lt(e,t){let n=0;while(n<e.length){let o=Math.min(n+t,e.length),s=e.charCodeAt(o-1);if(o<e.length&&s>=55296&&s<=56319)o+=o-1>n?-1:1;yield e.slice(n,o),n=o}}var kn=1e4,In=1000;function Tn(e){let t,n=Number.NEGATIVE_INFINITY,o;try{if(e!==void 0&&typeof BroadcastChannel==="function")t=new BroadcastChannel(e),t.onmessage=(s)=>{if(s.data?.type!=="claimed")return;n=Date.now(),o?.()}}catch{t=void 0}return{claimed(){try{t?.postMessage({type:"claimed"})}catch{}},heard(){if(Date.now()-n<=kn)return Promise.resolve(!0);if(t===void 0)return Promise.resolve(!1);return new Promise((s)=>{let i=setTimeout(()=>s(!1),In);o=()=>{clearTimeout(i),s(!0)}})},close(){t?.close()}}}function Zn(e,t,n,o=!1){let s=new WebSocket(t,xe),i=new Map,r="opening",a,c=65536,_,I=0,N=Tn(e.tabs),D,U,C,G=new Promise((d,k)=>{U=d,C=k});G.catch(()=>{});let B=setTimeout(()=>{v(de("The relay did not answer in time.","network"))},gn),L=st({...ft(e),server:{...e.server,icons:e.server.icons??qe()},client:(d)=>e.clientFor(d)}),m=e.registry.onChange(()=>L.toolsChanged());function y(d){if(s.readyState!==WebSocket.OPEN)return!1;try{return s.send(JSON.stringify(d)),!0}catch{return!1}}function T(){if(I<=0)return;clearTimeout(_),_=setTimeout(()=>{a??="heartbeat",R(4003);try{s.close()}catch{}},I*2.5)}function v(d){if(r!=="opening")return;R(0),C(d);try{s.close()}catch{}}function R(d){if(r==="closed")return;let k=r==="ready";r="closed",clearTimeout(B),clearTimeout(_),m();for(let w of i.values())w.abort();if(i.clear(),L.close(),k){let w=a??at[d]??(d===1006?"network":"closed");if(C(de("The address was taken over again before its AI apps were disconnected.",w)),e.closed(w,d),w==="replaced"){N.heard().then((j)=>{N.close(),e.replaced({sibling:j})});return}}N.close()}async function S(d){let k=new AbortController;i.set(d.id,k);let w=()=>r==="ready"&&i.get(d.id)===k&&!k.signal.aborted;try{let j=new Request(`https://tab.invalid${d.path}`,{method:d.method,headers:d.headers,signal:k.signal}),M=await L.handle(j,{grant:d.grant,body:d.body});if(!w()){await M.body?.cancel().catch(()=>{});return}let z={};for(let V of hn){let F=M.headers.get(V);if(F!==null)z[V]=F}if(!(z["content-type"]??"").startsWith("text/event-stream")||M.body===null){let V=await M.text();if(!w())return;if(V.length<=c){y({type:"http.response",id:d.id,status:M.status,headers:z,body:V});return}y({type:"http.response.start",id:d.id,status:M.status,headers:z});for(let F of lt(V,c)){if(!w())break;y({type:"http.response.chunk",id:d.id,data:F})}if(w())y({type:"http.response.end",id:d.id});return}y({type:"http.response.start",id:d.id,status:M.status,headers:z});let W=M.body.getReader(),Z=new TextDecoder;k.signal.addEventListener("abort",()=>{W.cancel().catch(()=>{})});for(;;){let{done:V,value:F}=await W.read();if(V||!w())break;let ce=Z.decode(F,{stream:!0});for(let ne of lt(ce,c))y({type:"http.response.chunk",id:d.id,data:ne})}if(w())y({type:"http.response.end",id:d.id})}catch(j){if(w())e.error(j instanceof Error?j:Error(String(j))),y({type:"http.response",id:d.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(i.get(d.id)===k)i.delete(d.id)}}function A(d){if(r==="opening"){if(d.type==="session"){let k=Rn(d.limits.maxMessageBytes);if(k===void 0){v(de(`The relay's message limit (${d.limits.maxMessageBytes} bytes) is too small; tab-mcp needs at least ${xn}.`,"policy"));return}c=k,r="ready",clearTimeout(B),I=d.limits.heartbeatMs,T(),N.claimed();let w=e.sessionStarted(d);if(o&&d.grants.length>0){D={left:new Set(d.grants.map((j)=>j.grantId)),session:w},y({type:"grants.revokeAll"});return}U(w)}else if(d.type==="error")v(de(`The relay refused the connection: ${d.message||d.code}`,d.code==="rate_limited"?"rate_limited":"policy"));else if(d.type==="bye")v(de(`The relay ended the connection: ${d.reason}`,ut[d.reason]??"closed"));return}if(r!=="ready")return;switch(d.type){case"ping":T(),y({type:"pong",t:d.t});return;case"http.request":S(d);return;case"http.cancel":i.get(d.id)?.abort(),i.delete(d.id);return;case"pairing.code":e.pairingCode(d.reason===void 0?{code:d.code,expiresAt:d.expiresAt}:{code:d.code,expiresAt:d.expiresAt,reason:d.reason});return;case"grant.added":e.grantAdded(d.grant);return;case"grant.removed":if(e.grantRemoved(d.grantId),D?.left.delete(d.grantId),D?.left.size===0)U(D.session);return;case"identity.bound":e.identityResult(!0,d.round);return;case"bye":if(a=ut[d.reason]??"closed",a==="replaced")R(4005);return;case"error":if(d.code==="identity_refused"){e.identityResult(!1,typeof d.round==="number"?d.round:void 0,d.message);return}e.error(Error(`Relay error ${d.code}: ${d.message}`));return;case"session":return}}return s.addEventListener("open",()=>{if(s.protocol!==""&&s.protocol!==xe){v(de(`The relay speaks ${s.protocol}, not ${xe}.`,"policy"));return}let d={type:"hello",library:e.library,page:{title:$n()},secret:n};if(e.appName!==void 0)d.app={name:e.appName};if(o)d.revokeAll=!0;y(d)}),s.addEventListener("message",(d)=>{if(typeof d.data!=="string")return;let k=dt(d.data);if(k!==void 0){if(r==="ready")T();A(k);return}let w=bn(d.data);if(w?.id!==void 0)y(wn.has(w.type)?{type:"error",code:"bad_message",message:`malformed ${w.type}`,id:w.id}:{type:"error",code:"unknown_type",message:`unknown type ${w.type}`,id:w.id})}),s.addEventListener("close",(d)=>{if(r==="opening"){R(d.code);let k=d.code===1006||d.code===1002;C(de(k?"Could not connect to the relay (refused, unreachable, or this page's origin is not allowed).":`The relay closed the connection (${d.code}${d.reason?`: ${d.reason}`:""}).`,at[d.code]??(k?"network":"closed")));return}R(d.code)}),{ready:G,send:y,close(d){if(r==="closed")return;if(r==="opening"){v(new DOMException("The connection was cancelled","AbortError"));return}a=d,y({type:"bye",reason:"user"}),R(1000);try{s.close(1000,"bye")}catch{}}}}export{xn as MIN_MESSAGE_BYTES,In as SIBLING_GRACE_MS,kn as SIBLING_WINDOW_MS,mn as addressIdOf,Yn as callFromWebMcp,Rn as chunkSize,en as compileRegistry,Zn as openConnection,lt as pieces,yn as withAddress};
|
|
10
|
+
|
|
11
|
+
//# debugId=FFAA4257DB4B9ACC64756E2164756E21
|
|
12
|
+
//# sourceMappingURL=connection-jk28y9f6.min.js.map
|