feat(mcp): the card offers the activity in a new tab where a chat cannot play it in a reply (#274)
Closes #274.
Where a chat cannot play the activity inside its reply, the card says so and offers it in a new tab, where the whole player runs. Nothing changes in ChatGPT, on the server or on the play page.
How the card knows
From the browser, never from a chat's name:
- It has no origin (
self.originis"null"). The chat sandboxed it without one, and a sandbox passes to every frame inside, so the play page there could not register its Service Worker. No frame is tried. This is Open WebUI 0.13.4. - The frame is refused. The browser raises
securitypolicyviolationfor the play page's address. This is Claude. - If the page speaks from inside the frame after all, the card shows the page: a wrong conclusion never hides a player that works.
What is seen
One state, in the loader's place and as tall as what it says, in the chat's theme:
| State | Title | Under it |
|---|---|---|
| The chat opens links | The activity opens in a new tab | why, and the button Open the activity |
| After a press | the same | "A new tab should have opened. If none did, copy this link into your browser's address bar.", the address and Copy |
| The chat answers no | the same | "The chat did not open it. Copy this link…", the address and Copy |
| The chat opens no link | Open the activity in your browser | "Copy this link…", the address and Copy, no button |
The button asks the chat to open the play page's address with the source in it (ui/open-link, or ChatGPT's openExternal). A plain link would not do: a tab opened from a sandboxed card keeps the sandbox, in Chromium, Firefox and WebKit. Whether a tab opened is not the card's to see, so the address is there from the first press on. Each state was looked at in light and dark, at 760 px and at a phone's 390 px, in the three engines: no scroller in the card, and Copy works in a card without an origin.
The card now also takes the chat's theme the MCP Apps way (hostContext.theme, and ui/notifications/host-context-changed), which it read only from ChatGPT's window.openai before.
Testing
- New
packages/mcp/tests/card.test.ts, five tests, in the verifier's browser: the card in a chat that sandboxes it as Open WebUI does, under the policy Open WebUI writes from the card's own domains; in one that refuses the frame; and in one that lets the page be framed. Each speaks MCP Apps to the card. Against the card before this change all five fail. - The package's tests: 36 pass in 4 files. The Worker's: 6 pass.
typecheckis clean. - By hand, in Chromium, Firefox and WebKit: the two signals, the four states above, and a page framed as before.
- End to end: from a card sandboxed without an origin, the press reached the stand-in chat as
ui/open-link, the chat opened the tab, and the live play page built and played the True/False sample there ("True False · 882 kB").
Not verified: Claude and Open WebUI themselves, which the card met only as stand-ins built from Open WebUI's source and from the policy Claude was seen to apply.
Notes
playwright-coreis a dev dependency of the package now, for the test's types; the browser is the verifier's own choice (launch).design/mcp.mdhas the rule;design/scope.mdrecords that a player without the Service Worker is not built, with the corpus numbers behind that.- The live server serves the new card once the Worker is deployed again. The card's address changes with its text, so a chat fetches it afresh. No npm release is needed for that.
Summary by cubic
Where a chat cannot play the activity inside its reply, the MCP card now offers it in a new tab instead of hanging on a spinner. The chat opens the tab itself, because a tab opened from a sandboxed card keeps the sandbox and loses its origin, as probed in Chromium, Firefox, and WebKit.
- Detects it from the browser (
self.origin === 'null'orsecuritypolicyviolation), never from a chat's name. - Shows an "Open the activity" button that asks the chat to open the play page, with the address available to copy from the first press on.
- A page that speaks from the frame still takes over, so a wrong conclusion never hides a player that works.
- Reads the chat's theme the MCP Apps way (
hostContext.theme) as well as ChatGPT'swindow.openai. - Adds
tests/card.test.ts, which runs the card in a browser in three stand-in chats, andplaywright-coreas a dev dependency.