@dudko.dev/agent-web-react 0.0.28 → 0.0.30
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 +368 -24
- package/dist/{chunk-UUB7CE6N.js → chunk-EMF7DTGS.js} +69 -1
- package/dist/chunk-EMF7DTGS.js.map +1 -0
- package/dist/chunk-FXHQXIOU.js +94 -0
- package/dist/chunk-FXHQXIOU.js.map +1 -0
- package/dist/chunk-VMCWL6VH.js +294 -0
- package/dist/chunk-VMCWL6VH.js.map +1 -0
- package/dist/elicitation-CcZe5-EK.d.cts +1535 -0
- package/dist/elicitation-CcZe5-EK.d.ts +1535 -0
- package/dist/index.cjs +4360 -618
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +705 -433
- package/dist/index.d.ts +705 -433
- package/dist/index.js +4029 -628
- package/dist/index.js.map +1 -1
- package/dist/mcp-app-policy-DIUmGPJP.d.cts +55 -0
- package/dist/mcp-app-policy-DIUmGPJP.d.ts +55 -0
- package/dist/mcp-app-sandbox.cjs +313 -0
- package/dist/mcp-app-sandbox.cjs.map +1 -0
- package/dist/mcp-app-sandbox.d.cts +65 -0
- package/dist/mcp-app-sandbox.d.ts +65 -0
- package/dist/mcp-app-sandbox.js +201 -0
- package/dist/mcp-app-sandbox.js.map +1 -0
- package/dist/mcp.cjs +316 -42
- package/dist/mcp.cjs.map +1 -1
- package/dist/mcp.d.cts +195 -100
- package/dist/mcp.d.ts +195 -100
- package/dist/mcp.js +234 -46
- package/dist/mcp.js.map +1 -1
- package/dist/pipeline.cjs.map +1 -1
- package/dist/pipeline.js +1 -1
- package/dist/styles.css +1143 -1
- package/package.json +13 -3
- package/dist/chunk-UUB7CE6N.js.map +0 -1
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MCP_APP_POLICY_MAX_ORIGINS,
|
|
3
|
+
MCP_APP_POLICY_TOKEN_MAX_CHARS,
|
|
4
|
+
MCP_APP_SANDBOX_PROXY_READY,
|
|
5
|
+
MCP_APP_SANDBOX_RESOURCE_READY,
|
|
6
|
+
isMcpAppSandboxMessage,
|
|
7
|
+
mcpAppPolicy,
|
|
8
|
+
mcpAppPolicyOfToken,
|
|
9
|
+
mcpAppPolicyOrigin,
|
|
10
|
+
mcpAppPolicyToken
|
|
11
|
+
} from "./chunk-FXHQXIOU.js";
|
|
12
|
+
|
|
13
|
+
// src/mcp-app-sandbox.ts
|
|
14
|
+
var LABEL = "[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?";
|
|
15
|
+
var NAME = `${LABEL}(?:\\.${LABEL})+`;
|
|
16
|
+
var EXACT_HTTPS = new RegExp(`^https://${LABEL}(?:\\.${LABEL})*(?::\\d{1,5})?$`);
|
|
17
|
+
var EXACT_LOOPBACK = /^http:\/\/(?:localhost|127\.0\.0\.1)(?::\d{1,5})?$/;
|
|
18
|
+
var PATTERN = new RegExp(`^https://([a-z0-9-]{0,40})\\*([a-z0-9-]{0,40})\\.(${NAME})$`);
|
|
19
|
+
var parseMcpAppSandboxHosts = (value) => {
|
|
20
|
+
const entries = (typeof value === "string" ? value.split(/[\s,]+/) : [...value ?? []]).map((e) => typeof e === "string" ? e.trim() : "").filter(Boolean);
|
|
21
|
+
const hosts = { origins: [], patterns: [], frameAncestors: [], invalid: [] };
|
|
22
|
+
const ancestor = (source) => {
|
|
23
|
+
if (!hosts.frameAncestors.includes(source)) hosts.frameAncestors.push(source);
|
|
24
|
+
};
|
|
25
|
+
for (const raw of entries) {
|
|
26
|
+
const entry = raw.toLowerCase().replace(/\/$/, "");
|
|
27
|
+
const pattern = PATTERN.exec(entry);
|
|
28
|
+
if (pattern) {
|
|
29
|
+
const [, prefix, suffix, rest] = pattern;
|
|
30
|
+
if (!hosts.patterns.some((p) => p.prefix === prefix && p.suffix === suffix && p.rest === rest)) {
|
|
31
|
+
hosts.patterns.push({ prefix, suffix, rest });
|
|
32
|
+
}
|
|
33
|
+
ancestor(`https://*.${rest}`);
|
|
34
|
+
} else if (EXACT_HTTPS.test(entry) || EXACT_LOOPBACK.test(entry)) {
|
|
35
|
+
if (!hosts.origins.includes(entry)) hosts.origins.push(entry);
|
|
36
|
+
ancestor(entry);
|
|
37
|
+
} else {
|
|
38
|
+
hosts.invalid.push(raw.slice(0, 120));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return hosts;
|
|
42
|
+
};
|
|
43
|
+
var isMcpAppSandboxHost = (hosts, origin) => {
|
|
44
|
+
if (hosts.origins.includes(origin)) return true;
|
|
45
|
+
const head = "https://";
|
|
46
|
+
for (const p of hosts.patterns) {
|
|
47
|
+
const tail = `.${p.rest}`;
|
|
48
|
+
if (!origin.startsWith(head) || !origin.endsWith(tail)) continue;
|
|
49
|
+
const label = origin.slice(head.length, origin.length - tail.length);
|
|
50
|
+
if (label.length > 63 || !label.startsWith(p.prefix) || !label.endsWith(p.suffix)) continue;
|
|
51
|
+
const middle = label.slice(p.prefix.length, label.length - p.suffix.length);
|
|
52
|
+
if (/^[a-z0-9-]+$/.test(middle)) return true;
|
|
53
|
+
}
|
|
54
|
+
return false;
|
|
55
|
+
};
|
|
56
|
+
var MCP_APP_SANDBOX_SCRIPT = `(function () {
|
|
57
|
+
'use strict'
|
|
58
|
+
var READY = ${JSON.stringify(MCP_APP_SANDBOX_PROXY_READY)}
|
|
59
|
+
var RESOURCE = ${JSON.stringify(MCP_APP_SANDBOX_RESOURCE_READY)}
|
|
60
|
+
var RESERVED = 'ui/notifications/sandbox-'
|
|
61
|
+
var me = window
|
|
62
|
+
if (me.parent === me) return
|
|
63
|
+
var cfg
|
|
64
|
+
try {
|
|
65
|
+
cfg = JSON.parse(document.getElementById('mcp-app-sandbox-hosts').textContent)
|
|
66
|
+
} catch (e) {
|
|
67
|
+
return
|
|
68
|
+
}
|
|
69
|
+
var origins = cfg && Array.isArray(cfg.origins) ? cfg.origins : []
|
|
70
|
+
var patterns = cfg && Array.isArray(cfg.patterns) ? cfg.patterns : []
|
|
71
|
+
function allowed(origin) {
|
|
72
|
+
if (typeof origin !== 'string') return false
|
|
73
|
+
if (origins.indexOf(origin) >= 0) return true
|
|
74
|
+
for (var i = 0; i < patterns.length; i++) {
|
|
75
|
+
var p = patterns[i]
|
|
76
|
+
var head = 'https://'
|
|
77
|
+
var tail = '.' + p.rest
|
|
78
|
+
if (origin.indexOf(head) !== 0 || origin.length <= head.length + tail.length) continue
|
|
79
|
+
if (origin.slice(origin.length - tail.length) !== tail) continue
|
|
80
|
+
var label = origin.slice(head.length, origin.length - tail.length)
|
|
81
|
+
if (label.length > 63 || label.indexOf(p.prefix) !== 0) continue
|
|
82
|
+
if (label.slice(label.length - p.suffix.length) !== p.suffix) continue
|
|
83
|
+
if (/^[a-z0-9-]+$/.test(label.slice(p.prefix.length, label.length - p.suffix.length))) return true
|
|
84
|
+
}
|
|
85
|
+
return false
|
|
86
|
+
}
|
|
87
|
+
var ancestors = []
|
|
88
|
+
for (var w = me.parent; ancestors.length < 32; w = w.parent) {
|
|
89
|
+
ancestors.push(w)
|
|
90
|
+
if (w === w.parent) break
|
|
91
|
+
}
|
|
92
|
+
function ancestor(source) {
|
|
93
|
+
for (var i = 0; i < ancestors.length; i++) if (ancestors[i] === source) return true
|
|
94
|
+
return false
|
|
95
|
+
}
|
|
96
|
+
function reserved(d) {
|
|
97
|
+
return !!d && typeof d === 'object' && typeof d.method === 'string' && d.method.indexOf(RESERVED) === 0
|
|
98
|
+
}
|
|
99
|
+
var OWN = me.origin
|
|
100
|
+
var host = null
|
|
101
|
+
var hostOrigin = ''
|
|
102
|
+
var app = null
|
|
103
|
+
me.addEventListener('message', function (e) {
|
|
104
|
+
var d = e.data
|
|
105
|
+
if (app && e.source === app) {
|
|
106
|
+
if (e.origin !== OWN || reserved(d)) return
|
|
107
|
+
host.postMessage(d, hostOrigin)
|
|
108
|
+
return
|
|
109
|
+
}
|
|
110
|
+
if (host) {
|
|
111
|
+
if (e.source !== host || e.origin !== hostOrigin || reserved(d) || !app) return
|
|
112
|
+
app.postMessage(d, OWN)
|
|
113
|
+
return
|
|
114
|
+
}
|
|
115
|
+
if (!d || typeof d !== 'object' || d.jsonrpc !== '2.0' || d.method !== RESOURCE) return
|
|
116
|
+
if (!ancestor(e.source) || !allowed(e.origin)) return
|
|
117
|
+
var p = d.params
|
|
118
|
+
if (!p || typeof p !== 'object' || typeof p.html !== 'string') return
|
|
119
|
+
host = e.source
|
|
120
|
+
hostOrigin = e.origin
|
|
121
|
+
var frame = document.createElement('iframe')
|
|
122
|
+
frame.id = 'app'
|
|
123
|
+
frame.setAttribute('sandbox', 'allow-scripts allow-same-origin')
|
|
124
|
+
frame.setAttribute('referrerpolicy', 'no-referrer')
|
|
125
|
+
frame.setAttribute('title', 'MCP App')
|
|
126
|
+
document.body.appendChild(frame)
|
|
127
|
+
app = frame.contentWindow
|
|
128
|
+
var doc = frame.contentDocument
|
|
129
|
+
doc.open()
|
|
130
|
+
doc.write(p.html)
|
|
131
|
+
doc.close()
|
|
132
|
+
})
|
|
133
|
+
var ready = { jsonrpc: '2.0', method: READY, params: {} }
|
|
134
|
+
for (var i = 0; i < ancestors.length; i++) ancestors[i].postMessage(ready, '*')
|
|
135
|
+
})()`;
|
|
136
|
+
var json = (value) => JSON.stringify(value).replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/&/g, "\\u0026");
|
|
137
|
+
var mcpAppSandboxPage = (hosts) => `<!doctype html><html><head><meta charset="utf-8"><meta name="robots" content="noindex"><title>MCP App sandbox</title><style>html,body{margin:0;height:100%;overflow:hidden;background:transparent}iframe{display:block;border:0;width:100%;height:100%}</style></head><body><script type="application/json" id="mcp-app-sandbox-hosts">${json({
|
|
138
|
+
origins: hosts.origins,
|
|
139
|
+
patterns: hosts.patterns
|
|
140
|
+
})}</script><script>${MCP_APP_SANDBOX_SCRIPT}</script></body></html>`;
|
|
141
|
+
var MCP_APP_SANDBOX_PERMISSIONS_POLICY = "camera=(), microphone=(), geolocation=(), display-capture=(), payment=(), usb=(), serial=(), midi=()";
|
|
142
|
+
var COMMON = {
|
|
143
|
+
"X-Content-Type-Options": "nosniff",
|
|
144
|
+
"X-Robots-Tag": "noindex, nofollow",
|
|
145
|
+
"Referrer-Policy": "no-referrer",
|
|
146
|
+
"Cache-Control": "no-store"
|
|
147
|
+
};
|
|
148
|
+
var mcpAppSandboxHeaders = (policy, hosts) => ({
|
|
149
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
150
|
+
"Content-Security-Policy": `${mcpAppPolicy(policy)}; frame-ancestors ${hosts.frameAncestors.length > 0 ? hosts.frameAncestors.join(" ") : "'none'"}`,
|
|
151
|
+
"Permissions-Policy": MCP_APP_SANDBOX_PERMISSIONS_POLICY,
|
|
152
|
+
...COMMON
|
|
153
|
+
});
|
|
154
|
+
var plain = (status, text, extra = {}) => new Response(text, {
|
|
155
|
+
status,
|
|
156
|
+
headers: {
|
|
157
|
+
"Content-Type": "text/plain; charset=utf-8",
|
|
158
|
+
"Content-Security-Policy": "default-src 'none'; frame-ancestors 'none'",
|
|
159
|
+
...COMMON,
|
|
160
|
+
...extra
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
var mcpAppSandboxResponse = (request, options) => {
|
|
164
|
+
const { pathname } = new URL(request.url);
|
|
165
|
+
const base = options.path.replace(/\/+$/, "");
|
|
166
|
+
if (!pathname.startsWith(`${base}/`)) return plain(404, "Not found");
|
|
167
|
+
const token = pathname.slice(base.length + 1);
|
|
168
|
+
if (token.length === 0 || token.includes("/")) return plain(404, "Not found");
|
|
169
|
+
if (request.method !== "GET" && request.method !== "HEAD") {
|
|
170
|
+
return plain(405, "Method not allowed", { Allow: "GET, HEAD" });
|
|
171
|
+
}
|
|
172
|
+
const policy = mcpAppPolicyOfToken(token);
|
|
173
|
+
if (!policy) return plain(400, "Not a policy this sandbox serves");
|
|
174
|
+
const hosts = parseMcpAppSandboxHosts(options.hosts);
|
|
175
|
+
if (hosts.invalid.length > 0 || hosts.frameAncestors.length === 0) {
|
|
176
|
+
return plain(503, "This sandbox has no valid allowed host origins");
|
|
177
|
+
}
|
|
178
|
+
return new Response(request.method === "HEAD" ? null : mcpAppSandboxPage(hosts), {
|
|
179
|
+
status: 200,
|
|
180
|
+
headers: mcpAppSandboxHeaders(policy, hosts)
|
|
181
|
+
});
|
|
182
|
+
};
|
|
183
|
+
export {
|
|
184
|
+
MCP_APP_POLICY_MAX_ORIGINS,
|
|
185
|
+
MCP_APP_POLICY_TOKEN_MAX_CHARS,
|
|
186
|
+
MCP_APP_SANDBOX_PERMISSIONS_POLICY,
|
|
187
|
+
MCP_APP_SANDBOX_PROXY_READY,
|
|
188
|
+
MCP_APP_SANDBOX_RESOURCE_READY,
|
|
189
|
+
MCP_APP_SANDBOX_SCRIPT,
|
|
190
|
+
isMcpAppSandboxHost,
|
|
191
|
+
isMcpAppSandboxMessage,
|
|
192
|
+
mcpAppPolicy,
|
|
193
|
+
mcpAppPolicyOfToken,
|
|
194
|
+
mcpAppPolicyOrigin,
|
|
195
|
+
mcpAppPolicyToken,
|
|
196
|
+
mcpAppSandboxHeaders,
|
|
197
|
+
mcpAppSandboxPage,
|
|
198
|
+
mcpAppSandboxResponse,
|
|
199
|
+
parseMcpAppSandboxHosts
|
|
200
|
+
};
|
|
201
|
+
//# sourceMappingURL=mcp-app-sandbox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/mcp-app-sandbox.ts"],"sourcesContent":["import {\n isMcpAppSandboxMessage,\n MCP_APP_POLICY_MAX_ORIGINS,\n MCP_APP_POLICY_TOKEN_MAX_CHARS,\n MCP_APP_SANDBOX_PROXY_READY,\n MCP_APP_SANDBOX_RESOURCE_READY,\n mcpAppPolicy,\n mcpAppPolicyOfToken,\n mcpAppPolicyOrigin,\n mcpAppPolicyToken,\n type McpAppPolicyOrigins,\n} from './mcp-app-policy.js'\n\n/**\n * The `./mcp-app-sandbox` entry: the MCP Apps sandbox proxy - the page a host serves on ANOTHER\n * origin, so that an app runs on an origin of its own (storage, cookies, a real `Origin`) and not\n * in an opaque one. Framework-free, no imports but `mcp-app-policy.ts`: a Cloudflare Worker, Deno,\n * Bun or Node (18+) serves it with `mcpAppSandboxResponse` (Request in, Response out).\n *\n * The page, `<base>/<policy>` (`<policy>` = `mcpAppPolicyToken`):\n *\n * 1. Its response carries the app's policy as a HEADER, built from the path (`mcpAppPolicy`), plus\n * `frame-ancestors` = the allowed host origins. The app's document is written into a frame\n * the page creates (`about:blank`, `document.write`), which INHERITS that policy - nothing the\n * app's markup says comes before it, and every document the app can reach on this origin\n * (this page, a reload of it, a frame of it) has a policy some host chose for that frame.\n * 2. Its script binds to the first ANCESTOR window on an allowed host origin that sends it\n * `ui/notifications/sandbox-resource-ready`, once; after that it relays the extension's\n * messages between that window (to its exact origin) and the app's window (to this origin),\n * never the `ui/notifications/sandbox-*` ones, and creates nothing else. It asks for\n * `ui/notifications/sandbox-proxy-ready` with a content-free message to every ancestor.\n * 3. The app's frame: `sandbox=\"allow-scripts allow-same-origin\"`, no `allow` attribute. The app\n * is same-origin with this page and can reach it - which is why the boundary is not here but\n * in what the HOST draws around it (the frame's sandbox, the shell's `frame-src` pinned to\n * this URL) and in the policy header above. A `sandbox`, `csp` or `permissions` the host sends\n * is ignored: the header is the policy, and no permission is ever granted.\n */\n\nexport {\n isMcpAppSandboxMessage,\n MCP_APP_POLICY_MAX_ORIGINS,\n MCP_APP_POLICY_TOKEN_MAX_CHARS,\n MCP_APP_SANDBOX_PROXY_READY,\n MCP_APP_SANDBOX_RESOURCE_READY,\n mcpAppPolicy,\n mcpAppPolicyOfToken,\n mcpAppPolicyOrigin,\n mcpAppPolicyToken,\n}\nexport type { McpAppPolicyOrigins }\n\n/** A host origin pattern: `https://<prefix>*<suffix>.<rest>`, `*` one run of `[a-z0-9-]`. */\nexport interface McpAppSandboxHostPattern {\n prefix: string\n suffix: string\n /** The rest of the host name after the first label: two labels at least. */\n rest: string\n}\n\n/** The host origins a sandbox page answers, as `parseMcpAppSandboxHosts` reads them. */\nexport interface McpAppSandboxHosts {\n /** Exact origins (`https://agent.example.com`, `http://127.0.0.1:4173`). */\n origins: string[]\n /** One-label patterns (`https://*-agents.example.workers.dev`). */\n patterns: McpAppSandboxHostPattern[]\n /** The same as `frame-ancestors` sources (a pattern widened to `https://*.<rest>`). */\n frameAncestors: string[]\n /** Entries that are neither: a sandbox with any of these refuses to serve (503). */\n invalid: string[]\n}\n\nconst LABEL = '[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?'\nconst NAME = `${LABEL}(?:\\\\.${LABEL})+`\nconst EXACT_HTTPS = new RegExp(`^https://${LABEL}(?:\\\\.${LABEL})*(?::\\\\d{1,5})?$`)\nconst EXACT_LOOPBACK = /^http:\\/\\/(?:localhost|127\\.0\\.0\\.1)(?::\\d{1,5})?$/\nconst PATTERN = new RegExp(`^https://([a-z0-9-]{0,40})\\\\*([a-z0-9-]{0,40})\\\\.(${NAME})$`)\n\n/**\n * The allowed host origins, from a list or a space / comma separated string (a deploy-time\n * setting, e.g. `ALLOWED_HOST_ORIGINS=\"https://agent.example.com https://*-agents.example.workers.dev\"`).\n * An entry is an exact origin - `https://`, or `http://` on `localhost` / `127.0.0.1` - or a\n * pattern with ONE `*` inside the first label of an `https://` host. The page's script holds the\n * pattern to one label (`[a-z0-9-]+`, no dot); `frame-ancestors` cannot say that, so there the\n * pattern is widened to `https://*.<rest>` (every subdomain of `<rest>`). Anything else is\n * `invalid`.\n */\nexport const parseMcpAppSandboxHosts = (\n value: string | readonly string[] | undefined,\n): McpAppSandboxHosts => {\n const entries = (typeof value === 'string' ? value.split(/[\\s,]+/) : [...(value ?? [])])\n .map((e) => (typeof e === 'string' ? e.trim() : ''))\n .filter(Boolean)\n const hosts: McpAppSandboxHosts = { origins: [], patterns: [], frameAncestors: [], invalid: [] }\n const ancestor = (source: string) => {\n if (!hosts.frameAncestors.includes(source)) hosts.frameAncestors.push(source)\n }\n for (const raw of entries) {\n const entry = raw.toLowerCase().replace(/\\/$/, '')\n const pattern = PATTERN.exec(entry)\n if (pattern) {\n const [, prefix, suffix, rest] = pattern\n if (\n !hosts.patterns.some((p) => p.prefix === prefix && p.suffix === suffix && p.rest === rest)\n ) {\n hosts.patterns.push({ prefix, suffix, rest })\n }\n ancestor(`https://*.${rest}`)\n } else if (EXACT_HTTPS.test(entry) || EXACT_LOOPBACK.test(entry)) {\n if (!hosts.origins.includes(entry)) hosts.origins.push(entry)\n ancestor(entry)\n } else {\n hosts.invalid.push(raw.slice(0, 120))\n }\n }\n return hosts\n}\n\n/** Whether an origin is one of the hosts (the same rule the page's script applies). */\nexport const isMcpAppSandboxHost = (hosts: McpAppSandboxHosts, origin: string): boolean => {\n if (hosts.origins.includes(origin)) return true\n const head = 'https://'\n for (const p of hosts.patterns) {\n const tail = `.${p.rest}`\n if (!origin.startsWith(head) || !origin.endsWith(tail)) continue\n const label = origin.slice(head.length, origin.length - tail.length)\n if (label.length > 63 || !label.startsWith(p.prefix) || !label.endsWith(p.suffix)) continue\n const middle = label.slice(p.prefix.length, label.length - p.suffix.length)\n if (/^[a-z0-9-]+$/.test(middle)) return true\n }\n return false\n}\n\n/**\n * The page's script (inline; it runs under the app's own policy, which allows inline scripts).\n * It reads the hosts from `#mcp-app-sandbox-hosts`, binds to the first allowed ancestor that sends\n * the resource, writes the app into its frame, and relays - see the entry's comment.\n */\nexport const MCP_APP_SANDBOX_SCRIPT = `(function () {\n 'use strict'\n var READY = ${JSON.stringify(MCP_APP_SANDBOX_PROXY_READY)}\n var RESOURCE = ${JSON.stringify(MCP_APP_SANDBOX_RESOURCE_READY)}\n var RESERVED = 'ui/notifications/sandbox-'\n var me = window\n if (me.parent === me) return\n var cfg\n try {\n cfg = JSON.parse(document.getElementById('mcp-app-sandbox-hosts').textContent)\n } catch (e) {\n return\n }\n var origins = cfg && Array.isArray(cfg.origins) ? cfg.origins : []\n var patterns = cfg && Array.isArray(cfg.patterns) ? cfg.patterns : []\n function allowed(origin) {\n if (typeof origin !== 'string') return false\n if (origins.indexOf(origin) >= 0) return true\n for (var i = 0; i < patterns.length; i++) {\n var p = patterns[i]\n var head = 'https://'\n var tail = '.' + p.rest\n if (origin.indexOf(head) !== 0 || origin.length <= head.length + tail.length) continue\n if (origin.slice(origin.length - tail.length) !== tail) continue\n var label = origin.slice(head.length, origin.length - tail.length)\n if (label.length > 63 || label.indexOf(p.prefix) !== 0) continue\n if (label.slice(label.length - p.suffix.length) !== p.suffix) continue\n if (/^[a-z0-9-]+$/.test(label.slice(p.prefix.length, label.length - p.suffix.length))) return true\n }\n return false\n }\n var ancestors = []\n for (var w = me.parent; ancestors.length < 32; w = w.parent) {\n ancestors.push(w)\n if (w === w.parent) break\n }\n function ancestor(source) {\n for (var i = 0; i < ancestors.length; i++) if (ancestors[i] === source) return true\n return false\n }\n function reserved(d) {\n return !!d && typeof d === 'object' && typeof d.method === 'string' && d.method.indexOf(RESERVED) === 0\n }\n var OWN = me.origin\n var host = null\n var hostOrigin = ''\n var app = null\n me.addEventListener('message', function (e) {\n var d = e.data\n if (app && e.source === app) {\n if (e.origin !== OWN || reserved(d)) return\n host.postMessage(d, hostOrigin)\n return\n }\n if (host) {\n if (e.source !== host || e.origin !== hostOrigin || reserved(d) || !app) return\n app.postMessage(d, OWN)\n return\n }\n if (!d || typeof d !== 'object' || d.jsonrpc !== '2.0' || d.method !== RESOURCE) return\n if (!ancestor(e.source) || !allowed(e.origin)) return\n var p = d.params\n if (!p || typeof p !== 'object' || typeof p.html !== 'string') return\n host = e.source\n hostOrigin = e.origin\n var frame = document.createElement('iframe')\n frame.id = 'app'\n frame.setAttribute('sandbox', 'allow-scripts allow-same-origin')\n frame.setAttribute('referrerpolicy', 'no-referrer')\n frame.setAttribute('title', 'MCP App')\n document.body.appendChild(frame)\n app = frame.contentWindow\n var doc = frame.contentDocument\n doc.open()\n doc.write(p.html)\n doc.close()\n })\n var ready = { jsonrpc: '2.0', method: READY, params: {} }\n for (var i = 0; i < ancestors.length; i++) ancestors[i].postMessage(ready, '*')\n})()`\n\nconst json = (value: unknown): string =>\n JSON.stringify(value).replace(/</g, '\\\\u003c').replace(/>/g, '\\\\u003e').replace(/&/g, '\\\\u0026')\n\n/** The page: the hosts as data, the script. Serve it with `mcpAppSandboxHeaders`. */\nexport const mcpAppSandboxPage = (hosts: McpAppSandboxHosts): string =>\n '<!doctype html><html><head><meta charset=\"utf-8\"><meta name=\"robots\" content=\"noindex\">' +\n '<title>MCP App sandbox</title>' +\n '<style>html,body{margin:0;height:100%;overflow:hidden;background:transparent}' +\n 'iframe{display:block;border:0;width:100%;height:100%}</style></head><body>' +\n `<script type=\"application/json\" id=\"mcp-app-sandbox-hosts\">${json({\n origins: hosts.origins,\n patterns: hosts.patterns,\n })}</script>` +\n `<script>${MCP_APP_SANDBOX_SCRIPT}</script></body></html>`\n\n/** Browser features the page and the app may never use, whatever an app asks for. */\nexport const MCP_APP_SANDBOX_PERMISSIONS_POLICY =\n 'camera=(), microphone=(), geolocation=(), display-capture=(), payment=(), usb=(), serial=(), midi=()'\n\nconst COMMON = {\n 'X-Content-Type-Options': 'nosniff',\n 'X-Robots-Tag': 'noindex, nofollow',\n 'Referrer-Policy': 'no-referrer',\n 'Cache-Control': 'no-store',\n}\n\n/**\n * The page's response headers: the app's policy AND `frame-ancestors` (the hosts; `'none'` when\n * there are none), `nosniff`, `no-store` (a policy is never served from a stale copy), no referrer,\n * `noindex`, and a Permissions-Policy that grants nothing.\n */\nexport const mcpAppSandboxHeaders = (\n policy: McpAppPolicyOrigins,\n hosts: McpAppSandboxHosts,\n): Record<string, string> => ({\n 'Content-Type': 'text/html; charset=utf-8',\n 'Content-Security-Policy': `${mcpAppPolicy(policy)}; frame-ancestors ${\n hosts.frameAncestors.length > 0 ? hosts.frameAncestors.join(' ') : \"'none'\"\n }`,\n 'Permissions-Policy': MCP_APP_SANDBOX_PERMISSIONS_POLICY,\n ...COMMON,\n})\n\nexport interface McpAppSandboxServeOptions {\n /** Where the pages are: `'/sandbox/v1'` serves `/sandbox/v1/<policy>`. */\n path: string\n /** The host origins that may frame the page and send it an app (see `parseMcpAppSandboxHosts`). */\n hosts: string | readonly string[] | undefined\n}\n\nconst plain = (status: number, text: string, extra: Record<string, string> = {}): Response =>\n new Response(text, {\n status,\n headers: {\n 'Content-Type': 'text/plain; charset=utf-8',\n 'Content-Security-Policy': \"default-src 'none'; frame-ancestors 'none'\",\n ...COMMON,\n ...extra,\n },\n })\n\n/**\n * A fetch handler for the sandbox page: `GET` / `HEAD` of `<path>/<policy>` is the page, with its\n * headers; a token that is not exactly what `mcpAppPolicyToken` writes is 400; another method 405;\n * any other path 404; no valid host origin (or an invalid entry in the setting) 503 - a sandbox\n * nobody may frame is a configuration error, not a page.\n */\nexport const mcpAppSandboxResponse = (\n request: Request,\n options: McpAppSandboxServeOptions,\n): Response => {\n const { pathname } = new URL(request.url)\n const base = options.path.replace(/\\/+$/, '')\n if (!pathname.startsWith(`${base}/`)) return plain(404, 'Not found')\n const token = pathname.slice(base.length + 1)\n if (token.length === 0 || token.includes('/')) return plain(404, 'Not found')\n if (request.method !== 'GET' && request.method !== 'HEAD') {\n return plain(405, 'Method not allowed', { Allow: 'GET, HEAD' })\n }\n const policy = mcpAppPolicyOfToken(token)\n if (!policy) return plain(400, 'Not a policy this sandbox serves')\n const hosts = parseMcpAppSandboxHosts(options.hosts)\n if (hosts.invalid.length > 0 || hosts.frameAncestors.length === 0) {\n return plain(503, 'This sandbox has no valid allowed host origins')\n }\n return new Response(request.method === 'HEAD' ? null : mcpAppSandboxPage(hosts), {\n status: 200,\n headers: mcpAppSandboxHeaders(policy, hosts),\n })\n}\n"],"mappings":";;;;;;;;;;;;;AAuEA,IAAM,QAAQ;AACd,IAAM,OAAO,GAAG,KAAK,SAAS,KAAK;AACnC,IAAM,cAAc,IAAI,OAAO,YAAY,KAAK,SAAS,KAAK,mBAAmB;AACjF,IAAM,iBAAiB;AACvB,IAAM,UAAU,IAAI,OAAO,qDAAqD,IAAI,IAAI;AAWjF,IAAM,0BAA0B,CACrC,UACuB;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