From c0ef8f919f21932ecff098c3c12fa5df582d1dc0 Mon Sep 17 00:00:00 2001 From: Aleksandr Shevchuk Date: Wed, 25 Nov 2026 10:13:54 +0200 Subject: [PATCH 1/2] feat(mcp): the card offers the activity in a new tab where a chat cannot play it in a reply (#274) A card with no origin frames nothing, since no frame inside it can have a Service Worker, and a frame the chat refuses is known from the browser's securitypolicyviolation. The card then shows one state in the loader's place: what happens, and a button that asks the chat to open the play page's address with the source in it (ui/open-link, or ChatGPT's openExternal), with the address to copy from the first press on. The page's own word from the frame takes the card back. The chat's theme is read the MCP Apps way as well (hostContext.theme). tests/card.test.ts runs the card in a browser in three stand-in chats. --- design/mcp.md | 28 ++++- design/scope.md | 10 ++ packages/mcp/README.md | 3 +- packages/mcp/lib/card.html | 109 ++++++++++++++-- packages/mcp/package.json | 1 + packages/mcp/tests/card.test.ts | 214 ++++++++++++++++++++++++++++++++ pnpm-lock.yaml | 3 + 7 files changed, 356 insertions(+), 12 deletions(-) create mode 100644 packages/mcp/tests/card.test.ts diff --git a/design/mcp.md b/design/mcp.md index f2f409eb..182e518e 100644 --- a/design/mcp.md +++ b/design/mcp.md @@ -123,6 +123,23 @@ command is that handler on a port. Its endpoint is `/mcp`. and no other (`openExternal`). It sends nothing to the server it came from and calls no tool. Its policy names the one site it frames and the chat's file store. A chat keeps a card by its address, so the address carries the card's hash. +- **Where the page cannot play in the card's frame, the card offers the activity in a tab, and + knows it from the browser** (#274), never from a chat's name. A card with no origin + (`self.origin` is `"null"`) was sandboxed without one, and a sandbox passes to every frame + inside: the page there has no Service Worker, so no frame is tried (Open WebUI 0.13.4 frames a + card with `sandbox="allow-scripts allow-downloads allow-popups"`). A chat that refuses the + frame has the browser raise `securitypolicyviolation` for the page's address (Claude lets a card + frame `blob:` and `data:` only, its `frameDomains` dropped). The card then + shows one state in the loader's place, as tall as what it says: what happens, and "Open the + activity", which asks the chat to open the play page's address with the source in it + (`ui/open-link`, or ChatGPT's `openExternal`). The tab is the chat's to open: one opened from + a sandboxed card keeps the sandbox, in all three engines. Whether a tab opened is not the + card's to see, so the address is there to copy from the first press on, and at once in a chat + that opens no link. The page's own word from the frame takes the card back: a wrong conclusion + never hides a player that works. The chat's theme is ChatGPT's `window.openai.theme` or MCP + Apps' `hostContext.theme`. Not known: Claude and Open WebUI themselves, which the card met + only as stand-ins. A player without the Service Worker is not built for such a chat + ([scope.md](scope.md)). - **What ChatGPT's frame was found to do is written in the card, with its date.** A card's frame saves no file and opens no tab on a press; the chat saves a file handed to it of 8 MB and refuses one of 16 MB, downloads from no address, and takes no package into its own files; its @@ -132,9 +149,14 @@ command is that handler on a port. Its endpoint is `/mcp`. - **Tested as a host runs it.** `tests/app.test.ts` starts the command on a free port and asks it over HTTP with the SDK's own client: the two tools and their words, the file input's schema, the card and its policy, a source checked, one refused, an attachment handed to the card alone, - a call whose file is no reference, a body over 1 MB, and that nothing was written. The card is - checked by hand in a page that stands in for a chat, its frame sandboxed as ChatGPT's was found - to be; in ChatGPT itself ran the probe's card, which this one is without its test parts. + a call whose file is no reference, a body over 1 MB, and that nothing was written. + `tests/card.test.ts` runs the card in a browser, the verifier's, in three chats that stand in + for the ones it was written against: one that sandboxes it without an origin, under the policy + Open WebUI writes from the card's domains; one that refuses the frame; one that lets the page + be framed. Each speaks MCP Apps to it, and the play page there says its height and no more. + With the site's own play page the card is checked by hand in a page that stands in for a chat, + its frame sandboxed as ChatGPT's was found to be; in ChatGPT itself ran the probe's card, which + this one is without its test parts. - **It is hosted as a Cloudflare Worker, at an address of ours** (`apps/mcp-worker`, #272): `mcp.embed-my.org`, one line of its config, since the domain's zone is on the same account. diff --git a/design/scope.md b/design/scope.md index b5d20c50..60401a1e 100644 --- a/design/scope.md +++ b/design/scope.md @@ -7,6 +7,16 @@ What is not built yet. The editor, offline management (save, library, delete), results storage and persistent file handles. xAPI is emitted as events and stored nowhere. +**A player without the Service Worker** (the owner's decision, 2026-11-25). A chat app may give +a card no origin, or refuse its frame, and a player could then run in the card itself, or in a +framed page, on `blob:` addresses and storage kept in memory. Run on the 79 corpus packages that +carry their libraries, under Open WebUI 0.13.4's rules for a card, such a player played 75 in +Chromium, Firefox and WebKit, and 77 as a page the card frames. Among those that started, the +six with a YouTube or Panopto video or another site embedded showed nothing in its place, since +the sandbox breaks the embed itself, and twelve lost two libraries' sounds; two old types need +`eval`. A player that plays some files and not others confuses the person using it, so the card +opens the activity in a tab, where the whole player runs ([mcp.md](mcp.md)). + ## Open **Demand-paced extraction, deferred on 2026-09-25.** The first request for a deflated entry diff --git a/packages/mcp/README.md b/packages/mcp/README.md index dbb2ebdf..4146a9e4 100644 --- a/packages/mcp/README.md +++ b/packages/mcp/README.md @@ -77,7 +77,8 @@ npx -y -p @missing-elements/h5p-mcp h5p-mcp-app --port 8787 Its endpoint is `/mcp`, with no sign-in. It has two tools: `h5p_types`, as above, and `h5p_play`, which checks an activity's source and shows the card. The card frames the play page of [missing-elements.github.io](https://missing-elements.github.io/h5p/), which builds the activity in -the person's browser and plays it there. +the person's browser and plays it there. In a chat app that does not let a card frame a page, or +gives the card no origin of its own, the card offers the same page in a new tab instead. What the server receives, and what it keeps: diff --git a/packages/mcp/lib/card.html b/packages/mcp/lib/card.html index 8057861c..1dbd569c 100644 --- a/packages/mcp/lib/card.html +++ b/packages/mcp/lib/card.html @@ -5,7 +5,7 @@ H5P activity ${served}` + response.end(` + +`) + }) + await listening(chat, '127.0.0.1') + CHAT = `http://localhost:${port(chat)}` + CARD = `http://127.0.0.1:${port(chat)}` + // The verifier's own choice of a browser: Chrome or Edge where one is installed, else Playwright's. + browser = await (verify as unknown as { launch: () => Promise }).launch() +}) + +afterAll(async () => { + await browser?.close() + site?.close() + chat?.close() +}) + +/** A chat of one kind with the card in it, and the card's frame. */ +async function open(query: string, late = 0): Promise<{ page: Page, card: Frame }> { + played = 0 + lateBy = late + const page = await browser.newPage({ viewport: { width: 760, height: 700 } }) + await page.goto(`${CHAT}/?${query}`) + const card = page.frames().find((frame) => frame.parentFrame() === page.mainFrame())! + return { page, card } +} +/** The source a play page's address carries, as the page reads it. */ +function sourceIn(address: string) { + const bytes = Buffer.from(new URL(address).hash.slice('#source='.length), 'base64url') + try { return JSON.parse(inflateRawSync(bytes).toString()) } catch { return JSON.parse(bytes.toString()) } +} +const offered = async (card: Frame) => ({ + title: await card.locator('#wait-title').innerText(), + note: await card.locator('#wait-note').innerText(), + spinner: await card.locator('#spinner').isVisible(), + button: await card.locator('#open').isVisible(), + link: await card.locator('#link').isVisible(), + frame: await card.locator('#page').isVisible(), + framed: await card.locator('#page').getAttribute('src') +}) + +describe('the card, where a chat cannot play the activity in its reply', () => { + it('frames nothing in a card without an origin, and offers the activity in a tab the chat opens', async () => { + const { page, card } = await open('kind=sandboxed&theme=dark') + await card.waitForSelector('#wait.tab') + expect(await card.evaluate(ORIGIN)).toBe('null') + expect(await offered(card)).toEqual({ + title: 'The activity opens in a new tab', + note: 'This chat does not play an activity inside a reply. It is built and played in your browser, and nothing is sent to a server.', + spinner: false, button: true, link: false, frame: false, framed: null + }) + // No frame was tried: the page was never asked for. + expect(played).toBe(0) + // The chat's theme, the MCP Apps way. + expect(await card.evaluate(SCHEME)).toBe('dark') + // The card is as tall as what it says, and the chat was told. + expect(await card.evaluate(FITS)).toBe(true) + expect((await page.evaluate(HEIGHTS)).at(-1)).toBeLessThan(300) + + await card.locator('#open').click() + await card.waitForSelector('#link:not([hidden])') + const asked = await page.evaluate(ASKED) + expect(asked).toHaveLength(1) + // The play page's own address, with the source in it and nothing else: no theme of the chat's. + expect(asked[0]).toMatch(new RegExp(`^${SITE}/h5p/play/#source=[\\w-]+$`)) + expect(sourceIn(asked[0]!)).toEqual(SOURCE) + // Whether a tab opened is not the card's to see: the address is there to copy from then on. + expect(await card.locator('#link-note').innerText()).toBe('A new tab should have opened. If none did, copy this link into your browser’s address bar.') + expect(await card.locator('#link-address').inputValue()).toBe(asked[0]) + expect(await card.evaluate(FITS)).toBe(true) + await page.close() + }) + + it('offers the tab where the chat refuses the frame', async () => { + const { page, card } = await open('kind=refused') + await card.waitForSelector('#wait.tab') + expect(await card.evaluate(ORIGIN)).not.toBe('null') + expect(await offered(card)).toMatchObject({ title: 'The activity opens in a new tab', spinner: false, button: true, frame: false }) + // The refused frame loads with nothing in it: its load does not take the card back. + await page.waitForTimeout(700) + expect(await offered(card)).toMatchObject({ title: 'The activity opens in a new tab', button: true, frame: false }) + expect(played).toBe(0) + await card.locator('#open').click() + expect(sourceIn((await page.evaluate(ASKED))[0]!)).toEqual(SOURCE) + await page.close() + }) + + it('says so where the chat answers no, and gives the address alone where the chat opens no link', async () => { + const refusing = await open('kind=sandboxed&answer=no') + await refusing.card.waitForSelector('#wait.tab') + await refusing.card.locator('#open').click() + await expect.poll(() => refusing.card.locator('#link-note').innerText()).toBe('The chat did not open it. Copy this link into your browser’s address bar.') + await refusing.page.close() + + const { page, card } = await open('kind=sandboxed&opens=no') + await card.waitForSelector('#wait.tab') + expect(await offered(card)).toMatchObject({ title: 'Open the activity in your browser', button: false, link: true }) + expect(await card.locator('#link-note').innerText()).toBe('Copy this link into your browser’s address bar.') + expect(sourceIn(await card.locator('#link-address').inputValue())).toEqual(SOURCE) + await page.close() + }) +}) + +describe('the card, where a chat lets the play page be framed', () => { + it('frames the page and offers no tab', async () => { + const { page, card } = await open('kind=framed&theme=dark') + await card.waitForSelector('#page.on') + expect(await offered(card)).toMatchObject({ frame: true, button: false, link: false }) + expect(await card.locator('#wait').isVisible()).toBe(false) + expect(await card.locator('#page').getAttribute('src')).toMatch(new RegExp(`^${SITE}/h5p/play/\\?theme=dark#source=`)) + expect(played).toBe(1) + expect(await page.evaluate(ASKED)).toEqual([]) + await page.close() + }) + + it('shows a page that speaks from the frame, whatever was concluded before', async () => { + const { page, card } = await open('kind=framed', 1500) + await card.waitForSelector('#page[src]', { state: 'attached' }) + // The browser's word that the frame was refused, where the page then plays all the same. + await card.evaluate(`document.dispatchEvent(new SecurityPolicyViolationEvent('securitypolicyviolation', { + blockedURI: ${JSON.stringify(`${SITE}/h5p/play/`)}, violatedDirective: 'frame-src', effectiveDirective: 'frame-src', originalPolicy: "frame-src 'none'", documentURI: location.href, disposition: 'enforce', statusCode: 200 + }))`) + await card.waitForSelector('#wait.tab') + expect(await offered(card)).toMatchObject({ title: 'The activity opens in a new tab', button: true, frame: false }) + await card.waitForSelector('#page.on') + expect(await offered(card)).toMatchObject({ frame: true, button: false }) + expect(await card.locator('#wait').isVisible()).toBe(false) + await page.close() + }) +}) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 89e99e63..019a8d90 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -236,6 +236,9 @@ importers: '@types/node': specifier: ^26.6.6 version: 26.6.6 + playwright-core: + specifier: ^1.65.1 + version: 1.65.1 typescript: specifier: ^7.0.2 version: 7.0.2 From 0e8680435d03a9d9e221b1dba8f384c4f1ede9b6 Mon Sep 17 00:00:00 2001 From: Aleksandr Shevchuk Date: Wed, 25 Nov 2026 10:19:24 +0200 Subject: [PATCH 2/2] docs(mcp): the tab is the chat's own, which no sandbox holds; one the card opened itself would keep it, as probed in three engines (#274) --- design/mcp.md | 6 ++++-- packages/mcp/README.md | 3 ++- packages/mcp/lib/card.html | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/design/mcp.md b/design/mcp.md index 182e518e..39329152 100644 --- a/design/mcp.md +++ b/design/mcp.md @@ -132,8 +132,10 @@ command is that handler on a port. Its endpoint is `/mcp`. frame `blob:` and `data:` only, its `frameDomains` dropped). The card then shows one state in the loader's place, as tall as what it says: what happens, and "Open the activity", which asks the chat to open the play page's address with the source in it - (`ui/open-link`, or ChatGPT's `openExternal`). The tab is the chat's to open: one opened from - a sandboxed card keeps the sandbox, in all three engines. Whether a tab opened is not the + (`ui/open-link`, or ChatGPT's `openExternal`). The tab is the chat's to open, from its own + page, which no sandbox holds. One the card opened itself, by a link with `target="_blank"`, + would keep the card's sandbox and have no origin either (probed in Chromium, Firefox and + WebKit, 2026-11-25). Whether a tab opened is not the card's to see, so the address is there to copy from the first press on, and at once in a chat that opens no link. The page's own word from the frame takes the card back: a wrong conclusion never hides a player that works. The chat's theme is ChatGPT's `window.openai.theme` or MCP diff --git a/packages/mcp/README.md b/packages/mcp/README.md index 4146a9e4..989c6b48 100644 --- a/packages/mcp/README.md +++ b/packages/mcp/README.md @@ -78,7 +78,8 @@ Its endpoint is `/mcp`, with no sign-in. It has two tools: `h5p_types`, as above which checks an activity's source and shows the card. The card frames the play page of [missing-elements.github.io](https://missing-elements.github.io/h5p/), which builds the activity in the person's browser and plays it there. In a chat app that does not let a card frame a page, or -gives the card no origin of its own, the card offers the same page in a new tab instead. +gives the card no origin of its own, the card asks the chat to open the same page in a new tab +instead, and shows the page's link to copy in case none opens. What the server receives, and what it keeps: diff --git a/packages/mcp/lib/card.html b/packages/mcp/lib/card.html index 1dbd569c..88d35e5c 100644 --- a/packages/mcp/lib/card.html +++ b/packages/mcp/lib/card.html @@ -145,7 +145,8 @@ // no origin was sandboxed without one, and a sandbox passes to every frame inside: the page there // has no Service Worker to play with, so no frame is tried (Open WebUI 0.13.4, November 2026). // And where a chat refuses the frame, the browser says so (Claude, the same month). The tab is -// the chat's to open: one opened from a sandboxed card keeps the sandbox. +// the chat's to open, from its own page: one the card opened itself, by a link, would keep the +// card's sandbox, and the page in it would have no origin either. let address = '' let tabbed = false let spoke = false