@dudko.dev/agent-web-react 0.0.42 → 0.0.43
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 +4 -2
- package/dist/{chunk-FXHQXIOU.js → chunk-AWZ2OZSG.js} +6 -2
- package/dist/chunk-AWZ2OZSG.js.map +1 -0
- package/dist/{elicitation-Dp6Fi6ZA.d.ts → elicitation-B5t9hdaJ.d.cts} +9 -3
- package/dist/{elicitation-Dp6Fi6ZA.d.cts → elicitation-rJu93Z3o.d.ts} +9 -3
- package/dist/index.cjs +852 -554
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +131 -8
- package/dist/index.d.ts +131 -8
- package/dist/index.js +701 -412
- package/dist/index.js.map +1 -1
- package/dist/{mcp-app-policy-DIUmGPJP.d.cts → mcp-app-policy-BhBIsbBy.d.cts} +20 -2
- package/dist/{mcp-app-policy-DIUmGPJP.d.ts → mcp-app-policy-BhBIsbBy.d.ts} +20 -2
- package/dist/mcp-app-sandbox.cjs +17 -7
- package/dist/mcp-app-sandbox.cjs.map +1 -1
- package/dist/mcp-app-sandbox.d.cts +11 -6
- package/dist/mcp-app-sandbox.d.ts +11 -6
- package/dist/mcp-app-sandbox.js +15 -7
- package/dist/mcp-app-sandbox.js.map +1 -1
- package/dist/mcp.d.cts +3 -2
- package/dist/mcp.d.ts +3 -2
- package/dist/styles.css +99 -6
- package/package.json +3 -3
- package/dist/chunk-FXHQXIOU.js.map +0 -1
|
@@ -12,6 +12,18 @@ declare const MCP_APP_SANDBOX_PROXY_READY = "ui/notifications/sandbox-proxy-read
|
|
|
12
12
|
declare const MCP_APP_SANDBOX_RESOURCE_READY = "ui/notifications/sandbox-resource-ready";
|
|
13
13
|
/** The specification reserves these between a host and its proxy: never relayed to or from an app. */
|
|
14
14
|
declare const isMcpAppSandboxMessage: (data: unknown) => boolean;
|
|
15
|
+
/**
|
|
16
|
+
* The colour scheme of an app's frame: the theme the app is told when its frame is drawn. Every
|
|
17
|
+
* document between the page and the app declares it (the frame element, the shell, the sandbox
|
|
18
|
+
* page and its frame), because a browser paints an OPAQUE canvas - the canvas colour of the
|
|
19
|
+
* embedded document's own scheme - behind a document whose scheme differs from its frame
|
|
20
|
+
* element's: an app that is dark with a transparent body was drawn on white.
|
|
21
|
+
*/
|
|
22
|
+
type McpAppColorScheme = 'light' | 'dark';
|
|
23
|
+
/** The query parameter of the sandbox page that carries the scheme (`?scheme=dark`). */
|
|
24
|
+
declare const MCP_APP_SCHEME_PARAM = "scheme";
|
|
25
|
+
/** `light` or `dark` exactly; anything else is no scheme (nothing is declared). */
|
|
26
|
+
declare const mcpAppColorScheme: (value: unknown) => McpAppColorScheme | undefined;
|
|
15
27
|
/** The origins an app's policy grants, each already an origin (`mcpAppPolicyOrigin`). */
|
|
16
28
|
interface McpAppPolicyOrigins {
|
|
17
29
|
/** `fetch` / XHR / WebSocket (`connect-src`). */
|
|
@@ -24,6 +36,12 @@ interface McpAppPolicyOrigins {
|
|
|
24
36
|
* network ONLY where the resource declared it. Nested frames, workers, plugins, forms and `<base>`
|
|
25
37
|
* are refused whatever was declared (a frame the app may embed would also be a place it may
|
|
26
38
|
* navigate itself to). The lists must already be checked origins: nothing here re-checks them.
|
|
39
|
+
*
|
|
40
|
+
* `'wasm-unsafe-eval'` lets the app compile WebAssembly (a tracer, a codec, a parser), which the
|
|
41
|
+
* specification's default policy leaves out and a server cannot ask for (it declares origins, not
|
|
42
|
+
* keywords). It adds no reach: a module only calls what the app's own script hands it, and the
|
|
43
|
+
* network stays `connect-src`. `eval`, `new Function` and string timers stay refused - that is
|
|
44
|
+
* `'unsafe-eval'`, which is never granted.
|
|
27
45
|
*/
|
|
28
46
|
declare const mcpAppPolicy: ({ connect, resources }: McpAppPolicyOrigins) => string;
|
|
29
47
|
/**
|
|
@@ -51,5 +69,5 @@ declare const mcpAppPolicyToken: ({ connect, resources, }: McpAppPolicyOrigins)
|
|
|
51
69
|
*/
|
|
52
70
|
declare const mcpAppPolicyOfToken: (token: unknown) => McpAppPolicyOrigins | undefined;
|
|
53
71
|
|
|
54
|
-
export { MCP_APP_POLICY_TOKEN_MAX_CHARS as M, MCP_APP_SANDBOX_PROXY_READY as a, MCP_APP_SANDBOX_RESOURCE_READY as b,
|
|
55
|
-
export type { McpAppPolicyOrigins as
|
|
72
|
+
export { MCP_APP_POLICY_TOKEN_MAX_CHARS as M, MCP_APP_SANDBOX_PROXY_READY as a, MCP_APP_SANDBOX_RESOURCE_READY as b, MCP_APP_SCHEME_PARAM as c, mcpAppPolicyToken as e, MCP_APP_POLICY_MAX_ORIGINS as g, mcpAppPolicy as h, isMcpAppSandboxMessage as i, mcpAppPolicyOfToken as j, mcpAppPolicyOrigin as k, mcpAppColorScheme as m };
|
|
73
|
+
export type { McpAppColorScheme as d, McpAppPolicyOrigins as f };
|
|
@@ -12,6 +12,18 @@ declare const MCP_APP_SANDBOX_PROXY_READY = "ui/notifications/sandbox-proxy-read
|
|
|
12
12
|
declare const MCP_APP_SANDBOX_RESOURCE_READY = "ui/notifications/sandbox-resource-ready";
|
|
13
13
|
/** The specification reserves these between a host and its proxy: never relayed to or from an app. */
|
|
14
14
|
declare const isMcpAppSandboxMessage: (data: unknown) => boolean;
|
|
15
|
+
/**
|
|
16
|
+
* The colour scheme of an app's frame: the theme the app is told when its frame is drawn. Every
|
|
17
|
+
* document between the page and the app declares it (the frame element, the shell, the sandbox
|
|
18
|
+
* page and its frame), because a browser paints an OPAQUE canvas - the canvas colour of the
|
|
19
|
+
* embedded document's own scheme - behind a document whose scheme differs from its frame
|
|
20
|
+
* element's: an app that is dark with a transparent body was drawn on white.
|
|
21
|
+
*/
|
|
22
|
+
type McpAppColorScheme = 'light' | 'dark';
|
|
23
|
+
/** The query parameter of the sandbox page that carries the scheme (`?scheme=dark`). */
|
|
24
|
+
declare const MCP_APP_SCHEME_PARAM = "scheme";
|
|
25
|
+
/** `light` or `dark` exactly; anything else is no scheme (nothing is declared). */
|
|
26
|
+
declare const mcpAppColorScheme: (value: unknown) => McpAppColorScheme | undefined;
|
|
15
27
|
/** The origins an app's policy grants, each already an origin (`mcpAppPolicyOrigin`). */
|
|
16
28
|
interface McpAppPolicyOrigins {
|
|
17
29
|
/** `fetch` / XHR / WebSocket (`connect-src`). */
|
|
@@ -24,6 +36,12 @@ interface McpAppPolicyOrigins {
|
|
|
24
36
|
* network ONLY where the resource declared it. Nested frames, workers, plugins, forms and `<base>`
|
|
25
37
|
* are refused whatever was declared (a frame the app may embed would also be a place it may
|
|
26
38
|
* navigate itself to). The lists must already be checked origins: nothing here re-checks them.
|
|
39
|
+
*
|
|
40
|
+
* `'wasm-unsafe-eval'` lets the app compile WebAssembly (a tracer, a codec, a parser), which the
|
|
41
|
+
* specification's default policy leaves out and a server cannot ask for (it declares origins, not
|
|
42
|
+
* keywords). It adds no reach: a module only calls what the app's own script hands it, and the
|
|
43
|
+
* network stays `connect-src`. `eval`, `new Function` and string timers stay refused - that is
|
|
44
|
+
* `'unsafe-eval'`, which is never granted.
|
|
27
45
|
*/
|
|
28
46
|
declare const mcpAppPolicy: ({ connect, resources }: McpAppPolicyOrigins) => string;
|
|
29
47
|
/**
|
|
@@ -51,5 +69,5 @@ declare const mcpAppPolicyToken: ({ connect, resources, }: McpAppPolicyOrigins)
|
|
|
51
69
|
*/
|
|
52
70
|
declare const mcpAppPolicyOfToken: (token: unknown) => McpAppPolicyOrigins | undefined;
|
|
53
71
|
|
|
54
|
-
export { MCP_APP_POLICY_TOKEN_MAX_CHARS as M, MCP_APP_SANDBOX_PROXY_READY as a, MCP_APP_SANDBOX_RESOURCE_READY as b,
|
|
55
|
-
export type { McpAppPolicyOrigins as
|
|
72
|
+
export { MCP_APP_POLICY_TOKEN_MAX_CHARS as M, MCP_APP_SANDBOX_PROXY_READY as a, MCP_APP_SANDBOX_RESOURCE_READY as b, MCP_APP_SCHEME_PARAM as c, mcpAppPolicyToken as e, MCP_APP_POLICY_MAX_ORIGINS as g, mcpAppPolicy as h, isMcpAppSandboxMessage as i, mcpAppPolicyOfToken as j, mcpAppPolicyOrigin as k, mcpAppColorScheme as m };
|
|
73
|
+
export type { McpAppColorScheme as d, McpAppPolicyOrigins as f };
|
package/dist/mcp-app-sandbox.cjs
CHANGED
|
@@ -26,8 +26,10 @@ __export(mcp_app_sandbox_exports, {
|
|
|
26
26
|
MCP_APP_SANDBOX_PROXY_READY: () => MCP_APP_SANDBOX_PROXY_READY,
|
|
27
27
|
MCP_APP_SANDBOX_RESOURCE_READY: () => MCP_APP_SANDBOX_RESOURCE_READY,
|
|
28
28
|
MCP_APP_SANDBOX_SCRIPT: () => MCP_APP_SANDBOX_SCRIPT,
|
|
29
|
+
MCP_APP_SCHEME_PARAM: () => MCP_APP_SCHEME_PARAM,
|
|
29
30
|
isMcpAppSandboxHost: () => isMcpAppSandboxHost,
|
|
30
31
|
isMcpAppSandboxMessage: () => isMcpAppSandboxMessage,
|
|
32
|
+
mcpAppColorScheme: () => mcpAppColorScheme,
|
|
31
33
|
mcpAppPolicy: () => mcpAppPolicy,
|
|
32
34
|
mcpAppPolicyOfToken: () => mcpAppPolicyOfToken,
|
|
33
35
|
mcpAppPolicyOrigin: () => mcpAppPolicyOrigin,
|
|
@@ -43,11 +45,13 @@ module.exports = __toCommonJS(mcp_app_sandbox_exports);
|
|
|
43
45
|
var MCP_APP_SANDBOX_PROXY_READY = "ui/notifications/sandbox-proxy-ready";
|
|
44
46
|
var MCP_APP_SANDBOX_RESOURCE_READY = "ui/notifications/sandbox-resource-ready";
|
|
45
47
|
var isMcpAppSandboxMessage = (data) => typeof data === "object" && data !== null && typeof data.method === "string" && data.method.startsWith("ui/notifications/sandbox-");
|
|
48
|
+
var MCP_APP_SCHEME_PARAM = "scheme";
|
|
49
|
+
var mcpAppColorScheme = (value) => value === "light" || value === "dark" ? value : void 0;
|
|
46
50
|
var mcpAppPolicy = ({ connect, resources }) => {
|
|
47
51
|
const from = resources.length > 0 ? ` ${resources.join(" ")}` : "";
|
|
48
52
|
return [
|
|
49
53
|
"default-src 'none'",
|
|
50
|
-
`script-src 'unsafe-inline'${from}`,
|
|
54
|
+
`script-src 'unsafe-inline' 'wasm-unsafe-eval'${from}`,
|
|
51
55
|
`style-src 'unsafe-inline'${from}`,
|
|
52
56
|
`img-src data: blob:${from}`,
|
|
53
57
|
`font-src data:${from}`,
|
|
@@ -245,10 +249,13 @@ var MCP_APP_SANDBOX_SCRIPT = `(function () {
|
|
|
245
249
|
for (var i = 0; i < ancestors.length; i++) ancestors[i].postMessage(ready, '*')
|
|
246
250
|
})()`;
|
|
247
251
|
var json = (value) => JSON.stringify(value).replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/&/g, "\\u0026");
|
|
248
|
-
var mcpAppSandboxPage = (hosts) =>
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
+
var mcpAppSandboxPage = (hosts, scheme) => {
|
|
253
|
+
const s = mcpAppColorScheme(scheme);
|
|
254
|
+
return '<!doctype html><html><head><meta charset="utf-8"><meta name="robots" content="noindex">' + (s ? `<meta name="color-scheme" content="${s}">` : "") + `<title>MCP App sandbox</title><style>${s ? `:root{color-scheme:${s}}` : ""}html,body{margin:0;height:100%;overflow:hidden;background:transparent}iframe{display:block;border:0;width:100%;height:100%${s ? `;color-scheme:${s}` : ""}}</style></head><body><script type="application/json" id="mcp-app-sandbox-hosts">${json({
|
|
255
|
+
origins: hosts.origins,
|
|
256
|
+
patterns: hosts.patterns
|
|
257
|
+
})}</script><script>${MCP_APP_SANDBOX_SCRIPT}</script></body></html>`;
|
|
258
|
+
};
|
|
252
259
|
var MCP_APP_SANDBOX_PERMISSIONS_POLICY = "camera=(), microphone=(), geolocation=(), display-capture=(), payment=(), usb=(), serial=(), midi=()";
|
|
253
260
|
var COMMON = {
|
|
254
261
|
"X-Content-Type-Options": "nosniff",
|
|
@@ -272,7 +279,7 @@ var plain = (status, text, extra = {}) => new Response(text, {
|
|
|
272
279
|
}
|
|
273
280
|
});
|
|
274
281
|
var mcpAppSandboxResponse = (request, options) => {
|
|
275
|
-
const { pathname } = new URL(request.url);
|
|
282
|
+
const { pathname, searchParams } = new URL(request.url);
|
|
276
283
|
const base = options.path.replace(/\/+$/, "");
|
|
277
284
|
if (!pathname.startsWith(`${base}/`)) return plain(404, "Not found");
|
|
278
285
|
const token = pathname.slice(base.length + 1);
|
|
@@ -286,7 +293,8 @@ var mcpAppSandboxResponse = (request, options) => {
|
|
|
286
293
|
if (hosts.invalid.length > 0 || hosts.frameAncestors.length === 0) {
|
|
287
294
|
return plain(503, "This sandbox has no valid allowed host origins");
|
|
288
295
|
}
|
|
289
|
-
|
|
296
|
+
const scheme = mcpAppColorScheme(searchParams.get(MCP_APP_SCHEME_PARAM));
|
|
297
|
+
return new Response(request.method === "HEAD" ? null : mcpAppSandboxPage(hosts, scheme), {
|
|
290
298
|
status: 200,
|
|
291
299
|
headers: mcpAppSandboxHeaders(policy, hosts)
|
|
292
300
|
});
|
|
@@ -299,8 +307,10 @@ var mcpAppSandboxResponse = (request, options) => {
|
|
|
299
307
|
MCP_APP_SANDBOX_PROXY_READY,
|
|
300
308
|
MCP_APP_SANDBOX_RESOURCE_READY,
|
|
301
309
|
MCP_APP_SANDBOX_SCRIPT,
|
|
310
|
+
MCP_APP_SCHEME_PARAM,
|
|
302
311
|
isMcpAppSandboxHost,
|
|
303
312
|
isMcpAppSandboxMessage,
|
|
313
|
+
mcpAppColorScheme,
|
|
304
314
|
mcpAppPolicy,
|
|
305
315
|
mcpAppPolicyOfToken,
|
|
306
316
|
mcpAppPolicyOrigin,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/mcp-app-sandbox.ts","../src/mcp-app-policy.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","/**\n * MCP Apps: what the host (the page, `mcp-app.ts`) and the sandbox proxy (a page on ANOTHER\n * origin, `mcp-app-sandbox.ts`) must agree on - the app's Content-Security-Policy, the policy as a\n * path segment of the proxy's URL, and the names of the sandbox messages. Pure code with NO\n * imports at all: the proxy's server bundles it without React or the core (a Worker), so the\n * origin rule below is a copy of the core's `mcpAppOrigin`, and `tests/apps-sandbox.test.ts`\n * holds the two to the same answers.\n */\n\n/** The proxy tells the host it can take the app (Sandbox → Host; content-free). */\nexport const MCP_APP_SANDBOX_PROXY_READY = 'ui/notifications/sandbox-proxy-ready'\n/** The host hands the proxy the app's HTML (Host → Sandbox), once. */\nexport const MCP_APP_SANDBOX_RESOURCE_READY = 'ui/notifications/sandbox-resource-ready'\n\n/** The specification reserves these between a host and its proxy: never relayed to or from an app. */\nexport const isMcpAppSandboxMessage = (data: unknown): boolean =>\n typeof data === 'object' &&\n data !== null &&\n typeof (data as { method?: unknown }).method === 'string' &&\n (data as { method: string }).method.startsWith('ui/notifications/sandbox-')\n\n/** The origins an app's policy grants, each already an origin (`mcpAppPolicyOrigin`). */\nexport interface McpAppPolicyOrigins {\n /** `fetch` / XHR / WebSocket (`connect-src`). */\n connect: string[]\n /** Scripts, styles, images, fonts, media. */\n resources: string[]\n}\n\n/**\n * The policy of an app's document: scripts and styles inline, `data:` / `blob:` media, and the\n * network ONLY where the resource declared it. Nested frames, workers, plugins, forms and `<base>`\n * are refused whatever was declared (a frame the app may embed would also be a place it may\n * navigate itself to). The lists must already be checked origins: nothing here re-checks them.\n */\nexport const mcpAppPolicy = ({ connect, resources }: McpAppPolicyOrigins): string => {\n const from = resources.length > 0 ? ` ${resources.join(' ')}` : ''\n return [\n \"default-src 'none'\",\n `script-src 'unsafe-inline'${from}`,\n `style-src 'unsafe-inline'${from}`,\n `img-src data: blob:${from}`,\n `font-src data:${from}`,\n `media-src data: blob:${from}`,\n connect.length > 0 ? `connect-src ${connect.join(' ')}` : \"connect-src 'none'\",\n \"frame-src 'none'\",\n \"child-src 'none'\",\n \"worker-src 'none'\",\n \"object-src 'none'\",\n \"form-action 'none'\",\n \"base-uri 'none'\",\n \"webrtc 'block'\",\n ].join('; ')\n}\n\n// ── The origin rule: a COPY of the core's `mcpAppOrigin` (src/mcp/apps.ts) ──────────────────\n\nconst LABEL = '[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?'\nconst HOST = `(?:\\\\*\\\\.)?${LABEL}(?:\\\\.${LABEL})*`\nconst PORT = '(?::\\\\d{1,5})?'\nconst SECURE_ORIGIN = new RegExp(`^(?:https|wss)://${HOST}${PORT}$`)\nconst LOOPBACK_ORIGIN = new RegExp(`^(?:http|ws)://(?:localhost|127\\\\.0\\\\.0\\\\.1|\\\\[::1\\\\])${PORT}$`)\n\n/**\n * One declared CSP entry as a source expression a policy may carry, or `undefined`: only an\n * origin (`https://` / `wss://`, a `*.` wildcard over at least two labels, or `http://` /\n * `ws://` on loopback). The same answers as the core's `mcpAppOrigin`, for the proxy's server.\n */\nexport const mcpAppPolicyOrigin = (entry: unknown): string | undefined => {\n if (typeof entry !== 'string' || entry.length > 300) return undefined\n const value = entry.trim().toLowerCase().replace(/\\/$/, '')\n if (SECURE_ORIGIN.test(value)) {\n const host = value.replace(/^[a-z]+:\\/\\//, '').replace(/:\\d+$/, '')\n if (host.startsWith('*.') && !host.slice(2).includes('.')) return undefined\n return value\n }\n return LOOPBACK_ORIGIN.test(value) ? value : undefined\n}\n\n// ── The policy in the proxy's URL ────────────────────────────────────────────────────────────\n\n/** At most this many origins per list (the core's `MCP_APP_MAX_DOMAINS`). */\nexport const MCP_APP_POLICY_MAX_ORIGINS = 32\n/** A policy token longer than this is not put in a URL: the app runs without its own origin. */\nexport const MCP_APP_POLICY_TOKEN_MAX_CHARS = 4096\n\nconst B64URL = /^[A-Za-z0-9_-]+$/\n\n/**\n * The policy as one path segment (base64url of `{\"c\":[…],\"r\":[…]}`), or `undefined` when it does\n * not fit. It is in the PATH, not the query, because a `frame-src` source expression matches a\n * path exactly and ignores the query: the host pins the proxy's frame to this one URL, so nothing\n * inside the frame can load the proxy page with a policy of its choosing.\n */\nexport const mcpAppPolicyToken = ({\n connect,\n resources,\n}: McpAppPolicyOrigins): string | undefined => {\n const json = JSON.stringify({ c: connect, r: resources })\n // Origins are ASCII; anything else is not a list of checked origins.\n if (/[^\\x20-\\x7e]/.test(json)) return undefined\n const token = btoa(json).replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=+$/, '')\n return token.length <= MCP_APP_POLICY_TOKEN_MAX_CHARS ? token : undefined\n}\n\nconst isObject = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value)\n\nconst originList = (value: unknown): string[] | undefined => {\n if (!Array.isArray(value) || value.length > MCP_APP_POLICY_MAX_ORIGINS) return undefined\n const out: string[] = []\n for (const entry of value) {\n // Exactly an origin as the host writes it: checked, canonical, once.\n if (typeof entry !== 'string' || mcpAppPolicyOrigin(entry) !== entry || out.includes(entry)) {\n return undefined\n }\n out.push(entry)\n }\n return out\n}\n\n/**\n * The policy a token stands for, or `undefined` for anything that is not exactly what\n * `mcpAppPolicyToken` writes: base64url of an object with the two lists and nothing else, every\n * entry an origin by the rule above, no more than `MCP_APP_POLICY_MAX_ORIGINS` each, the\n * canonical encoding (one URL per policy).\n */\nexport const mcpAppPolicyOfToken = (token: unknown): McpAppPolicyOrigins | undefined => {\n if (\n typeof token !== 'string' ||\n token.length === 0 ||\n token.length > MCP_APP_POLICY_TOKEN_MAX_CHARS ||\n !B64URL.test(token)\n ) {\n return undefined\n }\n let parsed: unknown\n try {\n parsed = JSON.parse(atob(token.replace(/-/g, '+').replace(/_/g, '/')))\n } catch {\n return undefined\n }\n if (!isObject(parsed)) return undefined\n const keys = Object.keys(parsed)\n if (keys.length !== 2 || !keys.includes('c') || !keys.includes('r')) return undefined\n const connect = originList(parsed.c)\n const resources = originList(parsed.r)\n if (!connect || !resources) return undefined\n const policy = { connect, resources }\n return mcpAppPolicyToken(policy) === token ? policy : undefined\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA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,EAAE;AAC5C,MAAI,CAAC,SAAS,WAAW,GAAG,IAAI,GAAG,EAAG,QAAO,MAAM,KAAK,WAAW;AACnE,QAAM,QAAQ,SAAS,MAAM,KAAK,SAAS,CAAC;AAC5C,MAAI,MAAM,WAAW,KAAK,MAAM,SAAS,GAAG,EAAG,QAAO,MAAM,KAAK,WAAW;AAC5E,MAAI,QAAQ,WAAW,SAAS,QAAQ,WAAW,QAAQ;AACzD,WAAO,MAAM,KAAK,sBAAsB,EAAE,OAAO,YAAY,CAAC;AAAA,EAChE;AACA,QAAM,SAAS,oBAAoB,KAAK;AACxC,MAAI,CAAC,OAAQ,QAAO,MAAM,KAAK,kCAAkC;AACjE,QAAM,QAAQ,wBAAwB,QAAQ,KAAK;AACnD,MAAI,MAAM,QAAQ,SAAS,KAAK,MAAM,eAAe,WAAW,GAAG;AACjE,WAAO,MAAM,KAAK,gDAAgD;AAAA,EACpE;AACA,SAAO,IAAI,SAAS,QAAQ,WAAW,SAAS,OAAO,kBAAkB,KAAK,GAAG;AAAA,IAC/E,QAAQ;AAAA,IACR,SAAS,qBAAqB,QAAQ,KAAK;AAAA,EAC7C,CAAC;AACH;","names":["json","LABEL"]}
|
|
1
|
+
{"version":3,"sources":["../src/mcp-app-sandbox.ts","../src/mcp-app-policy.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 MCP_APP_SCHEME_PARAM,\n mcpAppColorScheme,\n mcpAppPolicy,\n mcpAppPolicyOfToken,\n mcpAppPolicyOrigin,\n mcpAppPolicyToken,\n type McpAppColorScheme,\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 MCP_APP_SCHEME_PARAM,\n mcpAppColorScheme,\n mcpAppPolicy,\n mcpAppPolicyOfToken,\n mcpAppPolicyOrigin,\n mcpAppPolicyToken,\n}\nexport type { McpAppColorScheme, 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/**\n * The page: the hosts as data, the script. Serve it with `mcpAppSandboxHeaders`. `scheme` (the\n * frame's colour scheme, `?scheme=` of the page's URL) is declared by the page and on the app's\n * frame - only `light` / `dark`; without one the page declares nothing.\n */\nexport const mcpAppSandboxPage = (\n hosts: McpAppSandboxHosts,\n scheme?: McpAppColorScheme,\n): string => {\n const s = mcpAppColorScheme(scheme)\n return (\n '<!doctype html><html><head><meta charset=\"utf-8\"><meta name=\"robots\" content=\"noindex\">' +\n (s ? `<meta name=\"color-scheme\" content=\"${s}\">` : '') +\n '<title>MCP App sandbox</title>' +\n `<style>${s ? `:root{color-scheme:${s}}` : ''}` +\n 'html,body{margin:0;height:100%;overflow:hidden;background:transparent}' +\n `iframe{display:block;border:0;width:100%;height:100%${s ? `;color-scheme:${s}` : ''}}` +\n '</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}\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 (and `?scheme=light|dark`, the frame's colour scheme - anything else is none); a token\n * 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, searchParams } = 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 const scheme = mcpAppColorScheme(searchParams.get(MCP_APP_SCHEME_PARAM))\n return new Response(request.method === 'HEAD' ? null : mcpAppSandboxPage(hosts, scheme), {\n status: 200,\n headers: mcpAppSandboxHeaders(policy, hosts),\n })\n}\n","/**\n * MCP Apps: what the host (the page, `mcp-app.ts`) and the sandbox proxy (a page on ANOTHER\n * origin, `mcp-app-sandbox.ts`) must agree on - the app's Content-Security-Policy, the policy as a\n * path segment of the proxy's URL, and the names of the sandbox messages. Pure code with NO\n * imports at all: the proxy's server bundles it without React or the core (a Worker), so the\n * origin rule below is a copy of the core's `mcpAppOrigin`, and `tests/apps-sandbox.test.ts`\n * holds the two to the same answers.\n */\n\n/** The proxy tells the host it can take the app (Sandbox → Host; content-free). */\nexport const MCP_APP_SANDBOX_PROXY_READY = 'ui/notifications/sandbox-proxy-ready'\n/** The host hands the proxy the app's HTML (Host → Sandbox), once. */\nexport const MCP_APP_SANDBOX_RESOURCE_READY = 'ui/notifications/sandbox-resource-ready'\n\n/** The specification reserves these between a host and its proxy: never relayed to or from an app. */\nexport const isMcpAppSandboxMessage = (data: unknown): boolean =>\n typeof data === 'object' &&\n data !== null &&\n typeof (data as { method?: unknown }).method === 'string' &&\n (data as { method: string }).method.startsWith('ui/notifications/sandbox-')\n\n/**\n * The colour scheme of an app's frame: the theme the app is told when its frame is drawn. Every\n * document between the page and the app declares it (the frame element, the shell, the sandbox\n * page and its frame), because a browser paints an OPAQUE canvas - the canvas colour of the\n * embedded document's own scheme - behind a document whose scheme differs from its frame\n * element's: an app that is dark with a transparent body was drawn on white.\n */\nexport type McpAppColorScheme = 'light' | 'dark'\n\n/** The query parameter of the sandbox page that carries the scheme (`?scheme=dark`). */\nexport const MCP_APP_SCHEME_PARAM = 'scheme'\n\n/** `light` or `dark` exactly; anything else is no scheme (nothing is declared). */\nexport const mcpAppColorScheme = (value: unknown): McpAppColorScheme | undefined =>\n value === 'light' || value === 'dark' ? value : undefined\n\n/** The origins an app's policy grants, each already an origin (`mcpAppPolicyOrigin`). */\nexport interface McpAppPolicyOrigins {\n /** `fetch` / XHR / WebSocket (`connect-src`). */\n connect: string[]\n /** Scripts, styles, images, fonts, media. */\n resources: string[]\n}\n\n/**\n * The policy of an app's document: scripts and styles inline, `data:` / `blob:` media, and the\n * network ONLY where the resource declared it. Nested frames, workers, plugins, forms and `<base>`\n * are refused whatever was declared (a frame the app may embed would also be a place it may\n * navigate itself to). The lists must already be checked origins: nothing here re-checks them.\n *\n * `'wasm-unsafe-eval'` lets the app compile WebAssembly (a tracer, a codec, a parser), which the\n * specification's default policy leaves out and a server cannot ask for (it declares origins, not\n * keywords). It adds no reach: a module only calls what the app's own script hands it, and the\n * network stays `connect-src`. `eval`, `new Function` and string timers stay refused - that is\n * `'unsafe-eval'`, which is never granted.\n */\nexport const mcpAppPolicy = ({ connect, resources }: McpAppPolicyOrigins): string => {\n const from = resources.length > 0 ? ` ${resources.join(' ')}` : ''\n return [\n \"default-src 'none'\",\n `script-src 'unsafe-inline' 'wasm-unsafe-eval'${from}`,\n `style-src 'unsafe-inline'${from}`,\n `img-src data: blob:${from}`,\n `font-src data:${from}`,\n `media-src data: blob:${from}`,\n connect.length > 0 ? `connect-src ${connect.join(' ')}` : \"connect-src 'none'\",\n \"frame-src 'none'\",\n \"child-src 'none'\",\n \"worker-src 'none'\",\n \"object-src 'none'\",\n \"form-action 'none'\",\n \"base-uri 'none'\",\n \"webrtc 'block'\",\n ].join('; ')\n}\n\n// ── The origin rule: a COPY of the core's `mcpAppOrigin` (src/mcp/apps.ts) ──────────────────\n\nconst LABEL = '[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?'\nconst HOST = `(?:\\\\*\\\\.)?${LABEL}(?:\\\\.${LABEL})*`\nconst PORT = '(?::\\\\d{1,5})?'\nconst SECURE_ORIGIN = new RegExp(`^(?:https|wss)://${HOST}${PORT}$`)\nconst LOOPBACK_ORIGIN = new RegExp(`^(?:http|ws)://(?:localhost|127\\\\.0\\\\.0\\\\.1|\\\\[::1\\\\])${PORT}$`)\n\n/**\n * One declared CSP entry as a source expression a policy may carry, or `undefined`: only an\n * origin (`https://` / `wss://`, a `*.` wildcard over at least two labels, or `http://` /\n * `ws://` on loopback). The same answers as the core's `mcpAppOrigin`, for the proxy's server.\n */\nexport const mcpAppPolicyOrigin = (entry: unknown): string | undefined => {\n if (typeof entry !== 'string' || entry.length > 300) return undefined\n const value = entry.trim().toLowerCase().replace(/\\/$/, '')\n if (SECURE_ORIGIN.test(value)) {\n const host = value.replace(/^[a-z]+:\\/\\//, '').replace(/:\\d+$/, '')\n if (host.startsWith('*.') && !host.slice(2).includes('.')) return undefined\n return value\n }\n return LOOPBACK_ORIGIN.test(value) ? value : undefined\n}\n\n// ── The policy in the proxy's URL ────────────────────────────────────────────────────────────\n\n/** At most this many origins per list (the core's `MCP_APP_MAX_DOMAINS`). */\nexport const MCP_APP_POLICY_MAX_ORIGINS = 32\n/** A policy token longer than this is not put in a URL: the app runs without its own origin. */\nexport const MCP_APP_POLICY_TOKEN_MAX_CHARS = 4096\n\nconst B64URL = /^[A-Za-z0-9_-]+$/\n\n/**\n * The policy as one path segment (base64url of `{\"c\":[…],\"r\":[…]}`), or `undefined` when it does\n * not fit. It is in the PATH, not the query, because a `frame-src` source expression matches a\n * path exactly and ignores the query: the host pins the proxy's frame to this one URL, so nothing\n * inside the frame can load the proxy page with a policy of its choosing.\n */\nexport const mcpAppPolicyToken = ({\n connect,\n resources,\n}: McpAppPolicyOrigins): string | undefined => {\n const json = JSON.stringify({ c: connect, r: resources })\n // Origins are ASCII; anything else is not a list of checked origins.\n if (/[^\\x20-\\x7e]/.test(json)) return undefined\n const token = btoa(json).replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=+$/, '')\n return token.length <= MCP_APP_POLICY_TOKEN_MAX_CHARS ? token : undefined\n}\n\nconst isObject = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value)\n\nconst originList = (value: unknown): string[] | undefined => {\n if (!Array.isArray(value) || value.length > MCP_APP_POLICY_MAX_ORIGINS) return undefined\n const out: string[] = []\n for (const entry of value) {\n // Exactly an origin as the host writes it: checked, canonical, once.\n if (typeof entry !== 'string' || mcpAppPolicyOrigin(entry) !== entry || out.includes(entry)) {\n return undefined\n }\n out.push(entry)\n }\n return out\n}\n\n/**\n * The policy a token stands for, or `undefined` for anything that is not exactly what\n * `mcpAppPolicyToken` writes: base64url of an object with the two lists and nothing else, every\n * entry an origin by the rule above, no more than `MCP_APP_POLICY_MAX_ORIGINS` each, the\n * canonical encoding (one URL per policy).\n */\nexport const mcpAppPolicyOfToken = (token: unknown): McpAppPolicyOrigins | undefined => {\n if (\n typeof token !== 'string' ||\n token.length === 0 ||\n token.length > MCP_APP_POLICY_TOKEN_MAX_CHARS ||\n !B64URL.test(token)\n ) {\n return undefined\n }\n let parsed: unknown\n try {\n parsed = JSON.parse(atob(token.replace(/-/g, '+').replace(/_/g, '/')))\n } catch {\n return undefined\n }\n if (!isObject(parsed)) return undefined\n const keys = Object.keys(parsed)\n if (keys.length !== 2 || !keys.includes('c') || !keys.includes('r')) return undefined\n const connect = originList(parsed.c)\n const resources = originList(parsed.r)\n if (!connect || !resources) return undefined\n const policy = { connect, resources }\n return mcpAppPolicyToken(policy) === token ? policy : undefined\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACUO,IAAM,8BAA8B;AAEpC,IAAM,iCAAiC;AAGvC,IAAM,yBAAyB,CAAC,SACrC,OAAO,SAAS,YAChB,SAAS,QACT,OAAQ,KAA8B,WAAW,YAChD,KAA4B,OAAO,WAAW,2BAA2B;AAYrE,IAAM,uBAAuB;AAG7B,IAAM,oBAAoB,CAAC,UAChC,UAAU,WAAW,UAAU,SAAS,QAAQ;AAsB3C,IAAM,eAAe,CAAC,EAAE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AAQ,SAAS,MAAM,KAAK,SAAS,CAAC;AAC5C,MAAI,MAAM,WAAW,KAAK,MAAM,SAAS,GAAG,EAAG,QAAO,MAAM,KAAK,WAAW;AAC5E,MAAI,QAAQ,WAAW,SAAS,QAAQ,WAAW,QAAQ;AACzD,WAAO,MAAM,KAAK,sBAAsB,EAAE,OAAO,YAAY,CAAC;AAAA,EAChE;AACA,QAAM,SAAS,oBAAoB,KAAK;AACxC,MAAI,CAAC,OAAQ,QAAO,MAAM,KAAK,kCAAkC;AACjE,QAAM,QAAQ,wBAAwB,QAAQ,KAAK;AACnD,MAAI,MAAM,QAAQ,SAAS,KAAK,MAAM,eAAe,WAAW,GAAG;AACjE,WAAO,MAAM,KAAK,gDAAgD;AAAA,EACpE;AACA,QAAM,SAAS,kBAAkB,aAAa,IAAI,oBAAoB,CAAC;AACvE,SAAO,IAAI,SAAS,QAAQ,WAAW,SAAS,OAAO,kBAAkB,OAAO,MAAM,GAAG;AAAA,IACvF,QAAQ;AAAA,IACR,SAAS,qBAAqB,QAAQ,KAAK;AAAA,EAC7C,CAAC;AACH;","names":["json","LABEL"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { f as McpAppPolicyOrigins, d as McpAppColorScheme } from './mcp-app-policy-BhBIsbBy.cjs';
|
|
2
|
+
export { g as MCP_APP_POLICY_MAX_ORIGINS, M as MCP_APP_POLICY_TOKEN_MAX_CHARS, a as MCP_APP_SANDBOX_PROXY_READY, b as MCP_APP_SANDBOX_RESOURCE_READY, c as MCP_APP_SCHEME_PARAM, i as isMcpAppSandboxMessage, m as mcpAppColorScheme, h as mcpAppPolicy, j as mcpAppPolicyOfToken, k as mcpAppPolicyOrigin, e as mcpAppPolicyToken } from './mcp-app-policy-BhBIsbBy.cjs';
|
|
3
3
|
|
|
4
4
|
/** A host origin pattern: `https://<prefix>*<suffix>.<rest>`, `*` one run of `[a-z0-9-]`. */
|
|
5
5
|
interface McpAppSandboxHostPattern {
|
|
@@ -37,8 +37,12 @@ declare const isMcpAppSandboxHost: (hosts: McpAppSandboxHosts, origin: string) =
|
|
|
37
37
|
* the resource, writes the app into its frame, and relays - see the entry's comment.
|
|
38
38
|
*/
|
|
39
39
|
declare const MCP_APP_SANDBOX_SCRIPT: string;
|
|
40
|
-
/**
|
|
41
|
-
|
|
40
|
+
/**
|
|
41
|
+
* The page: the hosts as data, the script. Serve it with `mcpAppSandboxHeaders`. `scheme` (the
|
|
42
|
+
* frame's colour scheme, `?scheme=` of the page's URL) is declared by the page and on the app's
|
|
43
|
+
* frame - only `light` / `dark`; without one the page declares nothing.
|
|
44
|
+
*/
|
|
45
|
+
declare const mcpAppSandboxPage: (hosts: McpAppSandboxHosts, scheme?: McpAppColorScheme) => string;
|
|
42
46
|
/** Browser features the page and the app may never use, whatever an app asks for. */
|
|
43
47
|
declare const MCP_APP_SANDBOX_PERMISSIONS_POLICY = "camera=(), microphone=(), geolocation=(), display-capture=(), payment=(), usb=(), serial=(), midi=()";
|
|
44
48
|
/**
|
|
@@ -55,11 +59,12 @@ interface McpAppSandboxServeOptions {
|
|
|
55
59
|
}
|
|
56
60
|
/**
|
|
57
61
|
* A fetch handler for the sandbox page: `GET` / `HEAD` of `<path>/<policy>` is the page, with its
|
|
58
|
-
* headers
|
|
62
|
+
* headers (and `?scheme=light|dark`, the frame's colour scheme - anything else is none); a token
|
|
63
|
+
* that is not exactly what `mcpAppPolicyToken` writes is 400; another method 405;
|
|
59
64
|
* any other path 404; no valid host origin (or an invalid entry in the setting) 503 - a sandbox
|
|
60
65
|
* nobody may frame is a configuration error, not a page.
|
|
61
66
|
*/
|
|
62
67
|
declare const mcpAppSandboxResponse: (request: Request, options: McpAppSandboxServeOptions) => Response;
|
|
63
68
|
|
|
64
|
-
export { MCP_APP_SANDBOX_PERMISSIONS_POLICY, MCP_APP_SANDBOX_SCRIPT, McpAppPolicyOrigins, isMcpAppSandboxHost, mcpAppSandboxHeaders, mcpAppSandboxPage, mcpAppSandboxResponse, parseMcpAppSandboxHosts };
|
|
69
|
+
export { MCP_APP_SANDBOX_PERMISSIONS_POLICY, MCP_APP_SANDBOX_SCRIPT, McpAppColorScheme, McpAppPolicyOrigins, isMcpAppSandboxHost, mcpAppSandboxHeaders, mcpAppSandboxPage, mcpAppSandboxResponse, parseMcpAppSandboxHosts };
|
|
65
70
|
export type { McpAppSandboxHostPattern, McpAppSandboxHosts, McpAppSandboxServeOptions };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { f as McpAppPolicyOrigins, d as McpAppColorScheme } from './mcp-app-policy-BhBIsbBy.js';
|
|
2
|
+
export { g as MCP_APP_POLICY_MAX_ORIGINS, M as MCP_APP_POLICY_TOKEN_MAX_CHARS, a as MCP_APP_SANDBOX_PROXY_READY, b as MCP_APP_SANDBOX_RESOURCE_READY, c as MCP_APP_SCHEME_PARAM, i as isMcpAppSandboxMessage, m as mcpAppColorScheme, h as mcpAppPolicy, j as mcpAppPolicyOfToken, k as mcpAppPolicyOrigin, e as mcpAppPolicyToken } from './mcp-app-policy-BhBIsbBy.js';
|
|
3
3
|
|
|
4
4
|
/** A host origin pattern: `https://<prefix>*<suffix>.<rest>`, `*` one run of `[a-z0-9-]`. */
|
|
5
5
|
interface McpAppSandboxHostPattern {
|
|
@@ -37,8 +37,12 @@ declare const isMcpAppSandboxHost: (hosts: McpAppSandboxHosts, origin: string) =
|
|
|
37
37
|
* the resource, writes the app into its frame, and relays - see the entry's comment.
|
|
38
38
|
*/
|
|
39
39
|
declare const MCP_APP_SANDBOX_SCRIPT: string;
|
|
40
|
-
/**
|
|
41
|
-
|
|
40
|
+
/**
|
|
41
|
+
* The page: the hosts as data, the script. Serve it with `mcpAppSandboxHeaders`. `scheme` (the
|
|
42
|
+
* frame's colour scheme, `?scheme=` of the page's URL) is declared by the page and on the app's
|
|
43
|
+
* frame - only `light` / `dark`; without one the page declares nothing.
|
|
44
|
+
*/
|
|
45
|
+
declare const mcpAppSandboxPage: (hosts: McpAppSandboxHosts, scheme?: McpAppColorScheme) => string;
|
|
42
46
|
/** Browser features the page and the app may never use, whatever an app asks for. */
|
|
43
47
|
declare const MCP_APP_SANDBOX_PERMISSIONS_POLICY = "camera=(), microphone=(), geolocation=(), display-capture=(), payment=(), usb=(), serial=(), midi=()";
|
|
44
48
|
/**
|
|
@@ -55,11 +59,12 @@ interface McpAppSandboxServeOptions {
|
|
|
55
59
|
}
|
|
56
60
|
/**
|
|
57
61
|
* A fetch handler for the sandbox page: `GET` / `HEAD` of `<path>/<policy>` is the page, with its
|
|
58
|
-
* headers
|
|
62
|
+
* headers (and `?scheme=light|dark`, the frame's colour scheme - anything else is none); a token
|
|
63
|
+
* that is not exactly what `mcpAppPolicyToken` writes is 400; another method 405;
|
|
59
64
|
* any other path 404; no valid host origin (or an invalid entry in the setting) 503 - a sandbox
|
|
60
65
|
* nobody may frame is a configuration error, not a page.
|
|
61
66
|
*/
|
|
62
67
|
declare const mcpAppSandboxResponse: (request: Request, options: McpAppSandboxServeOptions) => Response;
|
|
63
68
|
|
|
64
|
-
export { MCP_APP_SANDBOX_PERMISSIONS_POLICY, MCP_APP_SANDBOX_SCRIPT, McpAppPolicyOrigins, isMcpAppSandboxHost, mcpAppSandboxHeaders, mcpAppSandboxPage, mcpAppSandboxResponse, parseMcpAppSandboxHosts };
|
|
69
|
+
export { MCP_APP_SANDBOX_PERMISSIONS_POLICY, MCP_APP_SANDBOX_SCRIPT, McpAppColorScheme, McpAppPolicyOrigins, isMcpAppSandboxHost, mcpAppSandboxHeaders, mcpAppSandboxPage, mcpAppSandboxResponse, parseMcpAppSandboxHosts };
|
|
65
70
|
export type { McpAppSandboxHostPattern, McpAppSandboxHosts, McpAppSandboxServeOptions };
|
package/dist/mcp-app-sandbox.js
CHANGED
|
@@ -3,12 +3,14 @@ import {
|
|
|
3
3
|
MCP_APP_POLICY_TOKEN_MAX_CHARS,
|
|
4
4
|
MCP_APP_SANDBOX_PROXY_READY,
|
|
5
5
|
MCP_APP_SANDBOX_RESOURCE_READY,
|
|
6
|
+
MCP_APP_SCHEME_PARAM,
|
|
6
7
|
isMcpAppSandboxMessage,
|
|
8
|
+
mcpAppColorScheme,
|
|
7
9
|
mcpAppPolicy,
|
|
8
10
|
mcpAppPolicyOfToken,
|
|
9
11
|
mcpAppPolicyOrigin,
|
|
10
12
|
mcpAppPolicyToken
|
|
11
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-AWZ2OZSG.js";
|
|
12
14
|
|
|
13
15
|
// src/mcp-app-sandbox.ts
|
|
14
16
|
var LABEL = "[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?";
|
|
@@ -134,10 +136,13 @@ var MCP_APP_SANDBOX_SCRIPT = `(function () {
|
|
|
134
136
|
for (var i = 0; i < ancestors.length; i++) ancestors[i].postMessage(ready, '*')
|
|
135
137
|
})()`;
|
|
136
138
|
var json = (value) => JSON.stringify(value).replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/&/g, "\\u0026");
|
|
137
|
-
var mcpAppSandboxPage = (hosts) =>
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
139
|
+
var mcpAppSandboxPage = (hosts, scheme) => {
|
|
140
|
+
const s = mcpAppColorScheme(scheme);
|
|
141
|
+
return '<!doctype html><html><head><meta charset="utf-8"><meta name="robots" content="noindex">' + (s ? `<meta name="color-scheme" content="${s}">` : "") + `<title>MCP App sandbox</title><style>${s ? `:root{color-scheme:${s}}` : ""}html,body{margin:0;height:100%;overflow:hidden;background:transparent}iframe{display:block;border:0;width:100%;height:100%${s ? `;color-scheme:${s}` : ""}}</style></head><body><script type="application/json" id="mcp-app-sandbox-hosts">${json({
|
|
142
|
+
origins: hosts.origins,
|
|
143
|
+
patterns: hosts.patterns
|
|
144
|
+
})}</script><script>${MCP_APP_SANDBOX_SCRIPT}</script></body></html>`;
|
|
145
|
+
};
|
|
141
146
|
var MCP_APP_SANDBOX_PERMISSIONS_POLICY = "camera=(), microphone=(), geolocation=(), display-capture=(), payment=(), usb=(), serial=(), midi=()";
|
|
142
147
|
var COMMON = {
|
|
143
148
|
"X-Content-Type-Options": "nosniff",
|
|
@@ -161,7 +166,7 @@ var plain = (status, text, extra = {}) => new Response(text, {
|
|
|
161
166
|
}
|
|
162
167
|
});
|
|
163
168
|
var mcpAppSandboxResponse = (request, options) => {
|
|
164
|
-
const { pathname } = new URL(request.url);
|
|
169
|
+
const { pathname, searchParams } = new URL(request.url);
|
|
165
170
|
const base = options.path.replace(/\/+$/, "");
|
|
166
171
|
if (!pathname.startsWith(`${base}/`)) return plain(404, "Not found");
|
|
167
172
|
const token = pathname.slice(base.length + 1);
|
|
@@ -175,7 +180,8 @@ var mcpAppSandboxResponse = (request, options) => {
|
|
|
175
180
|
if (hosts.invalid.length > 0 || hosts.frameAncestors.length === 0) {
|
|
176
181
|
return plain(503, "This sandbox has no valid allowed host origins");
|
|
177
182
|
}
|
|
178
|
-
|
|
183
|
+
const scheme = mcpAppColorScheme(searchParams.get(MCP_APP_SCHEME_PARAM));
|
|
184
|
+
return new Response(request.method === "HEAD" ? null : mcpAppSandboxPage(hosts, scheme), {
|
|
179
185
|
status: 200,
|
|
180
186
|
headers: mcpAppSandboxHeaders(policy, hosts)
|
|
181
187
|
});
|
|
@@ -187,8 +193,10 @@ export {
|
|
|
187
193
|
MCP_APP_SANDBOX_PROXY_READY,
|
|
188
194
|
MCP_APP_SANDBOX_RESOURCE_READY,
|
|
189
195
|
MCP_APP_SANDBOX_SCRIPT,
|
|
196
|
+
MCP_APP_SCHEME_PARAM,
|
|
190
197
|
isMcpAppSandboxHost,
|
|
191
198
|
isMcpAppSandboxMessage,
|
|
199
|
+
mcpAppColorScheme,
|
|
192
200
|
mcpAppPolicy,
|
|
193
201
|
mcpAppPolicyOfToken,
|
|
194
202
|
mcpAppPolicyOrigin,
|
|
@@ -1 +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;AACvB,QAAM,WAAW,OAAO,UAAU,WAAW,MAAM,MAAM,QAAQ,IAAI,CAAC,GAAI,SAAS,CAAC,CAAE,GACnF,IAAI,CAAC,MAAO,OAAO,MAAM,WAAW,EAAE,KAAK,IAAI,EAAG,EAClD,OAAO,OAAO;AACjB,QAAM,QAA4B,EAAE,SAAS,CAAC,GAAG,UAAU,CAAC,GAAG,gBAAgB,CAAC,GAAG,SAAS,CAAC,EAAE;AAC/F,QAAM,WAAW,CAAC,WAAmB;AACnC,QAAI,CAAC,MAAM,eAAe,SAAS,MAAM,EAAG,OAAM,eAAe,KAAK,MAAM;AAAA,EAC9E;AACA,aAAW,OAAO,SAAS;AACzB,UAAM,QAAQ,IAAI,YAAY,EAAE,QAAQ,OAAO,EAAE;AACjD,UAAM,UAAU,QAAQ,KAAK,KAAK;AAClC,QAAI,SAAS;AACX,YAAM,CAAC,EAAE,QAAQ,QAAQ,IAAI,IAAI;AACjC,UACE,CAAC,MAAM,SAAS,KAAK,CAAC,MAAM,EAAE,WAAW,UAAU,EAAE,WAAW,UAAU,EAAE,SAAS,IAAI,GACzF;AACA,cAAM,SAAS,KAAK,EAAE,QAAQ,QAAQ,KAAK,CAAC;AAAA,MAC9C;AACA,eAAS,aAAa,IAAI,EAAE;AAAA,IAC9B,WAAW,YAAY,KAAK,KAAK,KAAK,eAAe,KAAK,KAAK,GAAG;AAChE,UAAI,CAAC,MAAM,Q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E,MAAI,QAAQ,WAAW,SAAS,QAAQ,WAAW,QAAQ;AACzD,WAAO,MAAM,KAAK,sBAAsB,EAAE,OAAO,YAAY,CAAC;AAAA,EAChE;AACA,QAAM,SAAS,oBAAoB,KAAK;AACxC,MAAI,CAAC,OAAQ,QAAO,MAAM,KAAK,kCAAkC;AACjE,QAAM,QAAQ,wBAAwB,QAAQ,KAAK;AACnD,MAAI,MAAM,QAAQ,SAAS,KAAK,MAAM,eAAe,WAAW,GAAG;AACjE,WAAO,MAAM,KAAK,gDAAgD;AAAA,EACpE;AACA,SAAO,IAAI,SAAS,QAAQ,WAAW,SAAS,OAAO,kBAAkB,KAAK,GAAG;AAAA,IAC/E,QAAQ;AAAA,IACR,SAAS,qBAAqB,QAAQ,KAAK;AAAA,EAC7C,CAAC;AACH;","names":[]}
|
|
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 MCP_APP_SCHEME_PARAM,\n mcpAppColorScheme,\n mcpAppPolicy,\n mcpAppPolicyOfToken,\n mcpAppPolicyOrigin,\n mcpAppPolicyToken,\n type McpAppColorScheme,\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 MCP_APP_SCHEME_PARAM,\n mcpAppColorScheme,\n mcpAppPolicy,\n mcpAppPolicyOfToken,\n mcpAppPolicyOrigin,\n mcpAppPolicyToken,\n}\nexport type { McpAppColorScheme, 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/**\n * The page: the hosts as data, the script. Serve it with `mcpAppSandboxHeaders`. `scheme` (the\n * frame's colour scheme, `?scheme=` of the page's URL) is declared by the page and on the app's\n * frame - only `light` / `dark`; without one the page declares nothing.\n */\nexport const mcpAppSandboxPage = (\n hosts: McpAppSandboxHosts,\n scheme?: McpAppColorScheme,\n): string => {\n const s = mcpAppColorScheme(scheme)\n return (\n '<!doctype html><html><head><meta charset=\"utf-8\"><meta name=\"robots\" content=\"noindex\">' +\n (s ? `<meta name=\"color-scheme\" content=\"${s}\">` : '') +\n '<title>MCP App sandbox</title>' +\n `<style>${s ? `:root{color-scheme:${s}}` : ''}` +\n 'html,body{margin:0;height:100%;overflow:hidden;background:transparent}' +\n `iframe{display:block;border:0;width:100%;height:100%${s ? `;color-scheme:${s}` : ''}}` +\n '</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}\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 (and `?scheme=light|dark`, the frame's colour scheme - anything else is none); a token\n * 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, searchParams } = 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 const scheme = mcpAppColorScheme(searchParams.get(MCP_APP_SCHEME_PARAM))\n return new Response(request.method === 'HEAD' ? null : mcpAppSandboxPage(hosts, scheme), {\n status: 200,\n headers: mcpAppSandboxHeaders(policy, hosts),\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;AA4EA,IAAM,QAAQ;AACd,IAAM,OAAO,GAAG,KAAK,SAAS,KAAK;AACnC,IAAM,cAAc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QAAQ,WAAW,QAAQ;AACzD,WAAO,MAAM,KAAK,sBAAsB,EAAE,OAAO,YAAY,CAAC;AAAA,EAChE;AACA,QAAM,SAAS,oBAAoB,KAAK;AACxC,MAAI,CAAC,OAAQ,QAAO,MAAM,KAAK,kCAAkC;AACjE,QAAM,QAAQ,wBAAwB,QAAQ,KAAK;AACnD,MAAI,MAAM,QAAQ,SAAS,KAAK,MAAM,eAAe,WAAW,GAAG;AACjE,WAAO,MAAM,KAAK,gDAAgD;AAAA,EACpE;AACA,QAAM,SAAS,kBAAkB,aAAa,IAAI,oBAAoB,CAAC;AACvE,SAAO,IAAI,SAAS,QAAQ,WAAW,SAAS,OAAO,kBAAkB,OAAO,MAAM,GAAG;AAAA,IACvF,QAAQ;AAAA,IACR,SAAS,qBAAqB,QAAQ,KAAK;AAAA,EAC7C,CAAC;AACH;","names":[]}
|
package/dist/mcp.d.cts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { McpSkillConsent, AgentToolSet } from '@dudko.dev/agent-web';
|
|
2
|
-
import { aY as McpOAuthRegistration, aZ as McpProtocolMode, P as PendingElicitation, f as McpElicitationResult, a_ as McpElicitationOptions, a$ as McpCatalogEntry, b0 as McpServerProtocol, b1 as McpOAuthRegistrationKind, b2 as McpOAuthCallback, b3 as McpServerResult, b4 as McpModule, b5 as ConnectedMcp, b6 as BrowserOAuthProviderOptions, b7 as BrowserOAuthProvider } from './elicitation-
|
|
2
|
+
import { aY as McpOAuthRegistration, aZ as McpProtocolMode, P as PendingElicitation, f as McpElicitationResult, a_ as McpElicitationOptions, a$ as McpCatalogEntry, b0 as McpServerProtocol, b1 as McpOAuthRegistrationKind, b2 as McpOAuthCallback, b3 as McpServerResult, b4 as McpModule, b5 as ConnectedMcp, b6 as BrowserOAuthProviderOptions, b7 as BrowserOAuthProvider } from './elicitation-B5t9hdaJ.cjs';
|
|
3
3
|
import { McpAppsConnectionLike } from './index.cjs';
|
|
4
|
-
export { b8 as ElicitationQueue, b9 as ElicitationQueueOptions, ap as McpElicitationFieldSchema, ba as McpElicitationHandler, aq as McpElicitationRequest, ar as McpElicitationSchema, bb as McpServerInstructions, bc as createElicitationQueue, bd as elicitationConnectOptions, be as elicitationSettings, bf as elicitationTimeoutOf } from './elicitation-
|
|
4
|
+
export { b8 as ElicitationQueue, b9 as ElicitationQueueOptions, ap as McpElicitationFieldSchema, ba as McpElicitationHandler, aq as McpElicitationRequest, ar as McpElicitationSchema, bb as McpServerInstructions, bc as createElicitationQueue, bd as elicitationConnectOptions, be as elicitationSettings, bf as elicitationTimeoutOf } from './elicitation-B5t9hdaJ.cjs';
|
|
5
|
+
import './mcp-app-policy-BhBIsbBy.cjs';
|
|
5
6
|
|
|
6
7
|
type McpStatus = 'idle' | 'connecting' | 'connected' | 'needs-authorization' | 'error';
|
|
7
8
|
/** The OAuth details of one server. Everything is optional. */
|
package/dist/mcp.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { McpSkillConsent, AgentToolSet } from '@dudko.dev/agent-web';
|
|
2
|
-
import { aY as McpOAuthRegistration, aZ as McpProtocolMode, P as PendingElicitation, f as McpElicitationResult, a_ as McpElicitationOptions, a$ as McpCatalogEntry, b0 as McpServerProtocol, b1 as McpOAuthRegistrationKind, b2 as McpOAuthCallback, b3 as McpServerResult, b4 as McpModule, b5 as ConnectedMcp, b6 as BrowserOAuthProviderOptions, b7 as BrowserOAuthProvider } from './elicitation-
|
|
2
|
+
import { aY as McpOAuthRegistration, aZ as McpProtocolMode, P as PendingElicitation, f as McpElicitationResult, a_ as McpElicitationOptions, a$ as McpCatalogEntry, b0 as McpServerProtocol, b1 as McpOAuthRegistrationKind, b2 as McpOAuthCallback, b3 as McpServerResult, b4 as McpModule, b5 as ConnectedMcp, b6 as BrowserOAuthProviderOptions, b7 as BrowserOAuthProvider } from './elicitation-rJu93Z3o.js';
|
|
3
3
|
import { McpAppsConnectionLike } from './index.js';
|
|
4
|
-
export { b8 as ElicitationQueue, b9 as ElicitationQueueOptions, ap as McpElicitationFieldSchema, ba as McpElicitationHandler, aq as McpElicitationRequest, ar as McpElicitationSchema, bb as McpServerInstructions, bc as createElicitationQueue, bd as elicitationConnectOptions, be as elicitationSettings, bf as elicitationTimeoutOf } from './elicitation-
|
|
4
|
+
export { b8 as ElicitationQueue, b9 as ElicitationQueueOptions, ap as McpElicitationFieldSchema, ba as McpElicitationHandler, aq as McpElicitationRequest, ar as McpElicitationSchema, bb as McpServerInstructions, bc as createElicitationQueue, bd as elicitationConnectOptions, be as elicitationSettings, bf as elicitationTimeoutOf } from './elicitation-rJu93Z3o.js';
|
|
5
|
+
import './mcp-app-policy-BhBIsbBy.js';
|
|
5
6
|
|
|
6
7
|
type McpStatus = 'idle' | 'connecting' | 'connected' | 'needs-authorization' | 'error';
|
|
7
8
|
/** The OAuth details of one server. Everything is optional. */
|