@ractive-ch/tab-mcp-client 0.1.0 → 0.3.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 -9
- package/always-allowed.d.ts +15 -0
- package/cdn/connection-5ehqkmw1.min.js +10 -0
- package/cdn/{connection-cfq1n4kh.min.js.map → connection-5ehqkmw1.min.js.map} +4 -4
- package/cdn/tab-mcp-client.min.js +3 -3
- package/cdn/tab-mcp-client.min.js.map +6 -5
- package/cdn/ui-dv7pxk0b.min.js +4 -0
- package/cdn/ui-dv7pxk0b.min.js.map +10 -0
- package/{connection-1gf7vqz2.js → connection-ag7eyd36.js} +50 -9
- package/connection-ag7eyd36.js.map +13 -0
- package/index.d.ts +1 -1
- package/index.js +50 -7
- package/index.js.map +6 -5
- package/internal.d.ts +4 -1
- package/mcp.d.ts +6 -1
- package/package.json +1 -1
- package/types.d.ts +31 -0
- package/{ui-71qbaznx.js → ui-g1k2g5hm.js} +113 -25
- package/ui-g1k2g5hm.js.map +10 -0
- package/ui.d.ts +11 -6
- package/version.d.ts +1 -1
- package/cdn/connection-cfq1n4kh.min.js +0 -10
- package/cdn/ui-vp7pkb1j.min.js +0 -4
- package/cdn/ui-vp7pkb1j.min.js.map +0 -10
- package/connection-1gf7vqz2.js.map +0 -13
- package/ui-71qbaznx.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.3.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.1
|
|
25
|
+
ractive/tab-mcp:0.2.1
|
|
26
26
|
```
|
|
27
27
|
|
|
28
28
|
For production, see
|
|
@@ -38,7 +38,7 @@ Or without a bundler, from a CDN as an ES module:
|
|
|
38
38
|
|
|
39
39
|
```html
|
|
40
40
|
<script type="module">
|
|
41
|
-
import { TabMcp } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.
|
|
41
|
+
import { TabMcp } from "https://cdn.jsdelivr.net/npm/@ractive-ch/tab-mcp-client@0.3.0/cdn/tab-mcp-client.min.js";
|
|
42
42
|
</script>
|
|
43
43
|
```
|
|
44
44
|
|
|
@@ -93,9 +93,11 @@ added and removed tools.
|
|
|
93
93
|
### Consequential tools
|
|
94
94
|
|
|
95
95
|
Mark tools that change or delete something with `consequentialHint: true`. The page then
|
|
96
|
-
asks the user before every call ("Allow" or "Don't allow"), showing the AI
|
|
97
|
-
|
|
98
|
-
|
|
96
|
+
asks the user before every call ("Allow", "Always allow" or "Don't allow"), showing the AI
|
|
97
|
+
app and the arguments. "Always allow" lets that tool run without asking for that AI app
|
|
98
|
+
until the page is reloaded or the app is disconnected. A refusal reaches the AI app as an
|
|
99
|
+
error result. Pass `onConfirm` to ask in your own UI (it is asked every time; remember
|
|
100
|
+
answers there if you want to):
|
|
99
101
|
|
|
100
102
|
```ts
|
|
101
103
|
const mcp = new TabMcp({
|
|
@@ -114,8 +116,15 @@ const mcp = new TabMcp({
|
|
|
114
116
|
2. The dialog shows the address and short instructions for Claude, ChatGPT and Claude
|
|
115
117
|
Code. The user adds the address to their AI app.
|
|
116
118
|
3. The AI app opens the relay's sign-in page in the browser. The dialog shows a 6-digit
|
|
117
|
-
code, which the user types there. The code changes every
|
|
118
|
-
|
|
119
|
+
code with a Copy button, which the user types or pastes there. The code changes every
|
|
120
|
+
2 minutes and after each use.
|
|
121
|
+
4. The dialog announces and lists the connected app with a Disconnect button, and shows
|
|
122
|
+
"Done" to close it.
|
|
123
|
+
|
|
124
|
+
Until an app connects, the dialog offers no prominent button under the code: only a small
|
|
125
|
+
"Close" at the bottom (and Escape). Closing it stops the code (`stopPairing()`); the page
|
|
126
|
+
stays connected and the address stays the same, so calling `showConnectDialog()` again
|
|
127
|
+
shows the same address with a new code.
|
|
119
128
|
|
|
120
129
|
The address stays the same across visits: the library keeps a secret per relay in
|
|
121
130
|
`localStorage`. "New address" in the dialog calls `newAddress()`, which disconnects every
|
|
@@ -133,7 +142,18 @@ Instead of `showConnectDialog()`, use `connect()`, `disconnect()`, `newAddress()
|
|
|
133
142
|
`startPairing()` and `stopPairing()` (codes come only while pairing is on),
|
|
134
143
|
`revoke(grantId)`, the properties `state`, `address`, `pairingCode`, `grants` and
|
|
135
144
|
`tools`, and the events `statechange`, `connected`, `disconnected`, `pairingcode`,
|
|
136
|
-
`grantschange`, `toolschange`, `replaced` and `error`.
|
|
145
|
+
`grantschange`, `toolschange`, `replaced` and `error`. For an activity log, `toolcall`
|
|
146
|
+
and `toolcallend` report every call by an AI app: its id, tool, arguments and AI app as it
|
|
147
|
+
starts, then its outcome (`ok`, `error`, `declined` or `cancelled`), result and duration.
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
mcp.addEventListener("toolcallend", (e) => {
|
|
151
|
+
const { tool, client, outcome, durationMs } = e.detail;
|
|
152
|
+
log(`${client.name ?? client.host}: ${tool} ${outcome} in ${durationMs} ms`);
|
|
153
|
+
});
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
The default dialogs take their
|
|
137
157
|
colours and sizes from `--tab-mcp-*` CSS custom properties (`--tab-mcp-font`,
|
|
138
158
|
`--tab-mcp-color`, `--tab-mcp-background`, `--tab-mcp-border`, `--tab-mcp-radius`, …)
|
|
139
159
|
and need no CSP exception.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The tools a user chose "Always allow" for, per grant (AI app). Kept in
|
|
3
|
+
* memory for the page's lifetime; an entry goes when its grant goes or its
|
|
4
|
+
* tool is unregistered, so a re-paired app or a new tool under the same name
|
|
5
|
+
* is asked again.
|
|
6
|
+
*/
|
|
7
|
+
export declare class AlwaysAllowed {
|
|
8
|
+
#private;
|
|
9
|
+
has(grantId: string, tool: string): boolean;
|
|
10
|
+
add(grantId: string, tool: string): void;
|
|
11
|
+
/** Forget every grant not in `grantIds`. */
|
|
12
|
+
keepGrants(grantIds: Iterable<string>): void;
|
|
13
|
+
/** Forget every tool not in `names`. */
|
|
14
|
+
keepTools(names: Iterable<string>): void;
|
|
15
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
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(et(e))}function et(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}var tt={prefixItems:!0,items:!0,allOf:!0,anyOf:!0,oneOf:!0},rt={$defs:!0,definitions:!0,properties:!0,patternProperties:!0,dependentSchemas:!0},nt={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},ot=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 F(e,t=Object.create(null),o=ot,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 F(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(nt[d])continue;let n=`${s}/${H(d)}`,f=e[d];if(Array.isArray(f)){if(tt[d]){let v=f.length;for(let q=0;q<v;q++)F(f[q],t,o,`${n}/${q}`)}}else if(rt[d])for(let v in f)F(f[v],t,o,`${n}/${H(v)}`);else F(f,t,o,n)}return t}var st=/^(\d\d\d\d)-(\d\d)-(\d\d)$/,it=[0,31,28,31,30,31,30,31,31,30,31,30,31],dt=/^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|[+-]\d\d(?::?\d\d)?)?$/i,at=/^(?=.{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,ut=/^(?:[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,lt=/^(?:(?:[^\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,ft=/^(?:(?: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=/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i,ct=/^(?:\/(?:[^~/]|~0|~1)*)*$/,mt=/^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i,yt=/^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/,gt=(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))},ht=/^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,$t=/^((([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,wt=(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 xe={date:Ae,time:Ce.bind(void 0,!1),"date-time":Rt,duration:wt,uri:It,"uri-reference":B(ut),"uri-template":B(lt),url:B(ft),email:gt,hostname:B(at),ipv4:B(ht),ipv6:B($t),regex:Mt,uuid:B(pt),"json-pointer":B(ct),"json-pointer-uri-fragment":B(mt),"relative-json-pointer":B(yt)};function bt(e){return e%4===0&&(e%100!==0||e%400===0)}function Ae(e){let t=e.match(st);if(!t)return!1;let o=+t[1],s=+t[2],i=+t[3];return s>=1&&s<=12&&i>=1&&i<=(s==2&&bt(o)?29:it[s])}function Ce(e,t){let o=t.match(dt);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 kt=/t|\s/i;function Rt(e){let t=e.split(kt);return t.length==2&&Ae(t[0])&&Ce(!0,t[1])}var xt=/\/|:/,vt=/^(?:[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 It(e){return xt.test(e)&&vt.test(e)}var Tt=/[^\\]\\Z/;function Mt(e){if(Tt.test(e))return!1;try{return new RegExp(e,"u"),!0}catch(t){return!1}}function Ne(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 S(e,t,o="2019-09",s=F(t),i=!0,d=null,n="#",f="#",v=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,M;switch(q){case"boolean":case"number":case"string":M=q;break;case"object":if(e===null)M="null";else if(Array.isArray(e))M="array";else M="object";break;default:throw Error(`Instances of "${q}" type are not supported.`)}let{$ref:J,$recursiveRef:ne,$recursiveAnchor:G,type:C,const:K,enum:O,required:Z,not:u,anyOf:y,allOf:x,oneOf:I,if:r,then:m,else:w,format:R,properties:T,patternProperties:_,additionalProperties:U,unevaluatedProperties:A,minProperties:V,maxProperties:P,propertyNames:j,dependentRequired:W,dependentSchemas:de,dependencies:we,prefixItems:be,items:ae,additionalItems:Me,unevaluatedItems:_e,contains:Se,minContains:Y,maxContains:fe,minItems:ke,maxItems:Re,uniqueItems:Qe,minimum:Q,maximum:L,exclusiveMinimum:ue,exclusiveMaximum:le,multipleOf:pe,minLength:ce,maxLength:me,pattern:Ee,__absolute_ref__:ye,__absolute_recursive_ref__:Le}=t,l=[];if(G===!0&&d===null)d=t;if(ne==="#"){let g=d===null?s[Le]:d,c=`${f}/$recursiveRef`,k=S(e,d===null?t:d,o,s,i,g,n,c,v);if(!k.valid)l.push({instanceLocation:n,keyword:"$recursiveRef",keywordLocation:c,error:"A subschema had errors."},...k.errors)}if(J!==void 0){let c=s[ye||J];if(c===void 0){let a=`Unresolved $ref "${J}".`;if(ye&&ye!==J)a+=` Absolute URI "${ye}".`;throw a+=`
|
|
2
|
+
Known schemas:
|
|
3
|
+
- ${Object.keys(s).join(`
|
|
4
|
+
- `)}`,Error(a)}let k=`${f}/$ref`,p=S(e,c,o,s,i,d,n,k,v);if(!p.valid)l.push({instanceLocation:n,keyword:"$ref",keywordLocation:k,error:"A subschema had errors."},...p.errors);if(o==="4"||o==="7")return{valid:l.length===0,errors:l}}if(Array.isArray(C)){let g=C.length,c=!1;for(let k=0;k<g;k++)if(M===C[k]||C[k]==="integer"&&M==="number"&&e%1===0&&e===e){c=!0;break}if(!c)l.push({instanceLocation:n,keyword:"type",keywordLocation:`${f}/type`,error:`Instance type "${M}" is invalid. Expected "${C.join('", "')}".`})}else if(C==="integer"){if(M!=="number"||e%1||e!==e)l.push({instanceLocation:n,keyword:"type",keywordLocation:`${f}/type`,error:`Instance type "${M}" is invalid. Expected "${C}".`})}else if(C!==void 0&&M!==C)l.push({instanceLocation:n,keyword:"type",keywordLocation:`${f}/type`,error:`Instance type "${M}" is invalid. Expected "${C}".`});if(K!==void 0){if(M==="object"||M==="array"){if(!oe(e,K))l.push({instanceLocation:n,keyword:"const",keywordLocation:`${f}/const`,error:`Instance does not match ${JSON.stringify(K)}.`})}else if(e!==K)l.push({instanceLocation:n,keyword:"const",keywordLocation:`${f}/const`,error:`Instance does not match ${JSON.stringify(K)}.`})}if(O!==void 0){if(M==="object"||M==="array"){if(!O.some((g)=>oe(e,g)))l.push({instanceLocation:n,keyword:"enum",keywordLocation:`${f}/enum`,error:`Instance does not match any of ${JSON.stringify(O)}.`})}else if(!O.some((g)=>e===g))l.push({instanceLocation:n,keyword:"enum",keywordLocation:`${f}/enum`,error:`Instance does not match any of ${JSON.stringify(O)}.`})}if(u!==void 0){let g=`${f}/not`;if(S(e,u,o,s,i,d,n,g).valid)l.push({instanceLocation:n,keyword:"not",keywordLocation:g,error:'Instance matched "not" schema.'})}let ge=[];if(y!==void 0){let g=`${f}/anyOf`,c=l.length,k=!1;for(let p=0;p<y.length;p++){let a=y[p],b=Object.create(v),h=S(e,a,o,s,i,G===!0?d:null,n,`${g}/${p}`,b);if(l.push(...h.errors),k=k||h.valid,h.valid)ge.push(b)}if(k)l.length=c;else l.splice(c,0,{instanceLocation:n,keyword:"anyOf",keywordLocation:g,error:"Instance does not match any subschemas."})}if(x!==void 0){let g=`${f}/allOf`,c=l.length,k=!0;for(let p=0;p<x.length;p++){let a=x[p],b=Object.create(v),h=S(e,a,o,s,i,G===!0?d:null,n,`${g}/${p}`,b);if(l.push(...h.errors),k=k&&h.valid,h.valid)ge.push(b)}if(k)l.length=c;else l.splice(c,0,{instanceLocation:n,keyword:"allOf",keywordLocation:g,error:"Instance does not match every subschema."})}if(I!==void 0){let g=`${f}/oneOf`,c=l.length,k=I.filter((p,a)=>{let b=Object.create(v),h=S(e,p,o,s,i,G===!0?d:null,n,`${g}/${a}`,b);if(l.push(...h.errors),h.valid)ge.push(b);return h.valid}).length;if(k===1)l.length=c;else l.splice(c,0,{instanceLocation:n,keyword:"oneOf",keywordLocation:g,error:`Instance does not match exactly one subschema (${k} matches).`})}if(M==="object"||M==="array")Object.assign(v,...ge);if(r!==void 0){let g=`${f}/if`;if(S(e,r,o,s,i,d,n,g,v).valid){if(m!==void 0){let k=S(e,m,o,s,i,d,n,`${f}/then`,v);if(!k.valid)l.push({instanceLocation:n,keyword:"if",keywordLocation:g,error:'Instance does not match "then" schema.'},...k.errors)}}else if(w!==void 0){let k=S(e,w,o,s,i,d,n,`${f}/else`,v);if(!k.valid)l.push({instanceLocation:n,keyword:"if",keywordLocation:g,error:'Instance does not match "else" schema.'},...k.errors)}}if(M==="object"){if(Z!==void 0){for(let p of Z)if(!(p in e))l.push({instanceLocation:n,keyword:"required",keywordLocation:`${f}/required`,error:`Instance does not have required property "${p}".`})}let g=Object.keys(e);if(V!==void 0&&g.length<V)l.push({instanceLocation:n,keyword:"minProperties",keywordLocation:`${f}/minProperties`,error:`Instance does not have at least ${V} properties.`});if(P!==void 0&&g.length>P)l.push({instanceLocation:n,keyword:"maxProperties",keywordLocation:`${f}/maxProperties`,error:`Instance does not have at least ${P} properties.`});if(j!==void 0){let p=`${f}/propertyNames`;for(let a in e){let b=`${n}/${H(a)}`,h=S(a,j,o,s,i,d,b,p);if(!h.valid)l.push({instanceLocation:n,keyword:"propertyNames",keywordLocation:p,error:`Property name "${a}" does not match schema.`},...h.errors)}}if(W!==void 0){let p=`${f}/dependantRequired`;for(let a in W)if(a in e){let b=W[a];for(let h of b)if(!(h in e))l.push({instanceLocation:n,keyword:"dependentRequired",keywordLocation:p,error:`Instance has "${a}" but does not have "${h}".`})}}if(de!==void 0)for(let p in de){let a=`${f}/dependentSchemas`;if(p in e){let b=S(e,de[p],o,s,i,d,n,`${a}/${H(p)}`,v);if(!b.valid)l.push({instanceLocation:n,keyword:"dependentSchemas",keywordLocation:a,error:`Instance has "${p}" but does not match dependant schema.`},...b.errors)}}if(we!==void 0){let p=`${f}/dependencies`;for(let a in we)if(a in e){let b=we[a];if(Array.isArray(b)){for(let h of b)if(!(h in e))l.push({instanceLocation:n,keyword:"dependencies",keywordLocation:p,error:`Instance has "${a}" but does not have "${h}".`})}else{let h=S(e,b,o,s,i,d,n,`${p}/${H(a)}`);if(!h.valid)l.push({instanceLocation:n,keyword:"dependencies",keywordLocation:p,error:`Instance has "${a}" but does not match dependant schema.`},...h.errors)}}}let c=Object.create(null),k=!1;if(T!==void 0){let p=`${f}/properties`;for(let a in T){if(!(a in e))continue;let b=`${n}/${H(a)}`,h=S(e[a],T[a],o,s,i,d,b,`${p}/${H(a)}`);if(h.valid)v[a]=c[a]=!0;else if(k=i,l.push({instanceLocation:n,keyword:"properties",keywordLocation:p,error:`Property "${a}" does not match schema.`},...h.errors),k)break}}if(!k&&_!==void 0){let p=`${f}/patternProperties`;for(let a in _){let b=new RegExp(a,"u"),h=_[a];for(let z in e){if(!b.test(z))continue;let Oe=`${n}/${H(z)}`,Pe=S(e[z],h,o,s,i,d,Oe,`${p}/${H(a)}`);if(Pe.valid)v[z]=c[z]=!0;else k=i,l.push({instanceLocation:n,keyword:"patternProperties",keywordLocation:p,error:`Property "${z}" matches pattern "${a}" but does not match associated schema.`},...Pe.errors)}}}if(!k&&U!==void 0){let p=`${f}/additionalProperties`;for(let a in e){if(c[a])continue;let b=`${n}/${H(a)}`,h=S(e[a],U,o,s,i,d,b,p);if(h.valid)v[a]=!0;else k=i,l.push({instanceLocation:n,keyword:"additionalProperties",keywordLocation:p,error:`Property "${a}" does not match additional properties schema.`},...h.errors)}}else if(!k&&A!==void 0){let p=`${f}/unevaluatedProperties`;for(let a in e)if(!v[a]){let b=`${n}/${H(a)}`,h=S(e[a],A,o,s,i,d,b,p);if(h.valid)v[a]=!0;else l.push({instanceLocation:n,keyword:"unevaluatedProperties",keywordLocation:p,error:`Property "${a}" does not match unevaluated properties schema.`},...h.errors)}}}else if(M==="array"){if(Re!==void 0&&e.length>Re)l.push({instanceLocation:n,keyword:"maxItems",keywordLocation:`${f}/maxItems`,error:`Array has too many items (${e.length} > ${Re}).`});if(ke!==void 0&&e.length<ke)l.push({instanceLocation:n,keyword:"minItems",keywordLocation:`${f}/minItems`,error:`Array has too few items (${e.length} < ${ke}).`});let g=e.length,c=0,k=!1;if(be!==void 0){let p=`${f}/prefixItems`,a=Math.min(be.length,g);for(;c<a;c++){let b=S(e[c],be[c],o,s,i,d,`${n}/${c}`,`${p}/${c}`);if(v[c]=!0,!b.valid){if(k=i,l.push({instanceLocation:n,keyword:"prefixItems",keywordLocation:p,error:"Items did not match schema."},...b.errors),k)break}}}if(ae!==void 0){let p=`${f}/items`;if(Array.isArray(ae)){let a=Math.min(ae.length,g);for(;c<a;c++){let b=S(e[c],ae[c],o,s,i,d,`${n}/${c}`,`${p}/${c}`);if(v[c]=!0,!b.valid){if(k=i,l.push({instanceLocation:n,keyword:"items",keywordLocation:p,error:"Items did not match schema."},...b.errors),k)break}}}else for(;c<g;c++){let a=S(e[c],ae,o,s,i,d,`${n}/${c}`,p);if(v[c]=!0,!a.valid){if(k=i,l.push({instanceLocation:n,keyword:"items",keywordLocation:p,error:"Items did not match schema."},...a.errors),k)break}}if(!k&&Me!==void 0){let a=`${f}/additionalItems`;for(;c<g;c++){let b=S(e[c],Me,o,s,i,d,`${n}/${c}`,a);if(v[c]=!0,!b.valid)k=i,l.push({instanceLocation:n,keyword:"additionalItems",keywordLocation:a,error:"Items did not match additional items schema."},...b.errors)}}}if(Se!==void 0)if(g===0&&Y===void 0)l.push({instanceLocation:n,keyword:"contains",keywordLocation:`${f}/contains`,error:"Array is empty. It must contain at least one item matching the schema."});else if(Y!==void 0&&g<Y)l.push({instanceLocation:n,keyword:"minContains",keywordLocation:`${f}/minContains`,error:`Array has less items (${g}) than minContains (${Y}).`});else{let p=`${f}/contains`,a=l.length,b=0;for(let h=0;h<g;h++){let z=S(e[h],Se,o,s,i,d,`${n}/${h}`,p);if(z.valid)v[h]=!0,b++;else l.push(...z.errors)}if(b>=(Y||0))l.length=a;if(Y===void 0&&fe===void 0&&b===0)l.splice(a,0,{instanceLocation:n,keyword:"contains",keywordLocation:p,error:"Array does not contain item matching schema."});else if(Y!==void 0&&b<Y)l.push({instanceLocation:n,keyword:"minContains",keywordLocation:`${f}/minContains`,error:`Array must contain at least ${Y} items matching schema. Only ${b} items were found.`});else if(fe!==void 0&&b>fe)l.push({instanceLocation:n,keyword:"maxContains",keywordLocation:`${f}/maxContains`,error:`Array may contain at most ${fe} items matching schema. ${b} items were found.`})}if(!k&&_e!==void 0){let p=`${f}/unevaluatedItems`;for(c;c<g;c++){if(v[c])continue;let a=S(e[c],_e,o,s,i,d,`${n}/${c}`,p);if(v[c]=!0,!a.valid)l.push({instanceLocation:n,keyword:"unevaluatedItems",keywordLocation:p,error:"Items did not match unevaluated items schema."},...a.errors)}}if(Qe)for(let p=0;p<g;p++){let a=e[p],b=typeof a==="object"&&a!==null;for(let h=0;h<g;h++){if(p===h)continue;let z=e[h];if(a===z||b&&(typeof z==="object"&&z!==null)&&oe(a,z))l.push({instanceLocation:n,keyword:"uniqueItems",keywordLocation:`${f}/uniqueItems`,error:`Duplicate items at indexes ${p} and ${h}.`}),p=Number.MAX_SAFE_INTEGER,h=Number.MAX_SAFE_INTEGER}}}else if(M==="number"){if(o==="4"){if(Q!==void 0&&(ue===!0&&e<=Q||e<Q))l.push({instanceLocation:n,keyword:"minimum",keywordLocation:`${f}/minimum`,error:`${e} is less than ${ue?"or equal to ":""} ${Q}.`});if(L!==void 0&&(le===!0&&e>=L||e>L))l.push({instanceLocation:n,keyword:"maximum",keywordLocation:`${f}/maximum`,error:`${e} is greater than ${le?"or equal to ":""} ${L}.`})}else{if(Q!==void 0&&e<Q)l.push({instanceLocation:n,keyword:"minimum",keywordLocation:`${f}/minimum`,error:`${e} is less than ${Q}.`});if(L!==void 0&&e>L)l.push({instanceLocation:n,keyword:"maximum",keywordLocation:`${f}/maximum`,error:`${e} is greater than ${L}.`});if(ue!==void 0&&e<=ue)l.push({instanceLocation:n,keyword:"exclusiveMinimum",keywordLocation:`${f}/exclusiveMinimum`,error:`${e} is less than ${ue}.`});if(le!==void 0&&e>=le)l.push({instanceLocation:n,keyword:"exclusiveMaximum",keywordLocation:`${f}/exclusiveMaximum`,error:`${e} is greater than or equal to ${le}.`})}if(pe!==void 0){let g=e%pe;if(Math.abs(0-g)>=0.00000011920929&&Math.abs(pe-g)>=0.00000011920929)l.push({instanceLocation:n,keyword:"multipleOf",keywordLocation:`${f}/multipleOf`,error:`${e} is not a multiple of ${pe}.`})}}else if(M==="string"){let g=ce===void 0&&me===void 0?0:Ne(e);if(ce!==void 0&&g<ce)l.push({instanceLocation:n,keyword:"minLength",keywordLocation:`${f}/minLength`,error:`String is too short (${g} < ${ce}).`});if(me!==void 0&&g>me)l.push({instanceLocation:n,keyword:"maxLength",keywordLocation:`${f}/maxLength`,error:`String is too long (${g} > ${me}).`});if(Ee!==void 0&&!new RegExp(Ee,"u").test(e))l.push({instanceLocation:n,keyword:"pattern",keywordLocation:`${f}/pattern`,error:"String does not match pattern."});if(R!==void 0&&xe[R]&&!xe[R](e))l.push({instanceLocation:n,keyword:"format",keywordLocation:`${f}/format`,error:`String does not match format "${R}".`})}return{valid:l.length===0,errors:l}}class ve{schema;draft;shortCircuit;lookup;constructor(e,t="2019-09",o=!0){this.schema=e,this.draft=t,this.shortCircuit=o,this.lookup=F(e)}validate(e){return S(e,this.schema,this.draft,this.lookup,this.shortCircuit)}addSchema(e,t){if(t)e={...e,$id:t};F(e,this.lookup)}}var je="ch.ractive.tab-mcp/annotations",_t=["readOnlyHint","untrustedContentHint","consequentialHint","debugging"],St=["destructiveHint","idempotentHint","openWorldHint"];function ze(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 St){let d=e[i];if(d!==void 0)t[i]=d}let o={};for(let i of _t){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 ee(e){return{content:[{type:"text",text:e}],isError:!0}}function qe(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function He(e){if(typeof e==="string")return{content:[{type:"text",text:e}]};if(e===void 0)return{content:[]};if(qe(e)&&Array.isArray(e.content))return e;let t;try{t=JSON.stringify(e)}catch{}if(t===void 0)return ee("The tool returned a value that is not JSON.");let o={content:[{type:"text",text:t}]};if(qe(e))o.structuredContent=e;return o}function Je(e){let t=e instanceof Error?e.message:String(e);return ee(t||"The tool failed.")}var te="2026-07-28",X="io.modelcontextprotocol/protocolVersion",he="io.modelcontextprotocol/clientCapabilities",Ue="io.modelcontextprotocol/clientInfo",Et="io.modelcontextprotocol/serverInfo",Ie="io.modelcontextprotocol/subscriptionId",Ot=-32020,Ve=-32022,Pt=0;function Be(e){try{return structuredClone(e)}catch{return e}}var At=new TextEncoder;function re(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function Te(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 Te(e,{jsonrpc:"2.0",id:t,error:d})}function D(e,t,o){return N(400,e,Ot,`Bad Request: the request headers and body disagree: ${o}`,{mismatch:{header:t,body:o}})}function se(e){return At.encode(`event: message
|
|
5
|
+
data: ${JSON.stringify(e)}
|
|
6
|
+
|
|
7
|
+
`)}var De={"content-type":"text/event-stream","cache-control":"no-cache"};function Ct(e){return(e??"").split(";")[0]?.trim().toLowerCase()==="application/json"}function Nt(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 qt(e){if(!(X in e))return{key:X,problem:"missing"};if(!(he in e))return{key:he,problem:"missing"};if(typeof e[X]!=="string")return{key:X,problem:"expected a protocol version string"};if(!re(e[he]))return{key:he,problem:"expected an object"};let t=e[Ue];if(t!==void 0&&!(re(t)&&typeof t.name==="string"&&typeof t.version==="string"))return{key:Ue,problem:"expected {name, version}"};return}function jt(e){let t=e.notifications;return re(t)&&t.toolsListChanged===!0?{toolsListChanged:!0}:{}}function Ge(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 WeakMap,d=new Set,n=!1,f=(u={})=>({...u,[Et]:s});function v(u,y){return{jsonrpc:"2.0",id:u,result:{...y,resultType:"complete",_meta:f()}}}function q(u,y){let x=i.get(u);if(x===void 0)x=new ve(u.inputSchema,"2020-12",!1),i.set(u,x);let I=x.validate(y);if(I.valid)return;let r=I.errors.filter((m)=>m.keyword!=="properties"&&m.keyword!=="$ref").map((m)=>`${m.instanceLocation} ${m.error}`).slice(0,5).join("; ");return`Input validation error: Invalid arguments for tool ${u.name}: ${r||"the arguments do not match the schema"}`}function M(){return t.list().map((u)=>{let y={name:u.name};if(u.title!==void 0)y.title=u.title;y.description=u.description,y.inputSchema=u.inputSchema;let{annotations:x,meta:I}=ze(u.annotations);if(x!==void 0)y.annotations=x;if(I!==void 0)y._meta={[je]:I};return y})}async function J(u,y,x){let I=u.name;if(typeof I!=="string")return{invalid:"Invalid params: name must be a string"};let r=t.get(I);if(r===void 0)return{invalid:`Tool ${I} not found`};let m=u.arguments??{};if(!re(m))return{invalid:"Invalid params: arguments must be an object"};let w=e.client(x),R={id:++Pt,tool:r.name,arguments:Be(m),client:{...w}};if(r.title!==void 0)R.title=r.title;let T=Date.now();e.observe?.start(R);let[_,U]=await ne(r,m,y,w);return e.observe?.end({id:R.id,tool:r.name,client:{...w},outcome:_,result:Be(U),durationMs:Date.now()-T}),U}async function ne(u,y,x,I){let r=q(u,y);if(r!==void 0)return["error",ee(r)];if(u.annotations.consequentialHint===!0){let w={tool:{name:u.name,description:u.description},arguments:y,client:I,signal:x};if(u.title!==void 0)w.tool.title=u.title;let R=!1;try{R=await e.confirm(w)}catch{R=!1}if(!R)return[x.aborted?"cancelled":"declined",ee("The user declined")]}if(x.aborted)return["cancelled",ee("Cancelled")];let m;try{m=He(await u.execute(y,{signal:x,client:I}))}catch(w){m=Je(w)}if(x.aborted)return["cancelled",m];return[m.isError===!0?"error":"ok",m]}function G(u,y,x,I){let r=new ReadableStream({start:(m)=>{let w=(R)=>{if(x.aborted)return;let T;try{T=se(R)}catch{T=se(v(u,ee("The tool returned a result that is not JSON.")))}try{m.enqueue(T),m.close()}catch{}};J(y,x,I).then((R)=>w(typeof R.invalid==="string"?{jsonrpc:"2.0",id:u,error:{code:-32602,message:R.invalid}}:v(u,R)),()=>w({jsonrpc:"2.0",id:u,error:{code:-32603,message:"Internal error"}}))}});return new Response(r,{status:200,headers:De})}function C(u,y,x){let I=jt(y),r={jsonrpc:"2.0",id:u,result:{resultType:"complete",_meta:f({[Ie]:u})}},m,w=new ReadableStream({start:(R)=>{if(R.enqueue(se({jsonrpc:"2.0",method:"notifications/subscriptions/acknowledged",params:{notifications:I,_meta:{[Ie]:u}}})),Object.keys(I).length===0){R.enqueue(se(r)),R.close();return}let T={id:u,send:(_)=>{try{R.enqueue(se(_))}catch{d.delete(T)}},end:()=>{d.delete(T);try{R.enqueue(se(r)),R.close()}catch{}}};m=T,d.add(T),x.addEventListener("abort",()=>{d.delete(T);try{R.close()}catch{}})},cancel:()=>{if(m!==void 0)d.delete(m)}});return new Response(w,{status:200,headers:De})}function K(u,y){if(Array.isArray(y))return N(400,null,-32600,"Bad Request: JSON-RPC batches are not supported by this endpoint");if(!re(y)||y.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}=y;if(typeof x!=="string")return"result"in y||"error"in y?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"),m=u.headers.get("mcp-method"),w=re(y.params)?y.params:{},R=re(w._meta)?w._meta:void 0,T=R!==void 0&&X in R,_=typeof R?.[X]==="string"?R[X]:void 0,U=r!==null&&r>=te;if(I===void 0){if(_!==void 0&&r!==null&&r!==_)return D(null,r,`the notification envelope names protocol version ${_} but the MCP-Protocol-Version header names ${r}`);if((T||U)&&m!==null&&m!==x)return D(null,m,`the notification body names method ${x} but the Mcp-Method header names ${m}`);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 A=I;if(!T||x==="initialize"&&(_===void 0||_<te)){if(x==="initialize"){if(U)return D(A,r,"an initialize request (legacy handshake) was sent with a modern MCP-Protocol-Version header");let P=typeof w.protocolVersion==="string"?w.protocolVersion:void 0;return O(A,P)}if(U){let P=R===void 0?["_meta"]:[X];return N(400,A,-32602,`Invalid params: the MCP-Protocol-Version header names protocol revision ${r}, but the request is missing the required per-request envelope key(s): ${P.join(", ")}`,{envelope:{missing:P}})}return O(A,r??void 0)}let V=qt(R);if(V!==void 0)return N(400,A,-32602,`Invalid _meta envelope for protocol revision ${te}: ${V.key}: ${V.problem}`,{envelope:V});if(r!==null&&_!==void 0&&r!==_)return D(A,r,`the body envelope names protocol version ${_} but the MCP-Protocol-Version header names ${r}`);if(m!==null&&m!==x)return D(A,m,`the body names method ${x} but the Mcp-Method header names ${m}`);if(_!==te)return O(A,_);if(r===null)return D(A,"(missing)",`the body envelope names protocol version ${_} but the required MCP-Protocol-Version header is absent`);if(m===null)return D(A,"(missing)",`the body names method ${x} but the required Mcp-Method header is absent`);if(x==="tools/call"&&typeof w.name==="string"){let P=w.name,j=u.headers.get("mcp-name");if(j===null)return D(A,"(missing)",`the body carries params.name="${P}" but the required Mcp-Name header is absent`);let W=Nt(j);if(W===void 0)return D(A,j,"the Mcp-Name header carries an invalid Base64 sentinel value");if(W!==P)return D(A,j,`the body carries params.name="${P}" but the Mcp-Name header names "${W}"`)}return{id:A,method:x,params:w}}function O(u,y){return y===void 0?N(400,u,Ve,"Unsupported protocol version: the request did not name a protocol version",{supported:[te]}):N(400,u,Ve,`Unsupported protocol version: ${y}`,{supported:[te],requested:y})}async function Z(u,y){if(u.method.toUpperCase()!=="POST")return N(405,null,-32000,"Method not allowed.");if(!Ct(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(y.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:m,params:w}=I;switch(m){case"server/discover":{let R={supportedVersions:[te],capabilities:{tools:{listChanged:!0}}};if(o.instructions!==void 0)R.instructions=o.instructions;return R.ttlMs=0,R.cacheScope="private",Te(200,v(r,R))}case"tools/list":return Te(200,v(r,{tools:M(),ttlMs:0,cacheScope:"private"}));case"tools/call":return G(r,w,u.signal,y.grant);case"subscriptions/listen":return C(r,w,u.signal);default:return N(404,r,-32601,"Method not found")}}return{handle:(u,y)=>Z(u,y).catch(()=>N(500,null,-32603,"Internal server error")),toolsChanged(){if(n)return;n=!0,queueMicrotask(()=>{n=!1;for(let u of[...d])u.send({jsonrpc:"2.0",method:"notifications/tools/list_changed",params:{_meta:{[Ie]:u.id}}})})},close(){for(let u of[...d])u.end()}}}var $e="tab-mcp.v1";function ie(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}var E=(e)=>typeof e==="string";function Ke(e){if(!ie(e)||!E(e.grantId)||!E(e.createdAt))return!1;let t=e.client;return ie(t)&&E(t.id)&&E(t.name)&&E(t.host)}function zt(e){if(!ie(e))return!1;return["maxMessageBytes","maxBodyBytes","requestTimeoutMs","idleTimeoutMs","heartbeatMs","keepAliveMs","maxConcurrentRequests"].every((t)=>typeof e[t]==="number")}function Ht(e){return ie(e)&&Object.values(e).every(E)}function We(e){let t;try{t=JSON.parse(e)}catch{return}if(!ie(t))return;switch(t.type){case"session":return E(t.sessionId)&&E(t.address)&&E(t.origin)&&E(t.expiresAt)&&zt(t.limits)&&Array.isArray(t.grants)&&t.grants.every(Ke)&&(t.appName===void 0||E(t.appName))?t:void 0;case"ping":return typeof t.t==="number"?t:void 0;case"bye":return{type:"bye",reason:E(t.reason)?t.reason:""};case"http.request":return E(t.id)&&E(t.method)&&E(t.path)&&Ht(t.headers)&&E(t.body)&&ie(t.grant)&&E(t.grant.grantId)&&E(t.grant.clientId)?t:void 0;case"http.cancel":return E(t.id)?t:void 0;case"pairing.code":return E(t.code)&&E(t.expiresAt)?t:void 0;case"grant.added":return Ke(t.grant)?t:void 0;case"grant.removed":return E(t.grantId)?{type:"grant.removed",grantId:t.grantId,reason:E(t.reason)?t.reason:""}:void 0;case"error":return E(t.code)?t:void 0;default:return}}var Jt=15000,Ut={1000:"closed",1008:"policy",1009:"too_large",4001:"expired",4002:"idle",4003:"heartbeat",4004:"shutdown",4005:"replaced",4008:"rate_limited"},Vt={replaced:"replaced",expired:"expired",idle:"idle",shutdown:"shutdown"},Bt=["content-type","cache-control"];function Dt(){let e=globalThis.document?.title;return typeof e==="string"?e.slice(0,300):""}function Gt(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 Kt=new Set(["session","ping","bye","http.request","http.cancel","pairing.code","grant.added","grant.removed","error"]),Fe=512,Ze=6,Xe=64,Wt=Fe+Ze*Xe;function Yt(e){let t=Math.floor((e-Fe)/Ze);return t>=Xe?t:void 0}function*Ye(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 hr(e,t,o){let s=new WebSocket(t,$e),i=new Map,d="opening",n,f=65536,v,q=0,M,J,ne=new Promise((r,m)=>{M=r,J=m});ne.catch(()=>{});let G=setTimeout(()=>{u(Error("The relay did not answer in time."))},Jt),C=Ge({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 O(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(v),v=setTimeout(()=>{n??="heartbeat",y(4003);try{s.close()}catch{}},q*2.5)}function u(r){if(d!=="opening")return;y(0),J(r);try{s.close()}catch{}}function y(r){if(d==="closed")return;let m=d==="ready";d="closed",clearTimeout(G),clearTimeout(v),K();for(let w of i.values())w.abort();if(i.clear(),C.close(),m){let w=n??Ut[r]??(r===1006?"network":"closed");e.closed(w,r)}}async function x(r){let m=new AbortController;i.set(r.id,m);let w=()=>d==="ready"&&i.get(r.id)===m&&!m.signal.aborted;try{let R=new Request(`https://tab.invalid${r.path}`,{method:r.method,headers:r.headers,signal:m.signal}),T=await C.handle(R,{grant:r.grant,body:r.body});if(!w()){await T.body?.cancel().catch(()=>{});return}let _={};for(let P of Bt){let j=T.headers.get(P);if(j!==null)_[P]=j}if(!(_["content-type"]??"").startsWith("text/event-stream")||T.body===null){let P=await T.text();if(!w())return;if(P.length<=f){O({type:"http.response",id:r.id,status:T.status,headers:_,body:P});return}O({type:"http.response.start",id:r.id,status:T.status,headers:_});for(let j of Ye(P,f)){if(!w())break;O({type:"http.response.chunk",id:r.id,data:j})}if(w())O({type:"http.response.end",id:r.id});return}O({type:"http.response.start",id:r.id,status:T.status,headers:_});let A=T.body.getReader(),V=new TextDecoder;m.signal.addEventListener("abort",()=>{A.cancel().catch(()=>{})});for(;;){let{done:P,value:j}=await A.read();if(P||!w())break;let W=V.decode(j,{stream:!0});for(let de of Ye(W,f))O({type:"http.response.chunk",id:r.id,data:de})}if(w())O({type:"http.response.end",id:r.id})}catch(R){if(w())e.error(R instanceof Error?R:Error(String(R))),O({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)===m)i.delete(r.id)}}function I(r){if(d==="opening"){if(r.type==="session"){let m=Yt(r.limits.maxMessageBytes);if(m===void 0){u(Error(`The relay's message limit (${r.limits.maxMessageBytes} bytes) is too small; tab-mcp needs at least ${Wt}.`));return}f=m,d="ready",clearTimeout(G),q=r.limits.heartbeatMs,Z(),M(e.sessionStarted(r))}else if(r.type==="error")u(Error(`The relay refused the connection: ${r.message||r.code}`));else if(r.type==="bye")u(Error(`The relay ended the connection: ${r.reason}`));return}if(d!=="ready")return;switch(r.type){case"ping":Z(),O({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"bye":if(n=Vt[r.reason]??"closed",n==="replaced")e.replaced();return;case"error":e.error(Error(`Relay error ${r.code}: ${r.message}`));return;case"session":return}}return s.addEventListener("open",()=>{if(s.protocol!==""&&s.protocol!==$e){u(Error(`The relay speaks ${s.protocol}, not ${$e}.`));return}let r={type:"hello",library:e.library,page:{title:Dt()},secret:o};if(e.appName!==void 0)r.app={name:e.appName};O(r)}),s.addEventListener("message",(r)=>{if(typeof r.data!=="string")return;let m=We(r.data);if(m!==void 0){if(d==="ready")Z();I(m);return}let w=Gt(r.data);if(w?.id!==void 0)O(Kt.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",(r)=>{if(d==="opening"){y(r.code),J(Error(r.code===1006?"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}`:""}).`));return}y(r.code)}),{ready:ne,send:O,close(r){if(d==="closed")return;if(d==="opening"){u(new DOMException("The connection was cancelled","AbortError"));return}n=r,O({type:"bye",reason:"user"}),y(1000);try{s.close(1000,"bye")}catch{}}}}export{hr as openConnection};
|
|
8
|
+
|
|
9
|
+
//# debugId=B7FB94585F5A96F664756E2164756E21
|
|
10
|
+
//# sourceMappingURL=connection-5ehqkmw1.min.js.map
|