diff --git a/apps/mcp-worker/tests/worker.test.ts b/apps/mcp-worker/tests/worker.test.ts index dd0d4b2..0044663 100644 --- a/apps/mcp-worker/tests/worker.test.ts +++ b/apps/mcp-worker/tests/worker.test.ts @@ -78,6 +78,9 @@ describe('the app server as a Worker', () => { const { resources } = await ask(hosted, 'resources/list') expect(resources[0].uri).toBe(server.cardUri) expect(await ask(hosted, 'resources/read', { uri: server.cardUri })).toEqual(await ask(local, 'resources/read', { uri: server.cardUri })) + // And an earlier card's address, for a chat that kept one from before a change (#278). + const earlier = 'ui://h5p-play/card-df8ccbdd2aa8.html' + expect((await ask(hosted, 'resources/read', { uri: earlier })).contents[0].text).toBe((await ask(local, 'resources/read', { uri: server.cardUri })).contents[0].text) }) it('answers the endpoint and nothing else, and no body over 1 MB', async () => { diff --git a/design/mcp.md b/design/mcp.md index bc3c4cb..d668e5c 100644 --- a/design/mcp.md +++ b/design/mcp.md @@ -141,7 +141,9 @@ command is that handler on a port. Its endpoint is `/mcp`. shows the card and not the model, so a card drawn from the result alone, with no input, plays all the same (#276). 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. + the address carries the card's hash; and an earlier card's address gets this card, since a chat + may ask one it kept from before the card changed (#278): Grok could not load the app after #277 + was deployed ("read-resource failed: 400", 2026-11-25), while ChatGPT's old replies played on. - **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 diff --git a/packages/mcp/lib/app.mjs b/packages/mcp/lib/app.mjs index 63738ee..704bb6d 100644 --- a/packages/mcp/lib/app.mjs +++ b/packages/mcp/lib/app.mjs @@ -1,6 +1,6 @@ import { createHash } from 'node:crypto' import { readFile } from 'node:fs/promises' -import { McpServer, createMcpHandler } from '@modelcontextprotocol/server' +import { McpServer, ResourceNotFoundError, ResourceTemplate, createMcpHandler } from '@modelcontextprotocol/server' import { z } from 'zod' import { SourceError, buildPackage } from '@missing-elements/h5p-author' import { SOURCE_PROPERTIES, TYPES, answer, heldLines, refusal, typeAnswers } from './answers.mjs' @@ -203,8 +203,17 @@ export async function createApp(options = {}) { } }) - mcp.registerResource('h5p-play-card', cardUri, { title: 'H5P activity', mimeType: 'text/html;profile=mcp-app', _meta: cardMeta }, - async (uri) => ({ contents: [{ uri: uri.href, mimeType: 'text/html;profile=mcp-app', text: card, _meta: cardMeta }] })) + mcp.registerResource('h5p-play-card', cardUri, { title: 'H5P activity', mimeType: CARD_TYPE, _meta: cardMeta }, + async (uri) => ({ contents: [{ uri: uri.href, mimeType: CARD_TYPE, text: card, _meta: cardMeta }] })) + // An earlier card's address gets this card (#278): a chat may keep the tool list, or a reply it + // drew, from before the card changed, and ask that address again. Grok did after #277 was + // deployed, and could not load the app ("read-resource failed: 400", 2026-11-25); ChatGPT keeps + // the card it fetched. This card plays what an earlier one was handed. Not listed. + mcp.registerResource('h5p-play-card-earlier', new ResourceTemplate('ui://h5p-play/card-{hash}.html', { list: undefined }), { title: 'H5P activity', mimeType: CARD_TYPE, _meta: cardMeta }, + async (uri, { hash }) => { + if (typeof hash !== 'string' || !/^[0-9a-f]{12}$/.test(hash)) throw new ResourceNotFoundError(uri.href) + return { contents: [{ uri: uri.href, mimeType: CARD_TYPE, text: card, _meta: cardMeta }] } + }) return mcp } diff --git a/packages/mcp/tests/app.test.ts b/packages/mcp/tests/app.test.ts index 018245a..230a042 100644 --- a/packages/mcp/tests/app.test.ts +++ b/packages/mcp/tests/app.test.ts @@ -109,6 +109,13 @@ describe('the app server', () => { const { contents } = await client.readResource({ uri }) const card = contents[0] as { mimeType: string, text: string, _meta: Record } expect(card.mimeType).toBe('text/html;profile=mcp-app') + // An earlier card's address gets this card: a chat may ask one it kept from before a change (#278). + const earlier = await client.readResource({ uri: 'ui://h5p-play/card-df8ccbdd2aa8.html' }) + expect(earlier.contents[0]).toMatchObject({ uri: 'ui://h5p-play/card-df8ccbdd2aa8.html', mimeType: 'text/html;profile=mcp-app', text: card.text }) + expect((earlier.contents[0] as { _meta: unknown })._meta).toEqual(card._meta) + await expect(client.readResource({ uri: 'ui://h5p-play/card-latest.html' })).rejects.toThrow(/not found/i) + // One card is listed. + expect((await client.listResources()).resources.map((resource) => resource.uri)).toEqual([uri]) expect(card.text).toContain("const SITE = 'https://missing-elements.github.io'") expect(card.text).not.toContain('__SITE__') expect(card._meta.ui.csp.frameDomains).toEqual(['https://missing-elements.github.io'])