From f9bc565cda11c5435957d55af26a88fb458d66f5 Mon Sep 17 00:00:00 2001 From: Aleksandr Shevchuk Date: Wed, 2 Dec 2026 09:54:51 +0200 Subject: [PATCH 1/2] fix(mcp-app): the card's domain is ChatGPT's alone (#329) Claude refuses a card whose _meta.ui.domain is not its own hash of the connector's address. domain is now written only as openai/widgetDomain, which ChatGPT reads; other chats pick their own. --- design/mcp.md | 9 +++++---- packages/mcp-app/README.md | 4 ++-- packages/mcp-app/bin/h5p-mcp-app.mjs | 4 ++-- packages/mcp-app/lib/app.mjs | 6 +++--- packages/mcp-app/tests/app.test.ts | 5 +++-- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/design/mcp.md b/design/mcp.md index 78c72690..ca92e4df 100644 --- a/design/mcp.md +++ b/design/mcp.md @@ -229,10 +229,11 @@ command is that handler on a port. Its endpoint is `/mcp`. by a stand-in card that hands it a file, and in the card itself; in ChatGPT itself ran the probe's card, which this one is without its test parts. -- **The card names an origin of its own only where a host gives one** (#307), as `domain`: ChatGPT - asks for one to submit an app (`_meta.ui.domain`, an origin; `openai/widgetDomain` is its alias), - and MCP Apps leaves the value's form to each chat, so no default suits them all. The card's - address takes it into its hash. +- **The card names an origin of its own for ChatGPT alone** (#307), as `domain`: ChatGPT asks for + one to submit an app and reads it from `openai/widgetDomain`. It is not written to + `_meta.ui.domain`, whose form MCP Apps leaves to each chat: Claude refuses a card whose + `ui.domain` is not its own hash of the connector's address (#329), and picks its own when none + is given. The card's address takes `domain` into its hash. - **A host runs `createApp()`, the package's main export, with its own site and name.** It takes the play page's `site`, the `build` page a chat with no card is sent to, missing-elements.github.io's by default, which the card may open too, and the server's `title`; and, for a bundle such as a Cloudflare Worker, what diff --git a/packages/mcp-app/README.md b/packages/mcp-app/README.md index 2d32eef3..4cebc80c 100644 --- a/packages/mcp-app/README.md +++ b/packages/mcp-app/README.md @@ -23,8 +23,8 @@ Its endpoint is `/mcp`, with no sign-in, and the play page is at `/h5p/play/`. I - `--build`: the build page a chat with no card is sent to, [missing-elements.github.io's](https://missing-elements.github.io/h5p/build/) by default. - `--title`: the name the server gives itself. -- `--domain`: the card's own origin, in the chat's own form. ChatGPT takes an origin, as - `https://lessons.example`, and asks for one to submit an app. None by default. +- `--domain`: the card's own origin in ChatGPT, as `https://lessons.example`, which it asks for + to submit an app. Other chats pick their own. None by default. It has two tools: `h5p_types`, which lists the content types and says how to write each one, and `h5p_play`, which checks an activity's source and shows the card. diff --git a/packages/mcp-app/bin/h5p-mcp-app.mjs b/packages/mcp-app/bin/h5p-mcp-app.mjs index d5adc147..a2fe3a3f 100755 --- a/packages/mcp-app/bin/h5p-mcp-app.mjs +++ b/packages/mcp-app/bin/h5p-mcp-app.mjs @@ -23,8 +23,8 @@ Options: https://missing-elements.github.io/h5p/build/ by default --title the name the server gives itself in a chat; H5P Author MCP by Missing Elements by default - --domain the card's own origin, in the chat's own form: ChatGPT takes an origin, - as https://example.org, and asks for one to submit an app; none by default + --domain the card's own origin in ChatGPT, as https://example.org, which it asks + for to submit an app; other chats pick their own; none by default --version -h, --help ` diff --git a/packages/mcp-app/lib/app.mjs b/packages/mcp-app/lib/app.mjs index 63746397..a1319d7d 100644 --- a/packages/mcp-app/lib/app.mjs +++ b/packages/mcp-app/lib/app.mjs @@ -12,7 +12,7 @@ import { SOURCE_PROPERTIES, TYPES, answer, heldLines, refusal, skillCatalog, typ * @typedef {object} AppOptions * @property {string} [site] the origin of the site whose play page the card frames; by default the origin each request was sent to, where the command serves the page * @property {string} [build] the build page's address, which a chat with no card hands the source to and the card may open; missing-elements.github.io's by default - * @property {string} [domain] the card's own origin, in the chat's own form (#307): ChatGPT takes an origin, as `https://example.org`, and asks for one to submit an app; none by default + * @property {string} [domain] the card's own origin in ChatGPT (#307), as `https://example.org`, which it asks for to submit an app; other chats pick their own (#329); none by default * @property {string} [title] the name the server gives itself, which a chat shows; `H5P Author MCP by Missing Elements` by default * @property {string} [libraries] the pack's `parts/` folder to check with; the installed pack by default * @property {string} [references] the folder of the author package's type files and brief, its `references/`, with the skill's `SKILL.md` and `LICENSE` beside it, as in the package; the installed package's by default @@ -123,7 +123,7 @@ export async function createApp(options = {}) { // The build page is missing-elements.github.io's, wherever the play page is (#299). const build = web(options.build ?? BUILD, 'build').href const title = options.title ?? TITLE - // Each chat reads it its own way, so its form is not checked here beyond being one word. + // ChatGPT's alone: Claude checks `ui.domain` against a form of its own (#329), so it is not written there. const domain = options.domain if (domain !== undefined && !/^\S{1,255}$/.test(domain)) throw new Error(`domain is not a card's origin, as https://example.org: ${domain}`) // A Worker's bundle (#272) has no package folder for `import.meta` to find: it passes `version` and `card`. @@ -148,7 +148,7 @@ export async function createApp(options = {}) { // The card's policy: the one site it frames, and the chat's file store, which it asks for the // attached file. Written twice, as the MCP Apps specification places it and as ChatGPT reads it. const cardMeta = { - ui: { csp: { frameDomains: [site], connectDomains: FILE_HOSTS, resourceDomains: FILE_HOSTS }, prefersBorder: true, ...(domain ? { domain } : {}) }, + ui: { csp: { frameDomains: [site], connectDomains: FILE_HOSTS, resourceDomains: FILE_HOSTS }, prefersBorder: true }, ...(domain ? { 'openai/widgetDomain': domain } : {}), 'openai/widgetCSP': { frame_domains: [site], connect_domains: FILE_HOSTS, resource_domains: FILE_HOSTS, redirect_domains: [...new Set([site, new URL(build).origin])] }, 'openai/widgetDescription': 'Plays the H5P activity, built in the person\'s browser, with its download.' diff --git a/packages/mcp-app/tests/app.test.ts b/packages/mcp-app/tests/app.test.ts index 121808f5..05fd21a3 100644 --- a/packages/mcp-app/tests/app.test.ts +++ b/packages/mcp-app/tests/app.test.ts @@ -350,8 +350,9 @@ describe('the app server', () => { expect(meta).not.toHaveProperty('openai/widgetDomain') } const named = await cardOf({ domain: 'https://lesson.example' }) + // ChatGPT's alone: Claude refuses a `ui.domain` that is not its own hash of the connector's address. for (const meta of named.metas) { - expect(meta.ui.domain).toBe('https://lesson.example') + expect(meta.ui.domain).toBeUndefined() expect(meta['openai/widgetDomain']).toBe('https://lesson.example') } // A chat keeps a card by its address: a card given an origin has another. @@ -408,7 +409,7 @@ describe('the app server', () => { return JSON.parse(text.split('\n').find((line) => line.startsWith('data: '))?.slice(6) ?? text).result } const uri = (await ask('tools/list', {})).tools.find((tool: { name: string }) => tool.name === 'h5p_play')._meta['openai/outputTemplate'] - expect((await ask('resources/read', { uri })).contents[0]._meta.ui.domain).toBe('https://card.example') + expect((await ask('resources/read', { uri })).contents[0]._meta['openai/widgetDomain']).toBe('https://card.example') } finally { other.kill() } From 163513e8d9af82f272904a7d93feec69b29b8263 Mon Sep 17 00:00:00 2001 From: Aleksandr Shevchuk Date: Wed, 2 Dec 2026 12:28:50 +0200 Subject: [PATCH 2/2] fix(mcp-app): the card's own origin in each chat's form (#329) Claude's ui.domain is the first 32 hex of the SHA-256 of the connector's address with .claudemcpcontent.com, computed from the address each request was sent to; with it, a site framed in the card may keep localStorage. ChatGPT's stays domain, as openai/widgetDomain. The card's address now hashes its policy too, Claude's origin aside, so a chat that keeps the card by its address gets the changed one. --- design/mcp.md | 13 ++++--- packages/mcp-app/README.md | 3 +- packages/mcp-app/bin/h5p-mcp-app.mjs | 3 +- packages/mcp-app/lib/app.mjs | 51 +++++++++++++++++++--------- packages/mcp-app/tests/app.test.ts | 24 +++++++++---- 5 files changed, 65 insertions(+), 29 deletions(-) diff --git a/design/mcp.md b/design/mcp.md index ca92e4df..a8a1545e 100644 --- a/design/mcp.md +++ b/design/mcp.md @@ -229,11 +229,14 @@ command is that handler on a port. Its endpoint is `/mcp`. by a stand-in card that hands it a file, and in the card itself; in ChatGPT itself ran the probe's card, which this one is without its test parts. -- **The card names an origin of its own for ChatGPT alone** (#307), as `domain`: ChatGPT asks for - one to submit an app and reads it from `openai/widgetDomain`. It is not written to - `_meta.ui.domain`, whose form MCP Apps leaves to each chat: Claude refuses a card whose - `ui.domain` is not its own hash of the connector's address (#329), and picks its own when none - is given. The card's address takes `domain` into its hash. +- **The card names an origin of its own in each chat's form** (#307, #329). MCP Apps leaves the + form of `_meta.ui.domain` to each chat. ChatGPT's is `domain`, an origin it asks for to submit + an app, written as `openai/widgetDomain`. Claude's, in `_meta.ui.domain`, is the first 32 hex + of the SHA-256 of the connector's address with `.claudemcpcontent.com`, computed from the + address each request was sent to (`/mcp`, the only path the server answers): Claude shows an + error in place of a card whose `ui.domain` is not that, and lets a site framed in the card use + `localStorage` only with one. The card's address hashes the card and its policy, Claude's origin + aside, which differs by address and not by card. - **A host runs `createApp()`, the package's main export, with its own site and name.** It takes the play page's `site`, the `build` page a chat with no card is sent to, missing-elements.github.io's by default, which the card may open too, and the server's `title`; and, for a bundle such as a Cloudflare Worker, what diff --git a/packages/mcp-app/README.md b/packages/mcp-app/README.md index 4cebc80c..f4d1be74 100644 --- a/packages/mcp-app/README.md +++ b/packages/mcp-app/README.md @@ -24,7 +24,8 @@ Its endpoint is `/mcp`, with no sign-in, and the play page is at `/h5p/play/`. I [missing-elements.github.io's](https://missing-elements.github.io/h5p/build/) by default. - `--title`: the name the server gives itself. - `--domain`: the card's own origin in ChatGPT, as `https://lessons.example`, which it asks for - to submit an app. Other chats pick their own. None by default. + to submit an app. None by default. Claude's is computed from the address it calls, the + connector's, so a proxy in front of the server must pass on the public host. It has two tools: `h5p_types`, which lists the content types and says how to write each one, and `h5p_play`, which checks an activity's source and shows the card. diff --git a/packages/mcp-app/bin/h5p-mcp-app.mjs b/packages/mcp-app/bin/h5p-mcp-app.mjs index a2fe3a3f..a45c7ffc 100755 --- a/packages/mcp-app/bin/h5p-mcp-app.mjs +++ b/packages/mcp-app/bin/h5p-mcp-app.mjs @@ -24,7 +24,8 @@ Options: --title the name the server gives itself in a chat; H5P Author MCP by Missing Elements by default --domain the card's own origin in ChatGPT, as https://example.org, which it asks - for to submit an app; other chats pick their own; none by default + for to submit an app; none by default. Claude's is computed from the + address it calls --version -h, --help ` diff --git a/packages/mcp-app/lib/app.mjs b/packages/mcp-app/lib/app.mjs index a1319d7d..d319922e 100644 --- a/packages/mcp-app/lib/app.mjs +++ b/packages/mcp-app/lib/app.mjs @@ -12,7 +12,7 @@ import { SOURCE_PROPERTIES, TYPES, answer, heldLines, refusal, skillCatalog, typ * @typedef {object} AppOptions * @property {string} [site] the origin of the site whose play page the card frames; by default the origin each request was sent to, where the command serves the page * @property {string} [build] the build page's address, which a chat with no card hands the source to and the card may open; missing-elements.github.io's by default - * @property {string} [domain] the card's own origin in ChatGPT (#307), as `https://example.org`, which it asks for to submit an app; other chats pick their own (#329); none by default + * @property {string} [domain] the card's own origin in ChatGPT (#307), as `https://example.org`, which it asks for to submit an app; none by default. Claude's is computed from the address it calls (#329) * @property {string} [title] the name the server gives itself, which a chat shows; `H5P Author MCP by Missing Elements` by default * @property {string} [libraries] the pack's `parts/` folder to check with; the installed pack by default * @property {string} [references] the folder of the author package's type files and brief, its `references/`, with the skill's `SKILL.md` and `LICENSE` beside it, as in the package; the installed package's by default @@ -80,6 +80,13 @@ const handOver = (build, files) => `hand the activity over to be built in the pe /** Where a chat keeps attached files, which the card asks from the person's browser: ChatGPT's, as seen in November 2026. */ const FILE_HOSTS = ['https://*.blob.core.windows.net', 'https://files.oaiusercontent.com', 'https://*.oaiusercontent.com'] +/** + * The card's own origin in Claude's form (#329): the first 32 hex of the SHA-256 of the connector's + * address, as configured in Claude, which is the address Claude sends its requests to. + * @param {string} connector + */ +const claudeDomain = (connector) => `${createHash('sha256').update(connector).digest('hex').slice(0, 32)}.claudemcpcontent.com` + /** * What of the chat's reference to an attached file goes to the card: its id, and its name and type * where they came. Not its address, which lets its holder read the file and a call could make up. @@ -123,7 +130,8 @@ export async function createApp(options = {}) { // The build page is missing-elements.github.io's, wherever the play page is (#299). const build = web(options.build ?? BUILD, 'build').href const title = options.title ?? TITLE - // ChatGPT's alone: Claude checks `ui.domain` against a form of its own (#329), so it is not written there. + // ChatGPT's, as `openai/widgetDomain`: Claude's is computed from the address it calls (#329). The form + // is ChatGPT's to check, so here it is only one word. const domain = options.domain if (domain !== undefined && !/^\S{1,255}$/.test(domain)) throw new Error(`domain is not a card's origin, as https://example.org: ${domain}`) // A Worker's bundle (#272) has no package folder for `import.meta` to find: it passes `version` and `card`. @@ -137,22 +145,27 @@ export async function createApp(options = {}) { const skills = await skillCatalog({ references: options.references }) /** - * The card, its policy and the MCP handler for the site whose play page the card frames. + * The card, its policy and the MCP handler for the site whose play page the card frames, as + * asked at the connector's address. * @param {string} site + * @param {string} connector */ - function forSite(site) { + function forSite(site, connector) { const card = cardText.replaceAll('__SITE__', site).replaceAll('__BUILD__', new URL(build).origin) - // A chat keeps a card by its address, so a card that changed has another, and so has one - // given another origin of its own. - const cardUri = `ui://h5p-play/card-${createHash('sha256').update(card).update(domain ?? '').digest('hex').slice(0, 12)}.html` // The card's policy: the one site it frames, and the chat's file store, which it asks for the // attached file. Written twice, as the MCP Apps specification places it and as ChatGPT reads it. - const cardMeta = { + const policy = { ui: { csp: { frameDomains: [site], connectDomains: FILE_HOSTS, resourceDomains: FILE_HOSTS }, prefersBorder: true }, ...(domain ? { 'openai/widgetDomain': domain } : {}), 'openai/widgetCSP': { frame_domains: [site], connect_domains: FILE_HOSTS, resource_domains: FILE_HOSTS, redirect_domains: [...new Set([site, new URL(build).origin])] }, 'openai/widgetDescription': 'Plays the H5P activity, built in the person\'s browser, with its download.' } + // A chat keeps a card by its address, policy and all, so a card or a policy that changed has + // another. Claude's origin is left out: it differs by the address a chat calls, not by the card. + const cardUri = `ui://h5p-play/card-${createHash('sha256').update(card).update(JSON.stringify(policy)).digest('hex').slice(0, 12)}.html` + // Claude shows an error in place of a card whose origin is not this; with it, the play page + // framed in the card may keep storage (#329). + const cardMeta = { ...policy, ui: { ...policy.ui, domain: claudeDomain(connector) } } function server() { const mcp = new McpServer({ name: 'h5p-mcp-app', title, version }, { instructions: INSTRUCTIONS }) @@ -252,12 +265,16 @@ export async function createApp(options = {}) { /** @type {Map>} */ const sites = new Map() - /** @param {string} site */ - const held = (site) => { - let found = sites.get(site) + /** + * @param {string} site + * @param {string} connector + */ + const held = (site, connector) => { + const key = `${site} ${connector}` + let found = sites.get(key) if (!found) { - found = forSite(site) - sites.set(site, found) + found = forSite(site, connector) + sites.set(key, found) // Dropped, not closed: a request still running on it finishes. for (const oldest of sites.keys()) { if (sites.size <= SITES_HELD) break @@ -269,19 +286,21 @@ export async function createApp(options = {}) { return { version, - cardUri: fixed === null ? undefined : held(fixed).cardUri, + // The same at every address: Claude's origin is not in it. + cardUri: fixed === null ? undefined : held(fixed, `${fixed}/mcp`).cardUri, /** * @param {Request} request * @returns {Promise} */ async fetch(request) { - const { pathname } = new URL(request.url) + const { origin, pathname, search } = new URL(request.url) // For whoever opens the address, and for a host that asks whether the server is up. if (pathname === '/' && (request.method === 'GET' || request.method === 'HEAD')) return new Response(`${title}: the MCP endpoint is /mcp\n`, { headers: { 'content-type': 'text/plain; charset=utf-8' } }) if (pathname !== '/mcp') return new Response('Not found\n', { status: 404, headers: { 'content-type': 'text/plain; charset=utf-8' } }) // Said before a body is read, where its length is given; the handler holds one that gives none to the same bound. if (Number(request.headers.get('content-length')) > MOST) return new Response('A request takes 1 MB at most\n', { status: 413, headers: { 'content-type': 'text/plain; charset=utf-8' } }) - return held(fixed ?? new URL(request.url).origin).handler.fetch(request) + // The connector's address is the one asked, query and all, as Claude hashes it. + return held(fixed ?? origin, `${origin}/mcp${search}`).handler.fetch(request) }, close: async () => { await Promise.all([...sites.values()].map(({ handler }) => handler.close())) } } diff --git a/packages/mcp-app/tests/app.test.ts b/packages/mcp-app/tests/app.test.ts index 05fd21a3..3f3c218b 100644 --- a/packages/mcp-app/tests/app.test.ts +++ b/packages/mcp-app/tests/app.test.ts @@ -1,4 +1,5 @@ import { spawn, spawnSync, type ChildProcess } from 'node:child_process' +import { createHash } from 'node:crypto' import { mkdir, mkdtemp, readdir, readFile, rm, symlink, writeFile } from 'node:fs/promises' import { request as httpRequest } from 'node:http' import { createServer, type AddressInfo, type Server } from 'node:net' @@ -16,7 +17,9 @@ import { createApp } from '../lib/app.mjs' */ const COMMAND = resolve(import.meta.dirname, '../bin/h5p-mcp-app.mjs') -const META = { language: 'en', license: 'U', authors: [{ name: 'Unknown', role: 'Author' }] } +/** The card's own origin in Claude's form, for a connector's address (#329). */ +const claude = (connector: string) => `${createHash('sha256').update(connector).digest('hex').slice(0, 32)}.claudemcpcontent.com` +const META ={ language: 'en', license: 'U', authors: [{ name: 'Unknown', role: 'Author' }] } const QUIZ = { ...META, type: 'H5P.TrueFalse', title: 'Boiling point', params: { question: '

Water boils at 100 °C at sea level.

', correct: 'true' } } const VIDEO = { ...META, @@ -330,7 +333,7 @@ describe('the app server', () => { await expect(createApp({ site: 'data:text/html,

x

' })).rejects.toThrow(/site is not a web address/) }) - it('names the card\'s own origin only where a host gives one, under both names, in the listing and on the card', async () => { + it('names the card\'s own origin in each chat\'s form, in the listing and on the card', async () => { const cardOf = async (options: Parameters[0]) => { const app = await createApp({ site: 'https://lesson.example', ...options }) const ask = async (method: string, params: unknown) => { @@ -344,15 +347,16 @@ describe('the app server', () => { await app.close() return { uri: app.cardUri, metas: [listed, read] } } + // Claude's, from the address it asked at: Claude shows an error in place of a card with another (#329). const none = await cardOf({}) for (const meta of none.metas) { - expect(meta.ui.domain).toBeUndefined() + expect(meta.ui.domain).toBe(claude('https://lesson.example/mcp')) expect(meta).not.toHaveProperty('openai/widgetDomain') } + // ChatGPT's where a host gives one, under ChatGPT's own name, beside Claude's. const named = await cardOf({ domain: 'https://lesson.example' }) - // ChatGPT's alone: Claude refuses a `ui.domain` that is not its own hash of the connector's address. for (const meta of named.metas) { - expect(meta.ui.domain).toBeUndefined() + expect(meta.ui.domain).toBe(claude('https://lesson.example/mcp')) expect(meta['openai/widgetDomain']).toBe('https://lesson.example') } // A chat keeps a card by its address: a card given an origin has another. @@ -377,6 +381,12 @@ describe('the app server', () => { expect(one.card.text).toContain("const SITE = 'https://lesson.example'") expect(one.card._meta.ui.csp.frameDomains).toEqual(['https://lesson.example']) expect((await cardAt('https://other.example/mcp')).uri).not.toBe(one.uri) + // Claude's origin for the card, as Claude's documentation computes it for this address. + expect((await cardAt('https://example.com/mcp')).card._meta.ui.domain).toBe('c3d80a4ed901ee05b21755a88273b4a4.claudemcpcontent.com') + // Another connector's address for the same site: Claude's origin differs, the card's address does not. + const queried = await cardAt('https://lesson.example/mcp?team=1') + expect(queried.card._meta.ui.domain).not.toBe(one.card._meta.ui.domain) + expect(queried.uri).toBe(one.uri) await app.close() // The command takes the scheme a proxy that ends TLS says, and the host the request names. const card = await new Promise((done, failed) => { @@ -409,7 +419,9 @@ describe('the app server', () => { return JSON.parse(text.split('\n').find((line) => line.startsWith('data: '))?.slice(6) ?? text).result } const uri = (await ask('tools/list', {})).tools.find((tool: { name: string }) => tool.name === 'h5p_play')._meta['openai/outputTemplate'] - expect((await ask('resources/read', { uri })).contents[0]._meta['openai/widgetDomain']).toBe('https://card.example') + const meta = (await ask('resources/read', { uri })).contents[0]._meta + expect(meta['openai/widgetDomain']).toBe('https://card.example') + expect(meta.ui.domain).toBe(claude(`${at}/mcp`)) } finally { other.kill() }