Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions design/mcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,25 @@ 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, 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
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
Expand All @@ -132,9 +151,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.
Expand Down
10 changes: 10 additions & 0 deletions design/scope.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion packages/mcp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ 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 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:

Expand Down
110 changes: 102 additions & 8 deletions packages/mcp/lib/card.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>H5P activity</title>
<style>
:root { color-scheme: light dark; --border: light-dark(#d9d6d0, #3a3833); --surface: light-dark(#f1eeea, #24231f); --text: light-dark(#1c1b19, #f2f0ec); --muted: light-dark(#6b6862, #a8a49c); --accent: light-dark(#2f6db5, #7fb0ea); }
:root { color-scheme: light dark; --border: light-dark(#d9d6d0, #3a3833); --surface: light-dark(#f1eeea, #24231f); --text: light-dark(#1c1b19, #f2f0ec); --muted: light-dark(#6b6862, #a8a49c); --accent: light-dark(#2f6db5, #7fb0ea); --accent-ink: light-dark(#ffffff, #10233b); }
/* A root of its own for the margins inside: a height short by one left a scroller in the card. */
body { display: flow-root; margin: 0; font: 14px/1.4 system-ui, sans-serif; color: var(--text); background: transparent; }
[hidden] { display: none !important; }
Expand All @@ -18,22 +18,35 @@
.wait { z-index: 1; display: grid; place-items: center; align-content: center; gap: 12px; margin: 8px; padding: 0 16px; aspect-ratio: 16 / 9; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); text-align: center; }
.wait p { margin: 0; font-weight: 600; }
.wait small { color: var(--muted); font-size: 13px; }
/* Where the chat cannot play the activity in its reply: what happens, and the one thing to press.
As tall as what it says, not the player's place, since no player comes. */
.wait.tab { aspect-ratio: auto; padding: 28px 16px; }
.wait.tab small { max-width: 46ch; }
.wait button { font: inherit; font-weight: 600; padding: 7px 12px; border: 1px solid var(--border); border-radius: 8px; background: transparent; color: var(--text); cursor: pointer; }
.wait #open { padding: 10px 18px; border-color: var(--accent); background: var(--accent); color: var(--accent-ink); }
.wait button:hover { filter: brightness(1.08); }
.wait button:focus-visible, .wait input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.link { display: grid; gap: 8px; justify-items: center; width: min(100%, 440px); }
.link-row { display: flex; gap: 6px; width: 100%; }
.link-row input { flex: 1; min-width: 0; padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; background: transparent; color: var(--muted); font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; }
@media (prefers-reduced-motion: no-preference) { .spinner { animation: turn 0.8s linear infinite; } }
@keyframes turn { to { rotate: 1turn; } }
</style>
</head>
<body>
<div class="stage">
<div class="wait" id="wait" role="status"><div class="spinner" id="spinner"></div><p id="wait-title">Opening the activity…</p><small id="wait-note">It is built in your browser.</small></div>
<div class="wait" id="wait" role="status"><div class="spinner" id="spinner"></div><p id="wait-title">Opening the activity…</p><small id="wait-note">It is built in your browser.</small>
<button type="button" id="open" hidden>Open the activity</button>
<div class="link" id="link" hidden><small id="link-note"></small><span class="link-row"><input id="link-address" readonly aria-label="The activity's link"><button type="button" id="link-copy">Copy</button></span></div></div>
<iframe id="page" title="The H5P activity" allow="fullscreen; clipboard-write"></iframe>
</div>
<script>
// Runs whatever happens to the script below: a card that cannot go on says so, in place of a
// loader that turns for good.
window.addEventListener('error', () => {
const wait = document.getElementById('wait')
if (!wait || wait.hidden) return
if (!wait || wait.hidden || wait.classList.contains('tab')) return
document.getElementById('spinner').hidden = true
document.getElementById('wait-title').textContent = 'The activity could not be opened'
document.getElementById('wait-note').textContent = 'Ask the chat to show it again.'
Expand Down Expand Up @@ -70,8 +83,7 @@
// The chat's theme, for the card and for the page it frames.
let theme = null
let revealed = false
function themed() {
const now = openai()?.theme
function themed(now = openai()?.theme) {
if ((now !== 'light' && now !== 'dark') || now === theme) return
theme = now
document.documentElement.style.colorScheme = now
Expand All @@ -98,16 +110,26 @@
if (!source || typeof source !== 'object' || !source.type) return
shown = true
const fragment = await fragmentOf(source)
address = PLAY + fragment
themed()
if (self.origin === 'null') return void inTab()
// The page loads behind the card's own loader, and takes its place once it has something drawn
// to show: its first word, or its load at the latest. Nothing is blank in between.
frame.addEventListener('load', () => setTimeout(reveal, 300), { once: true })
frame.src = PLAY + (theme ? `?theme=${theme}` : '') + fragment
sizeToContent()
}

function reveal() {
if (revealed) return
function reveal(spoken = false) {
if (spoken) spoke = true
// A frame the chat refused loads all the same, with nothing in it: only the page's own word
// takes the card back from the tab it offers.
if (tabbed ? !spoke : revealed) return
if (tabbed) {
tabbed = false
frame.hidden = false
$('wait').classList.remove('tab')
}
revealed = true
// Until the page says its own height, it keeps the loader's: the reply does not shrink and grow again.
if (!frame.style.height) frame.style.height = `${Math.round($('wait').getBoundingClientRect().height + 16)}px`
Expand All @@ -118,6 +140,71 @@
sizeToContent()
}

// Where the page cannot play in the card's frame, the card offers the activity in a tab, where
// the whole player runs (#274). It knows from the browser, never from a chat's name. A card with
// 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, 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
let opening = 0
function inTab() {
if (tabbed || spoke || !address) return
tabbed = true
frame.classList.remove('on')
frame.hidden = true
$('spinner').hidden = true
$('wait').classList.add('tab')
$('wait').hidden = false
$('link-address').value = address
drawTab()
}
function drawTab() {
if (!tabbed) return
const opens = typeof openai()?.openExternal === 'function' || !!capabilities?.openLinks
$('wait-title').textContent = opens ? 'The activity opens in a new tab' : 'Open the activity in your browser'
$('wait-note').textContent = '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.'
$('open').hidden = !opens
// A chat that opens no link: the address is all there is to give.
if (!opens) copyThis('Copy this link into your browser’s address bar.')
sizeToContent()
}
function copyThis(why) {
$('link-note').textContent = why
$('link').hidden = false
sizeToContent()
}
const refused = () => copyThis('The chat did not open it. Copy this link into your browser’s address bar.')
document.addEventListener('securitypolicyviolation', (event) => {
if (String(event.blockedURI).startsWith(SITE)) inTab()
})
$('open').addEventListener('click', () => {
// Whether a tab opened is not the card's to see: a browser may stop one, and a chat answers
// the same. So the address is shown from the first press on.
copyThis('A new tab should have opened. If none did, copy this link into your browser’s address bar.')
try {
if (typeof openai()?.openExternal === 'function') void Promise.resolve(openai().openExternal({ href: address })).catch(refused)
else { opening = ++asked; toHost({ id: opening, method: 'ui/open-link', params: { url: address } }) }
} catch { refused() }
})
$('link-address').addEventListener('focus', () => $('link-address').select())
$('link-copy').addEventListener('click', async () => {
let copied = false
try {
await navigator.clipboard.writeText(address)
copied = true
} catch {
// No clipboard for a card without an origin: the browser's older way, and the address left
// selected for the person's own keys where that fails too.
$('link-address').select()
try { copied = document.execCommand('copy') } catch { /* selected, at least */ }
}
if (copied) $('link-copy').textContent = 'Copied'
})

// The file the person attached, as the server handed it on in the tool's result: its id in the
// chat's store, and its name and type. Never its address: the card asks the chat for that.
let attached = null
Expand Down Expand Up @@ -208,7 +295,7 @@
window.addEventListener('message', (event) => {
const message = event.data
if (event.source !== frame.contentWindow || event.origin !== SITE || message?.source !== 'h5p-play') return
reveal()
reveal(true)
if (message.type === 'height' && Number.isFinite(message.height)) {
frame.style.height = `${Math.max(120, Math.min(message.height, 2000))}px`
sizeToContent()
Expand Down Expand Up @@ -236,6 +323,7 @@
let saidSaves = false
let saidOpens = false
function sayWhatTheChatDoes() {
drawTab()
if (!revealed) return
if (!saidOpens && (typeof openai()?.openExternal === 'function' || capabilities?.openLinks)) {
saidOpens = true
Expand Down Expand Up @@ -295,8 +383,14 @@
else if (message.method === 'ui/notifications/tool-result') fromResult(message.params?._meta, message.params?.structuredContent)
else if (message.id === 1 && !message.method) {
if (message.result) capabilities = message.result.hostCapabilities ?? null
themed(message.result?.hostContext?.theme)
if (!message.error) toHost({ method: 'ui/notifications/initialized', params: {} })
sayWhatTheChatDoes()
} else if (message.method === 'ui/notifications/host-context-changed') {
themed(message.params?.theme)
} else if (opening && message.id === opening && !message.method) {
opening = 0
if (message.error || message.result?.isError === true) refused()
} else if (saving.has(message.id) && !message.method) {
const id = saving.get(message.id)
saving.delete(message.id)
Expand Down
1 change: 1 addition & 0 deletions packages/mcp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"devDependencies": {
"@modelcontextprotocol/client": "^2.4.0",
"@types/node": "^26.6.6",
"playwright-core": "^1.65.1",
"typescript": "^7.0.2",
"vitest": "^5.1.0"
},
Expand Down
Loading