How to show results as a card in a ChatGPT plugin

Day 5, 25 minutes · advanced

Goal of this lessonAdd a small card to your MCP server that lists the free kayaks, and check how the card and the tool are linked before ChatGPT ever opens it.

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:

  1. The tool has _meta.ui.resourceUri, which names the card, for example ui://moorhen/free-kayaks-v1.html.
  2. The resource at that address returns the page, with the MIME type text/html;profile=mcp-app.
  3. The page talks to ChatGPT with JSON-RPC messages over postMessage: it sends ui/initialize, then the notification ui/notifications/initialized, and then receives ui/notifications/tool-result, which carries the same structuredContent the 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

  1. Write kayak_card.html in two parts.
  2. Link the free kayaks tool to the card.
  3. Serve the card from moorhen_ui.py.
  4. Check the link with the Inspector command line.
  5. 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 resourceUri equals 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 account

Do it in OpenAI API

OpenAI API

  1. Create kayak_card.html and 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 });
        });
    
  2. 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>
    
  3. In moorhen.py, find the meta= line above def 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"}},
  4. 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")
    
  5. Stop the old server, run python moorhen_ui.py and call npx @modelcontextprotocol/inspector --cli http://localhost:3000/mcp --transport http --method tools/list. Find resourceUri on list_free_kayaks.
  6. Run the same command with --method resources/list, then --method resources/read --uri ui://moorhen/free-kayaks-v1.html. The type must be text/html;profile=mcp-app and the text must be your page.
  7. 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.
  8. Write card-notes.txt with 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.

Checked on 4 December 2026 · Source: OpenAI Plugins docs: Build your ChatGPT UI (opens in a new tab)

Create a free account to save your progress. Sign in or sign up