Day 5, 25 minutes · advanced
Why it matters
To show results as a card in a ChatGPT plugin, you write one HTML file, link it to a tool through a tool setting, and serve it from your MCP server as a resource.
A list of kayaks in plain text works, but a small card with the free kayaks is easier to scan, and the plugin pages say a card is worth building only when the visual part helps. Ingrid's card is deliberately tiny, because this is the part you can least test without ChatGPT itself.
You build the card as one HTML file, link it to the free kayaks tool through a tool setting, and serve it from the server. ChatGPT runs the page in a sandbox and sends it the tool result through a small message bridge. You check the parts you can check on your own computer: the tool points at the card, and the card is served with the right type. You write down plainly which parts you could not see.
How a card is built
The plugin UI follows the MCP Apps standard. Three pieces:
- The tool has
_meta.ui.resourceUri, which names the card, for exampleui://moorhen/free-kayaks-v1.html. - The resource at that address returns the page, with the MIME type
text/html;profile=mcp-app. - The page talks to ChatGPT with JSON-RPC messages over
postMessage: it sendsui/initialize, then the notificationui/notifications/initialized, and then receivesui/notifications/tool-result, which carries the samestructuredContentthe tool returned.
The card in this lesson uses only those messages and draws with plain textContent and createElement. It never puts tool data into HTML as markup, which keeps data from becoming code. The protocolVersion string in the card is the one the OpenAI quickstart shows; check the page when you write your own.
Settings on the resource
The resource's _meta.ui can hold: prefersBorder (draw a border), csp (the sites the card may call: connectDomains, resourceDomains, frameDomains) and domain. The submission page says a domain is required at submission for a plugin with UI. The card here loads nothing from outside, so it needs no csp entries.
Cache
The address of the resource works as a cache key: the docs say to publish a new address after a breaking change to the HTML, JavaScript or CSS. So when you change the page, give it a new address, such as ...-v2.html, and change resourceUri to match, then Refresh the plugin.
What you can and cannot check
You can check that tools/list shows _meta.ui.resourceUri on the tool, and that resources/list and resources/read return the page with the right MIME type. The card's script was also run against a stand-in for the browser, which showed that it sends the two start messages and draws the list from a result. It was not seen rendered in ChatGPT, so you need to open it there yourself.
The steps
- Write
kayak_card.htmlin two parts. - Link the free kayaks tool to the card.
- Serve the card from
moorhen_ui.py. - Check the link with the Inspector command line.
- Open it in ChatGPT after Refresh, if your account allows.
Pick your tool below and follow the steps.
If something fails
- No card in ChatGPT: check
resourceUriequals the resource address exactly, then Refresh. - An old card still shows: the address is cached. Use a new address.
- A blank card: the page never sent
ui/initialize, or sent it before the page was ready.
Common mistakes
- Putting tool data into the page with
innerHTML. - Editing the page without changing its address.
- Building a card where plain text would do.
Today's actions
Ticks are not saved without an accountDo it in OpenAI API
OpenAI API
- Create
kayak_card.htmland paste part one: the style, the markup and the message helper.<!doctype html> <html lang="en"> <meta charset="utf-8"> <title>Free kayaks</title> <style> body { font-family: system-ui, sans-serif; margin: 0; padding: 12px; } h2 { font-size: 1rem; margin: 0 0 8px; } ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; } li { padding: 8px 10px; border: 1px solid #c9d2dc; border-radius: 8px; } </style> <body> <h2 id="title">Free kayaks</h2> <ul id="list"></ul> <script type="module"> let counter = 0; const waiting = new Map(); const send = (message) => window.parent.postMessage({ jsonrpc: "2.0", ...message }, "*"); const request = (method, params) => new Promise((resolve, reject) => { const id = ++counter; waiting.set(id, { resolve, reject }); send({ id, method, params }); }); - Add part two to the end of the same file: it draws the list and starts the conversation with ChatGPT.
function show(result) { const data = result && result.structuredContent; if (!data) return; document.getElementById("title").textContent = "Free kayaks on " + data.date; const list = document.getElementById("list"); list.replaceChildren(); for (const kayak of data.kayaks) { const item = document.createElement("li"); item.textContent = kayak.name + " (" + kayak.kind + ")"; list.append(item); } if (!data.kayaks.length) list.textContent = "No free kayaks that day."; } window.addEventListener("message", (event) => { if (event.source !== window.parent) return; const message = event.data; if (!message || message.jsonrpc !== "2.0") return; if (typeof message.id === "number" && waiting.has(message.id)) { const entry = waiting.get(message.id); waiting.delete(message.id); if (message.error) entry.reject(message.error); else entry.resolve(message.result); } else if (message.method === "ui/notifications/tool-result") { show(message.params); } }); await request("ui/initialize", { appInfo: { name: "free-kayaks", version: "0.1.0" }, appCapabilities: {}, protocolVersion: "2026-01-26", }); send({ method: "ui/notifications/initialized", params: {} }); </script> </body> </html> - In
moorhen.py, find themeta=line abovedef list_free_kayaks(the first one) and replace it with the line below. The tool now names its card.meta={"securitySchemes": [{"type": "noauth"}], "ui": {"resourceUri": "ui://moorhen/free-kayaks-v1.html"}}, - Create
moorhen_ui.py: it imports your sign-in tools and serves the card as a resource.import os from pathlib import Path import moorhen_signin # noqa: F401 (adds the sign-in tools to the same server) from moorhen import server URI = "ui://moorhen/free-kayaks-v1.html" card_meta = {"prefersBorder": True} if os.environ.get("PUBLIC_URL"): card_meta["domain"] = os.environ["PUBLIC_URL"] @server.resource( URI, name="free-kayaks-card", mime_type="text/html;profile=mcp-app", meta={"ui": card_meta}, ) def free_kayaks_card() -> str: return Path("kayak_card.html").read_text(encoding="utf-8") if __name__ == "__main__": server.run(transport="streamable-http") - Stop the old server, run
python moorhen_ui.pyand callnpx @modelcontextprotocol/inspector --cli http://localhost:3000/mcp --transport http --method tools/list. FindresourceUrionlist_free_kayaks. - Run the same command with
--method resources/list, then--method resources/read --uri ui://moorhen/free-kayaks-v1.html. The type must betext/html;profile=mcp-appand the text must be your page. - In ChatGPT select Refresh on your plugin, start a new chat and ask which kayaks are free on 2027-06-12. If your account shows a card, note what it showed.
- Write
card-notes.txtwith two lists: what you saw on your own computer, and what needs ChatGPT (the card rendering, the border, the cache).
Note: The card logic was run only against a stand-in for the browser, not in ChatGPT. The page address is a cache key: use a new address for every changed page. The domain setting is required at submission for a plugin with UI.
Paid planSeeing the card needs the same plan and role as lesson 3. The local checks need none.
Create a free account to save your progress
Free, and no payment details. Your ticks and finished lessons are kept, on every device.
Create a free account I already have an accountCreate a free account to save your progress. Sign in or sign up