FerriteDocs

MCP Apps

Show an interactive view beside the conversation: serve a ui:// resource from your Ferrite application, link it to a tool, and talk to the host from the page.

An MCP App is a small web page a tool can show in the conversation. A booking tool can show a calendar, an order tool a board with the stages of each order, and the person works with the view while the assistant keeps the thread. The client loads the page in a sandboxed frame, and the page talks to it over postMessage, so your application never needs the client’s session.

MCP Apps use the extension identifier io.modelcontextprotocol/ui. A client without it still gets the tool’s ordinary result, so write the result first and the view second.

Serve a view

In an application built with agent-ready, return the page from PageSource::mcp_ui_resources() and name the tools that show it:

use crate::agent_ready::mcp_face::UiResource;

fn mcp_ui_resources(&self) -> Vec<UiResource> {
    vec![UiResource {
        uri: "ui://shop/board.html".into(),
        name: "board".into(),
        title: Some("Order board".into()),
        description: Some("Open orders, grouped by stage.".into()),
        html: include_str!("ui/board.html").into(),
        tools: vec!["list_orders".into()],
    }]
}

The MCP face serves the page through resources/read as text/html;profile=mcp-app, and the list_orders entry in tools/list carries _meta.ui.resourceUri. Nothing else in your tool changes.

Talk to the host

The page sends and receives JSON-RPC messages through window.parent.postMessage. It introduces itself, waits for the tool’s result, draws it, and answers when the host is about to remove it:

let nextId = 1;
const waiting = new Map();

function request(method, params) {
  const id = nextId++;
  window.parent.postMessage({ jsonrpc: "2.0", id, method, params }, "*");
  return new Promise((resolve, reject) => waiting.set(id, { resolve, reject }));
}

window.addEventListener("message", (event) => {
  if (event.source !== window.parent) return;
  const message = event.data;
  if (!message || message.jsonrpc !== "2.0") return;
  if (message.method === undefined && waiting.has(message.id)) {
    const { resolve, reject } = waiting.get(message.id);
    waiting.delete(message.id);
    message.error ? reject(new Error(message.error.message)) : resolve(message.result);
  } else if (message.method === "ui/notifications/tool-result") {
    draw(message.params.structuredContent);
  } else if (message.method === "ui/resource-teardown") {
    // Save anything unfinished, then let the host remove the frame.
    window.parent.postMessage({ jsonrpc: "2.0", id: message.id, result: {} }, "*");
  }
});

(async () => {
  await request("ui/initialize", {
    protocolVersion: "2026-01-26",
    appInfo: { name: "Order board", version: "1.0.0" },
    appCapabilities: {},
  });
  window.parent.postMessage(
    { jsonrpc: "2.0", method: "ui/notifications/initialized", params: {} },
    "*",
  );
})();

After that, the page can call your tools through the host with tools/call, send a message into the conversation with ui/message, and report its height with ui/notifications/size-changed. The host decides whether to allow a call and may ask the person first.

Build a page that works in a frame

  • Keep the HTML, CSS and JavaScript in one file. The default sandbox lets a page load nothing from the network; declare the origins a page needs.
  • Draw from the tool result the host sends. Do not put private data in the page itself, which is the same for every caller.
  • Insert values with textContent. Anything a customer typed is untrusted, in a view as on a page.
  • Support narrow widths and both colour schemes. The view may sit beside a conversation on a phone.
  • Keep every action available as a tool, and let the tool enforce permission. A view adds a way to call it and no authority.
  • Show a loading state until ui/notifications/tool-result arrives.

For ChatGPT and Codex, gpt-plugins provides the same model with OpenAI’s extensions and submission packaging.

Next

MCP Skills teaches an assistant when to open a view. WebMCP & OpenAPI covers the reverse case, where an assistant works inside your own site.

Ferrite counts page views on this site. Privacy · Terms · Support