@ractive-ch/tab-mcp-client 0.5.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -10
- package/cdn/connection-nygehv52.min.js +11 -0
- package/cdn/{connection-by0y4k0a.min.js.map → connection-nygehv52.min.js.map} +5 -6
- package/cdn/tab-mcp-client.min.js +3 -3
- package/cdn/tab-mcp-client.min.js.map +5 -5
- package/cdn/ui-yknfss9n.min.js +4 -0
- package/cdn/ui-yknfss9n.min.js.map +10 -0
- package/{connection-p2kxtegw.js → connection-p94fg1r9.js} +88 -25
- package/connection-p94fg1r9.js.map +13 -0
- package/connection.d.ts +2 -0
- package/index.js +65 -28
- package/index.js.map +5 -5
- package/mcp.d.ts +23 -1
- package/package.json +1 -1
- package/react.js +13 -6
- package/react.js.map +3 -3
- package/registry.d.ts +9 -0
- package/tab-mcp.d.ts +5 -2
- package/types.d.ts +7 -4
- package/{ui-rtahm62h.js → ui-htav9g19.js} +50 -18
- package/ui-htav9g19.js.map +10 -0
- package/ui.d.ts +5 -3
- package/version.d.ts +1 -1
- package/cdn/connection-by0y4k0a.min.js +0 -10
- package/cdn/ui-xh7shp5z.min.js +0 -4
- package/cdn/ui-xh7shp5z.min.js.map +0 -10
- package/connection-p2kxtegw.js.map +0 -13
- package/ui-rtahm62h.js.map +0 -10
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ relay. The page connects to the relay and gets an address. The user adds that ad
|
|
|
6
6
|
their AI app and types a pairing code from the page; the AI app then calls the page's
|
|
7
7
|
tools while the tab stays open. Nothing is installed on the user's computer.
|
|
8
8
|
|
|
9
|
-
**Status: 0.
|
|
9
|
+
**Status: 0.6.0.** Until 1.0, a new minor version can still change the API. Which AI apps
|
|
10
10
|
work is listed in [compatibility](https://github.com/ractive/tab-mcp/blob/main/docs/compatibility.md).
|
|
11
11
|
|
|
12
12
|
## You need a relay
|
|
@@ -22,7 +22,7 @@ docker run --rm -p 8080:8080 \
|
|
|
22
22
|
-e TAB_MCP_PUBLIC_URL=http://localhost:8080 \
|
|
23
23
|
-e TAB_MCP_ALLOWED_ORIGINS=http://localhost:3000 \
|
|
24
24
|
-e TAB_MCP_STORE=memory \
|
|
25
|
-
ractive/tab-mcp:0.
|
|
25
|
+
ractive/tab-mcp:0.4.0
|
|
26
26
|
```
|
|
27
27
|
|
|
28
28
|
For production, see
|
|
@@ -38,7 +38,7 @@ Or without a bundler, from a CDN as an ES module:
|
|
|
38
38
|
|
|
39
39
|
```html
|
|
40
40
|
<script type="module">
|
|
41
|
-
import { TabMcp } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.
|
|
41
|
+
import { TabMcp } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.6.0/cdn/tab-mcp-client.min.js";
|
|
42
42
|
</script>
|
|
43
43
|
```
|
|
44
44
|
|
|
@@ -78,7 +78,11 @@ Importing the library loads only a small core; `connect()` loads the rest.
|
|
|
78
78
|
|
|
79
79
|
- `name` (1-128 characters of `A-Z a-z 0-9 _ - .`), `title`, `description` (not empty);
|
|
80
80
|
- `inputSchema`: a JSON Schema with `"type": "object"`. Arguments are checked against it
|
|
81
|
-
before `execute` runs
|
|
81
|
+
before `execute` runs. `registerTool` rejects a schema the validator cannot use (a
|
|
82
|
+
pattern that is not a regular expression, a `$ref` that does not resolve). The
|
|
83
|
+
validator itself is loaded by `connect()`: from then on it checks each schema at
|
|
84
|
+
registration too, and a tool registered earlier whose schema it refuses (for example a
|
|
85
|
+
`$ref` next to a nested `$id`) is unregistered, with the reason in the event `error`;
|
|
82
86
|
- `execute(input, { signal, client })`: runs the tool. `signal` aborts when the AI app
|
|
83
87
|
gives up; `client` names the caller (`id`, verified `host`, declared `name`). Return a
|
|
84
88
|
string (one text block), an MCP result with a `content` array (passed through), or any
|
|
@@ -96,15 +100,28 @@ Mark tools that change or delete something with `consequentialHint: true`. The p
|
|
|
96
100
|
asks the user before every call ("Allow", "Always allow" or "Don't allow"), showing the AI
|
|
97
101
|
app and the arguments. "Always allow" lets that tool run without asking for that AI app
|
|
98
102
|
until the page is reloaded or the app is disconnected. A refusal reaches the AI app as an
|
|
99
|
-
error result
|
|
100
|
-
|
|
103
|
+
error result, and so does a call whose tool was removed while the user was asked.
|
|
104
|
+
|
|
105
|
+
Tools are called while the user is in the AI app, so the dialog often opens in a tab in
|
|
106
|
+
the background. "Allow" and "Always allow" can be clicked only once the page has been
|
|
107
|
+
visible and focused for `confirmDelayMs` (750 ms) with the dialog open; leaving the page
|
|
108
|
+
disables them and coming back starts the wait again, so the click that brings the page
|
|
109
|
+
forward cannot approve. Characters that are invisible or change the text direction (such
|
|
110
|
+
as U+202E) are shown in the arguments as `\uXXXX`, so the AI app cannot make them look
|
|
111
|
+
like something else; the tool gets the arguments unchanged.
|
|
112
|
+
|
|
113
|
+
Pass `onConfirm` to ask in your own UI (it is asked every time; remember answers there if
|
|
114
|
+
you want to). Show the verified `client.host` next to the name the AI app declares, as the
|
|
115
|
+
library's dialog does, since anyone can declare any name:
|
|
101
116
|
|
|
102
117
|
```ts
|
|
103
118
|
const mcp = new TabMcp({
|
|
104
119
|
relay: "https://relay.example",
|
|
105
120
|
server: { name: "calculator", version: "1.0.0" },
|
|
106
|
-
onConfirm: ({ tool, arguments: args, client, signal }) =>
|
|
107
|
-
|
|
121
|
+
onConfirm: ({ tool, arguments: args, client, signal }) => {
|
|
122
|
+
const app = client.name ? `${client.name} (${client.host})` : client.host;
|
|
123
|
+
return myDialog.ask(`${app} wants to run ${tool.name}.`, args, signal);
|
|
124
|
+
},
|
|
108
125
|
});
|
|
109
126
|
```
|
|
110
127
|
|
|
@@ -127,7 +144,9 @@ handles only some calls itself.
|
|
|
127
144
|
Until an app connects, the dialog offers no prominent button under the code: only a small
|
|
128
145
|
"Close" at the bottom (and Escape). Closing it stops the code (`stopPairing()`); the page
|
|
129
146
|
stays connected and the address stays the same, so calling `showConnectDialog()` again
|
|
130
|
-
shows the same address with a new code.
|
|
147
|
+
shows the same address with a new code. While the dialog is open, calling it again (a
|
|
148
|
+
double click) opens no second one; the call resolves when that one closes. A call for another
|
|
149
|
+
`document` (an iframe's, say) while it is open rejects with an `InvalidStateError`.
|
|
131
150
|
|
|
132
151
|
The address stays the same across visits: the library keeps a secret per relay and page
|
|
133
152
|
in `localStorage`, under `tab-mcp:secret:<relay origin>:<server.name>`, so two pages of one
|
|
@@ -187,7 +206,7 @@ await mcp.refreshIdentity();
|
|
|
187
206
|
|
|
188
207
|
The library asks the function after every connect. `identity` (`none`, `pending`,
|
|
189
208
|
`bound`, `refused`, with the reason in `identityMessage`) and the event
|
|
190
|
-
`identitychange` tell you whether the relay accepted it;
|
|
209
|
+
`identitychange` tell you whether the relay accepted it; when the function or the relay does not answer within `identityTimeoutMs` (15 s, counted from when the function is asked), it goes back to `none`. An AI app signed in as someone else gets "This AI tool is logged in as someone other
|
|
191
210
|
than the page."
|
|
192
211
|
|
|
193
212
|
### Your own UI
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
function oe(e,t){let o=typeof e;if(o!==typeof t)return!1;if(Array.isArray(e)){if(!Array.isArray(t))return!1;let s=e.length;if(s!==t.length)return!1;for(let i=0;i<s;i++)if(!oe(e[i],t[i]))return!1;return!0}if(o==="object"){if(!e||!t)return e===t;let s=Object.keys(e),i=Object.keys(t);if(s.length!==i.length)return!1;for(let n of s)if(!oe(e[n],t[n]))return!1;return!0}return e===t}function H(e){return encodeURI(st(e))}function st(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}var it={prefixItems:!0,items:!0,allOf:!0,anyOf:!0,oneOf:!0},dt={$defs:!0,definitions:!0,properties:!0,patternProperties:!0,dependentSchemas:!0},at={id:!0,$id:!0,$ref:!0,$schema:!0,$anchor:!0,$vocabulary:!0,$comment:!0,default:!0,enum:!0,const:!0,required:!0,type:!0,maximum:!0,minimum:!0,exclusiveMaximum:!0,exclusiveMinimum:!0,multipleOf:!0,maxLength:!0,minLength:!0,pattern:!0,format:!0,maxItems:!0,minItems:!0,uniqueItems:!0,maxProperties:!0,minProperties:!0},ut=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 X(e,t=Object.create(null),o=ut,s=""){if(e&&typeof e==="object"&&!Array.isArray(e)){let d=e.$id||e.id;if(d){let n=new URL(d,o.href);if(n.hash.length>1)t[n.href]=e;else if(n.hash="",s==="")o=n;else X(e,t,o)}}else if(e!==!0&&e!==!1)return t;let i=o.href+(s?"#"+s:"");if(t[i]!==void 0)throw Error(`Duplicate schema URI "${i}".`);if(t[i]=e,e===!0||e===!1)return t;if(e.__absolute_uri__===void 0)Object.defineProperty(e,"__absolute_uri__",{enumerable:!1,value:i});if(e.$ref&&e.__absolute_ref__===void 0){let d=new URL(e.$ref,o.href);d.hash=d.hash,Object.defineProperty(e,"__absolute_ref__",{enumerable:!1,value:d.href})}if(e.$recursiveRef&&e.__absolute_recursive_ref__===void 0){let d=new URL(e.$recursiveRef,o.href);d.hash=d.hash,Object.defineProperty(e,"__absolute_recursive_ref__",{enumerable:!1,value:d.href})}if(e.$anchor){let d=new URL("#"+e.$anchor,o.href);t[d.href]=e}for(let d in e){if(at[d])continue;let n=`${s}/${H(d)}`,l=e[d];if(Array.isArray(l)){if(it[d]){let T=l.length;for(let q=0;q<T;q++)X(l[q],t,o,`${n}/${q}`)}}else if(dt[d])for(let T in l)X(l[T],t,o,`${n}/${H(T)}`);else X(l,t,o,n)}return t}var lt=/^(\d\d\d\d)-(\d\d)-(\d\d)$/,ft=[0,31,28,31,30,31,30,31,31,30,31,30,31],ct=/^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|[+-]\d\d(?::?\d\d)?)?$/i,pt=/^(?=.{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,yt=/^(?:[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,mt=/^(?:(?:[^\x00-\x20"'<>%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i,gt=/^(?:(?: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,ht=/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i,$t=/^(?:\/(?:[^~/]|~0|~1)*)*$/,bt=/^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i,wt=/^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/,Rt=(e)=>{if(e[0]==='"')return!1;let[t,o,...s]=e.split("@");if(!t||!o||s.length!==0||t.length>64||o.length>253)return!1;if(t[0]==="."||t.endsWith(".")||t.includes(".."))return!1;if(!/^[a-z0-9.-]+$/i.test(o)||!/^[a-z0-9.!#$%&'*+/=?^_`{|}~-]+$/i.test(t))return!1;return o.split(".").every((i)=>/^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/i.test(i))},kt=/^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,xt=/^((([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,Tt=(e)=>e.length>1&&e.length<80&&(/^P\d+([.,]\d+)?W$/.test(e)||/^P[\dYMDTHS]*(\d[.,]\d+)?[YMDHS]$/.test(e)&&/^P([.,\d]+Y)?([.,\d]+M)?([.,\d]+D)?(T([.,\d]+H)?([.,\d]+M)?([.,\d]+S)?)?$/.test(e));function B(e){return e.test.bind(e)}var Te={date:Ce,time:Ne.bind(void 0,!1),"date-time":vt,duration:Tt,uri:Ot,"uri-reference":B(yt),"uri-template":B(mt),url:B(gt),email:Rt,hostname:B(pt),ipv4:B(kt),ipv6:B(xt),regex:At,uuid:B(ht),"json-pointer":B($t),"json-pointer-uri-fragment":B(bt),"relative-json-pointer":B(wt)};function It(e){return e%4===0&&(e%100!==0||e%400===0)}function Ce(e){let t=e.match(lt);if(!t)return!1;let o=+t[1],s=+t[2],i=+t[3];return s>=1&&s<=12&&i>=1&&i<=(s==2&&It(o)?29:ft[s])}function Ne(e,t){let o=t.match(ct);if(!o)return!1;let s=+o[1],i=+o[2],d=+o[3],n=!!o[5];return(s<=23&&i<=59&&d<=59||s==23&&i==59&&d==60)&&(!e||n)}var _t=/t|\s/i;function vt(e){let t=e.split(_t);return t.length==2&&Ce(t[0])&&Ne(!0,t[1])}var Mt=/\/|:/,St=/^(?:[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 Ot(e){return Mt.test(e)&&St.test(e)}var Et=/[^\\]\\Z/;function At(e){if(Et.test(e))return!1;try{return new RegExp(e,"u"),!0}catch(t){return!1}}function qe(e){let t=0,o=e.length,s=0,i;while(s<o)if(t++,i=e.charCodeAt(s++),i>=55296&&i<=56319&&s<o){if(i=e.charCodeAt(s),(i&64512)==56320)s++}return t}function O(e,t,o="2019-09",s=X(t),i=!0,d=null,n="#",l="#",T=Object.create(null)){if(t===!0)return{valid:!0,errors:[]};if(t===!1)return{valid:!1,errors:[{instanceLocation:n,keyword:"false",keywordLocation:n,error:"False boolean schema."}]};let q=typeof e,_;switch(q){case"boolean":case"number":case"string":_=q;break;case"object":if(e===null)_="null";else if(Array.isArray(e))_="array";else _="object";break;default:throw Error(`Instances of "${q}" type are not supported.`)}let{$ref:U,$recursiveRef:ne,$recursiveAnchor:G,type:C,const:K,enum:E,required:Z,not:u,anyOf:m,allOf:x,oneOf:I,if:r,then:y,else:b,format:k,properties:v,patternProperties:M,additionalProperties:J,unevaluatedProperties:P,minProperties:V,maxProperties:A,propertyNames:j,dependentRequired:W,dependentSchemas:ae,dependencies:we,prefixItems:Re,items:ue,additionalItems:Me,unevaluatedItems:Se,contains:Oe,minContains:Y,maxContains:ce,minItems:ke,maxItems:xe,uniqueItems:nt,minimum:L,maximum:ee,exclusiveMinimum:le,exclusiveMaximum:fe,multipleOf:pe,minLength:ye,maxLength:me,pattern:Ee,__absolute_ref__:ge,__absolute_recursive_ref__:ot}=t,f=[];if(G===!0&&d===null)d=t;if(ne==="#"){let g=d===null?s[ot]:d,p=`${l}/$recursiveRef`,R=O(e,d===null?t:d,o,s,i,g,n,p,T);if(!R.valid)f.push({instanceLocation:n,keyword:"$recursiveRef",keywordLocation:p,error:"A subschema had errors."},...R.errors)}if(U!==void 0){let p=s[ge||U];if(p===void 0){let a=`Unresolved $ref "${U}".`;if(ge&&ge!==U)a+=` Absolute URI "${ge}".`;throw a+=`
|
|
2
|
+
Known schemas:
|
|
3
|
+
- ${Object.keys(s).join(`
|
|
4
|
+
- `)}`,Error(a)}let R=`${l}/$ref`,c=O(e,p,o,s,i,d,n,R,T);if(!c.valid)f.push({instanceLocation:n,keyword:"$ref",keywordLocation:R,error:"A subschema had errors."},...c.errors);if(o==="4"||o==="7")return{valid:f.length===0,errors:f}}if(Array.isArray(C)){let g=C.length,p=!1;for(let R=0;R<g;R++)if(_===C[R]||C[R]==="integer"&&_==="number"&&e%1===0&&e===e){p=!0;break}if(!p)f.push({instanceLocation:n,keyword:"type",keywordLocation:`${l}/type`,error:`Instance type "${_}" is invalid. Expected "${C.join('", "')}".`})}else if(C==="integer"){if(_!=="number"||e%1||e!==e)f.push({instanceLocation:n,keyword:"type",keywordLocation:`${l}/type`,error:`Instance type "${_}" is invalid. Expected "${C}".`})}else if(C!==void 0&&_!==C)f.push({instanceLocation:n,keyword:"type",keywordLocation:`${l}/type`,error:`Instance type "${_}" is invalid. Expected "${C}".`});if(K!==void 0){if(_==="object"||_==="array"){if(!oe(e,K))f.push({instanceLocation:n,keyword:"const",keywordLocation:`${l}/const`,error:`Instance does not match ${JSON.stringify(K)}.`})}else if(e!==K)f.push({instanceLocation:n,keyword:"const",keywordLocation:`${l}/const`,error:`Instance does not match ${JSON.stringify(K)}.`})}if(E!==void 0){if(_==="object"||_==="array"){if(!E.some((g)=>oe(e,g)))f.push({instanceLocation:n,keyword:"enum",keywordLocation:`${l}/enum`,error:`Instance does not match any of ${JSON.stringify(E)}.`})}else if(!E.some((g)=>e===g))f.push({instanceLocation:n,keyword:"enum",keywordLocation:`${l}/enum`,error:`Instance does not match any of ${JSON.stringify(E)}.`})}if(u!==void 0){let g=`${l}/not`;if(O(e,u,o,s,i,d,n,g).valid)f.push({instanceLocation:n,keyword:"not",keywordLocation:g,error:'Instance matched "not" schema.'})}let he=[];if(m!==void 0){let g=`${l}/anyOf`,p=f.length,R=!1;for(let c=0;c<m.length;c++){let a=m[c],w=Object.create(T),h=O(e,a,o,s,i,G===!0?d:null,n,`${g}/${c}`,w);if(f.push(...h.errors),R=R||h.valid,h.valid)he.push(w)}if(R)f.length=p;else f.splice(p,0,{instanceLocation:n,keyword:"anyOf",keywordLocation:g,error:"Instance does not match any subschemas."})}if(x!==void 0){let g=`${l}/allOf`,p=f.length,R=!0;for(let c=0;c<x.length;c++){let a=x[c],w=Object.create(T),h=O(e,a,o,s,i,G===!0?d:null,n,`${g}/${c}`,w);if(f.push(...h.errors),R=R&&h.valid,h.valid)he.push(w)}if(R)f.length=p;else f.splice(p,0,{instanceLocation:n,keyword:"allOf",keywordLocation:g,error:"Instance does not match every subschema."})}if(I!==void 0){let g=`${l}/oneOf`,p=f.length,R=I.filter((c,a)=>{let w=Object.create(T),h=O(e,c,o,s,i,G===!0?d:null,n,`${g}/${a}`,w);if(f.push(...h.errors),h.valid)he.push(w);return h.valid}).length;if(R===1)f.length=p;else f.splice(p,0,{instanceLocation:n,keyword:"oneOf",keywordLocation:g,error:`Instance does not match exactly one subschema (${R} matches).`})}if(_==="object"||_==="array")Object.assign(T,...he);if(r!==void 0){let g=`${l}/if`;if(O(e,r,o,s,i,d,n,g,T).valid){if(y!==void 0){let R=O(e,y,o,s,i,d,n,`${l}/then`,T);if(!R.valid)f.push({instanceLocation:n,keyword:"if",keywordLocation:g,error:'Instance does not match "then" schema.'},...R.errors)}}else if(b!==void 0){let R=O(e,b,o,s,i,d,n,`${l}/else`,T);if(!R.valid)f.push({instanceLocation:n,keyword:"if",keywordLocation:g,error:'Instance does not match "else" schema.'},...R.errors)}}if(_==="object"){if(Z!==void 0){for(let c of Z)if(!(c in e))f.push({instanceLocation:n,keyword:"required",keywordLocation:`${l}/required`,error:`Instance does not have required property "${c}".`})}let g=Object.keys(e);if(V!==void 0&&g.length<V)f.push({instanceLocation:n,keyword:"minProperties",keywordLocation:`${l}/minProperties`,error:`Instance does not have at least ${V} properties.`});if(A!==void 0&&g.length>A)f.push({instanceLocation:n,keyword:"maxProperties",keywordLocation:`${l}/maxProperties`,error:`Instance does not have at least ${A} properties.`});if(j!==void 0){let c=`${l}/propertyNames`;for(let a in e){let w=`${n}/${H(a)}`,h=O(a,j,o,s,i,d,w,c);if(!h.valid)f.push({instanceLocation:n,keyword:"propertyNames",keywordLocation:c,error:`Property name "${a}" does not match schema.`},...h.errors)}}if(W!==void 0){let c=`${l}/dependantRequired`;for(let a in W)if(a in e){let w=W[a];for(let h of w)if(!(h in e))f.push({instanceLocation:n,keyword:"dependentRequired",keywordLocation:c,error:`Instance has "${a}" but does not have "${h}".`})}}if(ae!==void 0)for(let c in ae){let a=`${l}/dependentSchemas`;if(c in e){let w=O(e,ae[c],o,s,i,d,n,`${a}/${H(c)}`,T);if(!w.valid)f.push({instanceLocation:n,keyword:"dependentSchemas",keywordLocation:a,error:`Instance has "${c}" but does not match dependant schema.`},...w.errors)}}if(we!==void 0){let c=`${l}/dependencies`;for(let a in we)if(a in e){let w=we[a];if(Array.isArray(w)){for(let h of w)if(!(h in e))f.push({instanceLocation:n,keyword:"dependencies",keywordLocation:c,error:`Instance has "${a}" but does not have "${h}".`})}else{let h=O(e,w,o,s,i,d,n,`${c}/${H(a)}`);if(!h.valid)f.push({instanceLocation:n,keyword:"dependencies",keywordLocation:c,error:`Instance has "${a}" but does not match dependant schema.`},...h.errors)}}}let p=Object.create(null),R=!1;if(v!==void 0){let c=`${l}/properties`;for(let a in v){if(!(a in e))continue;let w=`${n}/${H(a)}`,h=O(e[a],v[a],o,s,i,d,w,`${c}/${H(a)}`);if(h.valid)T[a]=p[a]=!0;else if(R=i,f.push({instanceLocation:n,keyword:"properties",keywordLocation:c,error:`Property "${a}" does not match schema.`},...h.errors),R)break}}if(!R&&M!==void 0){let c=`${l}/patternProperties`;for(let a in M){let w=new RegExp(a,"u"),h=M[a];for(let z in e){if(!w.test(z))continue;let Ae=`${n}/${H(z)}`,Pe=O(e[z],h,o,s,i,d,Ae,`${c}/${H(a)}`);if(Pe.valid)T[z]=p[z]=!0;else R=i,f.push({instanceLocation:n,keyword:"patternProperties",keywordLocation:c,error:`Property "${z}" matches pattern "${a}" but does not match associated schema.`},...Pe.errors)}}}if(!R&&J!==void 0){let c=`${l}/additionalProperties`;for(let a in e){if(p[a])continue;let w=`${n}/${H(a)}`,h=O(e[a],J,o,s,i,d,w,c);if(h.valid)T[a]=!0;else R=i,f.push({instanceLocation:n,keyword:"additionalProperties",keywordLocation:c,error:`Property "${a}" does not match additional properties schema.`},...h.errors)}}else if(!R&&P!==void 0){let c=`${l}/unevaluatedProperties`;for(let a in e)if(!T[a]){let w=`${n}/${H(a)}`,h=O(e[a],P,o,s,i,d,w,c);if(h.valid)T[a]=!0;else f.push({instanceLocation:n,keyword:"unevaluatedProperties",keywordLocation:c,error:`Property "${a}" does not match unevaluated properties schema.`},...h.errors)}}}else if(_==="array"){if(xe!==void 0&&e.length>xe)f.push({instanceLocation:n,keyword:"maxItems",keywordLocation:`${l}/maxItems`,error:`Array has too many items (${e.length} > ${xe}).`});if(ke!==void 0&&e.length<ke)f.push({instanceLocation:n,keyword:"minItems",keywordLocation:`${l}/minItems`,error:`Array has too few items (${e.length} < ${ke}).`});let g=e.length,p=0,R=!1;if(Re!==void 0){let c=`${l}/prefixItems`,a=Math.min(Re.length,g);for(;p<a;p++){let w=O(e[p],Re[p],o,s,i,d,`${n}/${p}`,`${c}/${p}`);if(T[p]=!0,!w.valid){if(R=i,f.push({instanceLocation:n,keyword:"prefixItems",keywordLocation:c,error:"Items did not match schema."},...w.errors),R)break}}}if(ue!==void 0){let c=`${l}/items`;if(Array.isArray(ue)){let a=Math.min(ue.length,g);for(;p<a;p++){let w=O(e[p],ue[p],o,s,i,d,`${n}/${p}`,`${c}/${p}`);if(T[p]=!0,!w.valid){if(R=i,f.push({instanceLocation:n,keyword:"items",keywordLocation:c,error:"Items did not match schema."},...w.errors),R)break}}}else for(;p<g;p++){let a=O(e[p],ue,o,s,i,d,`${n}/${p}`,c);if(T[p]=!0,!a.valid){if(R=i,f.push({instanceLocation:n,keyword:"items",keywordLocation:c,error:"Items did not match schema."},...a.errors),R)break}}if(!R&&Me!==void 0){let a=`${l}/additionalItems`;for(;p<g;p++){let w=O(e[p],Me,o,s,i,d,`${n}/${p}`,a);if(T[p]=!0,!w.valid)R=i,f.push({instanceLocation:n,keyword:"additionalItems",keywordLocation:a,error:"Items did not match additional items schema."},...w.errors)}}}if(Oe!==void 0)if(g===0&&Y===void 0)f.push({instanceLocation:n,keyword:"contains",keywordLocation:`${l}/contains`,error:"Array is empty. It must contain at least one item matching the schema."});else if(Y!==void 0&&g<Y)f.push({instanceLocation:n,keyword:"minContains",keywordLocation:`${l}/minContains`,error:`Array has less items (${g}) than minContains (${Y}).`});else{let c=`${l}/contains`,a=f.length,w=0;for(let h=0;h<g;h++){let z=O(e[h],Oe,o,s,i,d,`${n}/${h}`,c);if(z.valid)T[h]=!0,w++;else f.push(...z.errors)}if(w>=(Y||0))f.length=a;if(Y===void 0&&ce===void 0&&w===0)f.splice(a,0,{instanceLocation:n,keyword:"contains",keywordLocation:c,error:"Array does not contain item matching schema."});else if(Y!==void 0&&w<Y)f.push({instanceLocation:n,keyword:"minContains",keywordLocation:`${l}/minContains`,error:`Array must contain at least ${Y} items matching schema. Only ${w} items were found.`});else if(ce!==void 0&&w>ce)f.push({instanceLocation:n,keyword:"maxContains",keywordLocation:`${l}/maxContains`,error:`Array may contain at most ${ce} items matching schema. ${w} items were found.`})}if(!R&&Se!==void 0){let c=`${l}/unevaluatedItems`;for(p;p<g;p++){if(T[p])continue;let a=O(e[p],Se,o,s,i,d,`${n}/${p}`,c);if(T[p]=!0,!a.valid)f.push({instanceLocation:n,keyword:"unevaluatedItems",keywordLocation:c,error:"Items did not match unevaluated items schema."},...a.errors)}}if(nt)for(let c=0;c<g;c++){let a=e[c],w=typeof a==="object"&&a!==null;for(let h=0;h<g;h++){if(c===h)continue;let z=e[h];if(a===z||w&&(typeof z==="object"&&z!==null)&&oe(a,z))f.push({instanceLocation:n,keyword:"uniqueItems",keywordLocation:`${l}/uniqueItems`,error:`Duplicate items at indexes ${c} and ${h}.`}),c=Number.MAX_SAFE_INTEGER,h=Number.MAX_SAFE_INTEGER}}}else if(_==="number"){if(o==="4"){if(L!==void 0&&(le===!0&&e<=L||e<L))f.push({instanceLocation:n,keyword:"minimum",keywordLocation:`${l}/minimum`,error:`${e} is less than ${le?"or equal to ":""} ${L}.`});if(ee!==void 0&&(fe===!0&&e>=ee||e>ee))f.push({instanceLocation:n,keyword:"maximum",keywordLocation:`${l}/maximum`,error:`${e} is greater than ${fe?"or equal to ":""} ${ee}.`})}else{if(L!==void 0&&e<L)f.push({instanceLocation:n,keyword:"minimum",keywordLocation:`${l}/minimum`,error:`${e} is less than ${L}.`});if(ee!==void 0&&e>ee)f.push({instanceLocation:n,keyword:"maximum",keywordLocation:`${l}/maximum`,error:`${e} is greater than ${ee}.`});if(le!==void 0&&e<=le)f.push({instanceLocation:n,keyword:"exclusiveMinimum",keywordLocation:`${l}/exclusiveMinimum`,error:`${e} is less than ${le}.`});if(fe!==void 0&&e>=fe)f.push({instanceLocation:n,keyword:"exclusiveMaximum",keywordLocation:`${l}/exclusiveMaximum`,error:`${e} is greater than or equal to ${fe}.`})}if(pe!==void 0){let g=e%pe;if(Math.abs(0-g)>=0.00000011920929&&Math.abs(pe-g)>=0.00000011920929)f.push({instanceLocation:n,keyword:"multipleOf",keywordLocation:`${l}/multipleOf`,error:`${e} is not a multiple of ${pe}.`})}}else if(_==="string"){let g=ye===void 0&&me===void 0?0:qe(e);if(ye!==void 0&&g<ye)f.push({instanceLocation:n,keyword:"minLength",keywordLocation:`${l}/minLength`,error:`String is too short (${g} < ${ye}).`});if(me!==void 0&&g>me)f.push({instanceLocation:n,keyword:"maxLength",keywordLocation:`${l}/maxLength`,error:`String is too long (${g} > ${me}).`});if(Ee!==void 0&&!new RegExp(Ee,"u").test(e))f.push({instanceLocation:n,keyword:"pattern",keywordLocation:`${l}/pattern`,error:"String does not match pattern."});if(k!==void 0&&Te[k]&&!Te[k](e))f.push({instanceLocation:n,keyword:"format",keywordLocation:`${l}/format`,error:`String does not match format "${k}".`})}return{valid:f.length===0,errors:f}}var ze="ch.ractive.tab-mcp/annotations",Pt=["readOnlyHint","untrustedContentHint","consequentialHint","debugging"],Ct=["destructiveHint","idempotentHint","openWorldHint"];function He(e){let t={};if(e.readOnlyHint===!0)t.readOnlyHint=!0,t.destructiveHint=!1;else if(e.readOnlyHint===!1)t.readOnlyHint=!1;if(e.consequentialHint===!0)t.destructiveHint=!0;if(e.untrustedContentHint===!0)t.openWorldHint=!0;for(let i of Ct){let d=e[i];if(d!==void 0)t[i]=d}let o={};for(let i of Pt){let d=e[i];if(d!==void 0)o[i]=d}let s={};if(Object.keys(t).length>0)s.annotations=t;if(Object.keys(o).length>0)s.meta=o;return s}function F(e){return{content:[{type:"text",text:e}],isError:!0}}function je(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function Je(e){if(typeof e==="string")return{content:[{type:"text",text:e}]};if(e===void 0)return{content:[]};if(je(e)&&Array.isArray(e.content))return e;let t;try{t=JSON.stringify(e)}catch{}if(t===void 0)return F("The tool returned a value that is not JSON.");let o={content:[{type:"text",text:t}]};if(je(e))o.structuredContent=e;return o}function Ue(e){let t=e instanceof Error?e.message:String(e);return F(t||"The tool failed.")}var te="2026-07-28",Q="io.modelcontextprotocol/protocolVersion",$e="io.modelcontextprotocol/clientCapabilities",Ve="io.modelcontextprotocol/clientInfo",Nt="io.modelcontextprotocol/serverInfo",Ie="io.modelcontextprotocol/subscriptionId",qt=-32020,Be=-32022,jt=0,De=new WeakMap;function _e(e){let t=De.get(e);if(t!==void 0)return t;let o=e.inputSchema,s;try{s=X(o)}catch(d){let n=d instanceof Error?d.message:String(d);throw Error(n.split(`
|
|
5
|
+
`)[0])}for(let d of Object.values(s)){if(typeof d!=="object"||d.$ref===void 0)continue;let n=d.__absolute_ref__;if(s[n??d.$ref]===void 0)throw Error(`$ref ${JSON.stringify(d.$ref)} does not resolve`)}let i=(d)=>O(d,o,"2020-12",s,!1);return De.set(e,i),i}function Ge(e,t,o=""){let s=t instanceof Error?t.message:String(t);return TypeError(`registerTool: the inputSchema of ${e}: ${s}${o}`)}function zt(e){let t=[];for(let o of e.list())try{_e(o)}catch(s){e.remove(o),t.push(Ge(o.name,s,"; the tool was unregistered"))}return e.setCompiler((o)=>{try{_e(o)}catch(s){throw Ge(o.name,s)}}),t}function Ke(e){try{return structuredClone(e)}catch{return e}}var Ht=new TextEncoder;function re(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function ve(e,t){return new Response(JSON.stringify(t),{status:e,headers:{"content-type":"application/json"}})}function N(e,t,o,s,i){let d={code:o,message:s};if(i!==void 0)d.data=i;return ve(e,{jsonrpc:"2.0",id:t,error:d})}function D(e,t,o){return N(400,e,qt,`Bad Request: the request headers and body disagree: ${o}`,{mismatch:{header:t,body:o}})}function se(e){return Ht.encode(`event: message
|
|
6
|
+
data: ${JSON.stringify(e)}
|
|
7
|
+
|
|
8
|
+
`)}var We={"content-type":"text/event-stream","cache-control":"no-cache"};function Jt(e){return(e??"").split(";")[0]?.trim().toLowerCase()==="application/json"}function Ut(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 o=atob(t),s=Uint8Array.from(o,(i)=>i.charCodeAt(0));return new TextDecoder("utf-8",{fatal:!0}).decode(s)}catch{return}}function Vt(e){if(!(Q in e))return{key:Q,problem:"missing"};if(!($e in e))return{key:$e,problem:"missing"};if(typeof e[Q]!=="string")return{key:Q,problem:"expected a protocol version string"};if(!re(e[$e]))return{key:$e,problem:"expected an object"};let t=e[Ve];if(t!==void 0&&!(re(t)&&typeof t.name==="string"&&typeof t.version==="string"))return{key:Ve,problem:"expected {name, version}"};return}function Bt(e){let t=e.notifications;return re(t)&&t.toolsListChanged===!0?{toolsListChanged:!0}:{}}function Ye(e){let{tools:t,server:o}=e,s={name:o.name,version:o.version};if(o.title!==void 0)s.title=o.title;let i=new Set,d=!1,n=(u={})=>({...u,[Nt]:s});function l(u,m){return{jsonrpc:"2.0",id:u,result:{...m,resultType:"complete",_meta:n()}}}function T(u,m){let x;try{x=_e(u)(m)}catch(r){let y=r instanceof Error?r.message:String(r);return`The input schema of tool ${u.name} cannot be used: ${y}`}if(x.valid)return;let I=x.errors.filter((r)=>r.keyword!=="properties"&&r.keyword!=="$ref").map((r)=>`${r.instanceLocation} ${r.error}`).slice(0,5).join("; ");return`Input validation error: Invalid arguments for tool ${u.name}: ${I||"the arguments do not match the schema"}`}function q(){return t.list().map((u)=>{let m={name:u.name};if(u.title!==void 0)m.title=u.title;m.description=u.description,m.inputSchema=u.inputSchema;let{annotations:x,meta:I}=He(u.annotations);if(x!==void 0)m.annotations=x;if(I!==void 0)m._meta={[ze]:I};return m})}let _=(u)=>({kind:"invalid",message:u});async function U(u,m,x){let I=u.name;if(typeof I!=="string")return _("Invalid params: name must be a string");let r=t.get(I);if(r===void 0)return _(`Tool ${I} not found`);let y=u.arguments??{};if(!re(y))return _("Invalid params: arguments must be an object");let b=e.client(x),k={id:++jt,tool:r.name,arguments:Ke(y),client:{...b}};if(r.title!==void 0)k.title=r.title;let v=Date.now();e.observe?.start(k);let M="error",J=F("Internal error");try{[M,J]=await ne(r,y,m,b)}finally{e.observe?.end({id:k.id,tool:r.name,client:{...b},outcome:M,result:Ke(J),durationMs:Date.now()-v})}return{kind:"result",result:J}}async function ne(u,m,x,I){let r=T(u,m);if(r!==void 0)return["error",F(r)];if(u.annotations.consequentialHint===!0){let b={tool:{name:u.name,description:u.description},arguments:m,client:I,signal:x};if(u.title!==void 0)b.tool.title=u.title;let k=!1;try{k=await e.confirm(b)}catch{k=!1}if(!k)return[x.aborted?"cancelled":"declined",F("The user declined")]}if(x.aborted)return["cancelled",F("Cancelled")];if(t.get(u.name)!==u)return["error",F("The tool is no longer available")];let y;try{y=Je(await u.execute(m,{signal:x,client:I}))}catch(b){y=Ue(b)}if(x.aborted)return["cancelled",y];return[y.isError===!0?"error":"ok",y]}function G(u,m,x,I){let r=new ReadableStream({start:(y)=>{let b=(k)=>{if(x.aborted)return;let v;try{v=se(k)}catch{v=se(l(u,F("The tool returned a result that is not JSON.")))}try{y.enqueue(v),y.close()}catch{}};U(m,x,I).then((k)=>b(k.kind==="invalid"?{jsonrpc:"2.0",id:u,error:{code:-32602,message:k.message}}:l(u,k.result)),()=>b({jsonrpc:"2.0",id:u,error:{code:-32603,message:"Internal error"}}))}});return new Response(r,{status:200,headers:We})}function C(u,m,x){let I=Bt(m),r={jsonrpc:"2.0",id:u,result:{resultType:"complete",_meta:n({[Ie]:u})}},y,b=new ReadableStream({start:(k)=>{if(k.enqueue(se({jsonrpc:"2.0",method:"notifications/subscriptions/acknowledged",params:{notifications:I,_meta:{[Ie]:u}}})),Object.keys(I).length===0){k.enqueue(se(r)),k.close();return}let v={id:u,send:(M)=>{try{k.enqueue(se(M))}catch{i.delete(v)}},end:()=>{i.delete(v);try{k.enqueue(se(r)),k.close()}catch{}}};y=v,i.add(v),x.addEventListener("abort",()=>{i.delete(v);try{k.close()}catch{}})},cancel:()=>{if(y!==void 0)i.delete(y)}});return new Response(b,{status:200,headers:We})}function K(u,m){if(Array.isArray(m))return N(400,null,-32600,"Bad Request: JSON-RPC batches are not supported by this endpoint");if(!re(m)||m.jsonrpc!=="2.0")return N(400,null,-32600,"Bad Request: the request body is not a valid JSON-RPC message");let{method:x,id:I}=m;if(typeof x!=="string")return"result"in m||"error"in m?N(400,null,-32600,"Bad Request: JSON-RPC responses cannot be posted to this endpoint"):N(400,null,-32600,"Bad Request: the request body is not a valid JSON-RPC message");let r=u.headers.get("mcp-protocol-version"),y=u.headers.get("mcp-method"),b=re(m.params)?m.params:{},k=re(b._meta)?b._meta:void 0,v=k!==void 0&&Q in k,M=typeof k?.[Q]==="string"?k[Q]:void 0,J=r!==null&&r>=te;if(I===void 0){if(M!==void 0&&r!==null&&r!==M)return D(null,r,`the notification envelope names protocol version ${M} but the MCP-Protocol-Version header names ${r}`);if((v||J)&&y!==null&&y!==x)return D(null,y,`the notification body names method ${x} but the Mcp-Method header names ${y}`);return"notification"}if(typeof I!=="string"&&typeof I!=="number")return N(400,null,-32600,"Bad Request: the request body is not a valid JSON-RPC message");let P=I;if(!v||x==="initialize"&&(M===void 0||M<te)){if(x==="initialize"){if(J)return D(P,r,"an initialize request (legacy handshake) was sent with a modern MCP-Protocol-Version header");let A=typeof b.protocolVersion==="string"?b.protocolVersion:void 0;return E(P,A)}if(J){let A=k===void 0?["_meta"]:[Q];return N(400,P,-32602,`Invalid params: the MCP-Protocol-Version header names protocol revision ${r}, but the request is missing the required per-request envelope key(s): ${A.join(", ")}`,{envelope:{missing:A}})}return E(P,r??void 0)}let V=Vt(k);if(V!==void 0)return N(400,P,-32602,`Invalid _meta envelope for protocol revision ${te}: ${V.key}: ${V.problem}`,{envelope:V});if(r!==null&&M!==void 0&&r!==M)return D(P,r,`the body envelope names protocol version ${M} but the MCP-Protocol-Version header names ${r}`);if(y!==null&&y!==x)return D(P,y,`the body names method ${x} but the Mcp-Method header names ${y}`);if(M!==te)return E(P,M);if(r===null)return D(P,"(missing)",`the body envelope names protocol version ${M} but the required MCP-Protocol-Version header is absent`);if(y===null)return D(P,"(missing)",`the body names method ${x} but the required Mcp-Method header is absent`);if(x==="tools/call"&&typeof b.name==="string"){let A=b.name,j=u.headers.get("mcp-name");if(j===null)return D(P,"(missing)",`the body carries params.name="${A}" but the required Mcp-Name header is absent`);let W=Ut(j);if(W===void 0)return D(P,j,"the Mcp-Name header carries an invalid Base64 sentinel value");if(W!==A)return D(P,j,`the body carries params.name="${A}" but the Mcp-Name header names "${W}"`)}return{id:P,method:x,params:b}}function E(u,m){return m===void 0?N(400,u,Be,"Unsupported protocol version: the request did not name a protocol version",{supported:[te]}):N(400,u,Be,`Unsupported protocol version: ${m}`,{supported:[te],requested:m})}async function Z(u,m){if(u.method.toUpperCase()!=="POST")return N(405,null,-32000,"Method not allowed.");if(!Jt(u.headers.get("content-type")))return N(415,null,-32000,"Unsupported Media Type: Content-Type must be application/json");let x;try{x=JSON.parse(m.body??await u.text())}catch{return N(400,null,-32700,"Parse error: the request body is not valid JSON")}let I=K(u,x);if(I instanceof Response)return I;if(I==="notification")return new Response(null,{status:202});let{id:r,method:y,params:b}=I;switch(y){case"server/discover":{let k={supportedVersions:[te],capabilities:{tools:{listChanged:!0}}};if(o.instructions!==void 0)k.instructions=o.instructions;return k.ttlMs=0,k.cacheScope="private",ve(200,l(r,k))}case"tools/list":return ve(200,l(r,{tools:q(),ttlMs:0,cacheScope:"private"}));case"tools/call":return G(r,b,u.signal,m.grant);case"subscriptions/listen":return C(r,b,u.signal);default:return N(404,r,-32601,"Method not found")}}return{handle:(u,m)=>Z(u,m).catch(()=>N(500,null,-32603,"Internal server error")),toolsChanged(){if(d)return;d=!0,queueMicrotask(()=>{d=!1;for(let u of[...i])u.send({jsonrpc:"2.0",method:"notifications/tools/list_changed",params:{_meta:{[Ie]:u.id}}})})},close(){for(let u of[...i])u.end()}}}var be="tab-mcp.v1";function ie(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}var S=(e)=>typeof e==="string";function Fe(e){if(!ie(e)||!S(e.grantId)||!S(e.createdAt))return!1;let t=e.client;return ie(t)&&S(t.id)&&S(t.name)&&S(t.host)}function Dt(e){if(!ie(e))return!1;return["maxMessageBytes","maxBodyBytes","requestTimeoutMs","idleTimeoutMs","heartbeatMs","keepAliveMs","maxConcurrentRequests"].every((t)=>typeof e[t]==="number")}function Gt(e){return ie(e)&&Object.values(e).every(S)}function Ze(e){let t;try{t=JSON.parse(e)}catch{return}if(!ie(t))return;switch(t.type){case"session":return S(t.sessionId)&&S(t.address)&&S(t.origin)&&S(t.expiresAt)&&Dt(t.limits)&&Array.isArray(t.grants)&&t.grants.every(Fe)&&(t.appName===void 0||S(t.appName))&&(t.pairing===void 0||S(t.pairing))?t:void 0;case"ping":return typeof t.t==="number"?t:void 0;case"bye":return{type:"bye",reason:S(t.reason)?t.reason:""};case"http.request":return S(t.id)&&S(t.method)&&S(t.path)&&Gt(t.headers)&&S(t.body)&&ie(t.grant)&&S(t.grant.grantId)&&S(t.grant.clientId)?t:void 0;case"http.cancel":return S(t.id)?t:void 0;case"pairing.code":return S(t.code)&&S(t.expiresAt)?t:void 0;case"grant.added":return Fe(t.grant)?t:void 0;case"grant.removed":return S(t.grantId)?{type:"grant.removed",grantId:t.grantId,reason:S(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 S(t.code)?t:void 0;default:return}}var Kt=15000,Xe={1000:"closed",1008:"policy",1009:"too_large",4001:"expired",4002:"idle",4003:"heartbeat",4004:"shutdown",4005:"replaced",4008:"rate_limited"},Qe={replaced:"replaced",expired:"expired",idle:"idle",shutdown:"shutdown"};function de(e,t){return Object.assign(Error(e),{reason:t})}var Wt=["content-type","cache-control"];function Yt(){let e=globalThis.document?.title;return typeof e==="string"?e.slice(0,300):""}function Ft(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 Zt=new Set(["session","ping","bye","http.request","http.cancel","pairing.code","grant.added","grant.removed","identity.bound","error"]),et=512,tt=6,rt=64,Xt=et+tt*rt;function Qt(e){let t=Math.floor((e-et)/tt);return t>=rt?t:void 0}function*Le(e,t){let o=0;while(o<e.length){let s=Math.min(o+t,e.length),i=e.charCodeAt(s-1);if(s<e.length&&i>=55296&&i<=56319)s+=s-1>o?-1:1;yield e.slice(o,s),o=s}}function $r(e,t,o){let s=new WebSocket(t,be),i=new Map,d="opening",n,l=65536,T,q=0,_,U,ne=new Promise((r,y)=>{_=r,U=y});ne.catch(()=>{});let G=setTimeout(()=>{u(de("The relay did not answer in time.","network"))},Kt),C=Ye({tools:e.registry,server:e.server,confirm:(r)=>e.confirm(r),client:(r)=>e.clientFor(r),observe:{start:(r)=>e.toolCallStarted(r),end:(r)=>e.toolCallEnded(r)}}),K=e.registry.onChange(()=>C.toolsChanged());function E(r){if(s.readyState!==WebSocket.OPEN)return!1;try{return s.send(JSON.stringify(r)),!0}catch{return!1}}function Z(){if(q<=0)return;clearTimeout(T),T=setTimeout(()=>{n??="heartbeat",m(4003);try{s.close()}catch{}},q*2.5)}function u(r){if(d!=="opening")return;m(0),U(r);try{s.close()}catch{}}function m(r){if(d==="closed")return;let y=d==="ready";d="closed",clearTimeout(G),clearTimeout(T),K();for(let b of i.values())b.abort();if(i.clear(),C.close(),y){let b=n??Xe[r]??(r===1006?"network":"closed");e.closed(b,r)}}async function x(r){let y=new AbortController;i.set(r.id,y);let b=()=>d==="ready"&&i.get(r.id)===y&&!y.signal.aborted;try{let k=new Request(`https://tab.invalid${r.path}`,{method:r.method,headers:r.headers,signal:y.signal}),v=await C.handle(k,{grant:r.grant,body:r.body});if(!b()){await v.body?.cancel().catch(()=>{});return}let M={};for(let A of Wt){let j=v.headers.get(A);if(j!==null)M[A]=j}if(!(M["content-type"]??"").startsWith("text/event-stream")||v.body===null){let A=await v.text();if(!b())return;if(A.length<=l){E({type:"http.response",id:r.id,status:v.status,headers:M,body:A});return}E({type:"http.response.start",id:r.id,status:v.status,headers:M});for(let j of Le(A,l)){if(!b())break;E({type:"http.response.chunk",id:r.id,data:j})}if(b())E({type:"http.response.end",id:r.id});return}E({type:"http.response.start",id:r.id,status:v.status,headers:M});let P=v.body.getReader(),V=new TextDecoder;y.signal.addEventListener("abort",()=>{P.cancel().catch(()=>{})});for(;;){let{done:A,value:j}=await P.read();if(A||!b())break;let W=V.decode(j,{stream:!0});for(let ae of Le(W,l))E({type:"http.response.chunk",id:r.id,data:ae})}if(b())E({type:"http.response.end",id:r.id})}catch(k){if(b())e.error(k instanceof Error?k:Error(String(k))),E({type:"http.response",id:r.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(r.id)===y)i.delete(r.id)}}function I(r){if(d==="opening"){if(r.type==="session"){let y=Qt(r.limits.maxMessageBytes);if(y===void 0){u(de(`The relay's message limit (${r.limits.maxMessageBytes} bytes) is too small; tab-mcp needs at least ${Xt}.`,"policy"));return}l=y,d="ready",clearTimeout(G),q=r.limits.heartbeatMs,Z(),_(e.sessionStarted(r))}else if(r.type==="error")u(de(`The relay refused the connection: ${r.message||r.code}`,r.code==="rate_limited"?"rate_limited":"policy"));else if(r.type==="bye")u(de(`The relay ended the connection: ${r.reason}`,Qe[r.reason]??"closed"));return}if(d!=="ready")return;switch(r.type){case"ping":Z(),E({type:"pong",t:r.t});return;case"http.request":x(r);return;case"http.cancel":i.get(r.id)?.abort(),i.delete(r.id);return;case"pairing.code":e.pairingCode({code:r.code,expiresAt:r.expiresAt});return;case"grant.added":e.grantAdded(r.grant);return;case"grant.removed":e.grantRemoved(r.grantId);return;case"identity.bound":e.identityResult(!0,r.round);return;case"bye":if(n=Qe[r.reason]??"closed",n==="replaced")e.replaced();return;case"error":if(r.code==="identity_refused"){e.identityResult(!1,typeof r.round==="number"?r.round:void 0,r.message);return}e.error(Error(`Relay error ${r.code}: ${r.message}`));return;case"session":return}}return s.addEventListener("open",()=>{if(s.protocol!==""&&s.protocol!==be){u(de(`The relay speaks ${s.protocol}, not ${be}.`,"policy"));return}let r={type:"hello",library:e.library,page:{title:Yt()},secret:o};if(e.appName!==void 0)r.app={name:e.appName};E(r)}),s.addEventListener("message",(r)=>{if(typeof r.data!=="string")return;let y=Ze(r.data);if(y!==void 0){if(d==="ready")Z();I(y);return}let b=Ft(r.data);if(b?.id!==void 0)E(Zt.has(b.type)?{type:"error",code:"bad_message",message:`malformed ${b.type}`,id:b.id}:{type:"error",code:"unknown_type",message:`unknown type ${b.type}`,id:b.id})}),s.addEventListener("close",(r)=>{if(d==="opening"){m(r.code);let y=r.code===1006||r.code===1002;U(de(y?"Could not connect to the relay (refused, unreachable, or this page's origin is not allowed).":`The relay closed the connection (${r.code}${r.reason?`: ${r.reason}`:""}).`,Xe[r.code]??(y?"network":"closed")));return}m(r.code)}),{ready:ne,send:E,close(r){if(d==="closed")return;if(d==="opening"){u(new DOMException("The connection was cancelled","AbortError"));return}n=r,E({type:"bye",reason:"user"}),m(1000);try{s.close(1000,"bye")}catch{}}}}export{zt as compileRegistry,$r as openConnection};
|
|
9
|
+
|
|
10
|
+
//# debugId=49574567FC8D9C0964756E2164756E21
|
|
11
|
+
//# sourceMappingURL=connection-nygehv52.min.js.map
|