From Tool Results to an Interactive View with MCP Apps
A tool returns a list of articles. Reading it is easy; refreshing it is where a chat transcript starts to feel awkward.

A tool returns a list of articles. Reading it is easy; refreshing it is where a chat transcript starts to feel awkward.
An interactive View can give that result a useful next action without making the model describe another button click. We'll connect a journal-listing tool to bundled HTML, deliver results through the host bridge, and keep a text response for hosts that cannot display the View.
Link a tool to an HTML resource
Core MCP supports more than plain text, including structured and resource content. Interactive UI is provided by the optional MCP Apps extension, not by a universal React component schema. A custom application/vnd.mcp.ui+json payload is an application-specific format, not the standardized Apps contract.
Examples are illustrative, not claims of deployed production behavior.
Use compatible MCP SDK v2, @modelcontextprotocol/ext-apps 2, and Zod 4 packages in a separate example project. _meta.ui.resourceUri links the tool to a predeclared ui:// resource. RESOURCE_MIME_TYPE is text/html;profile=mcp-app. The text result remains useful without UI support. Pass self-contained, built HTML into this factory and serve it through the SDK transport; the factory alone does not start a server.
// app-server.ts
import { McpServer } from "@modelcontextprotocol/server";
import {
registerAppTool, registerAppResource, RESOURCE_MIME_TYPE,
} from "@modelcontextprotocol/ext-apps/server";
import * as z from "zod/v4";
export function createJournalApp(bundledHtml: string) {
const server = new McpServer({ name: "journal-app", version: "1.0.0" });
const resourceUri = "ui://journal/discovery.html";
registerAppTool(server, "list_journal", {
description: "List the demonstration journal entry.",
inputSchema: z.object({}).strict(),
_meta: { ui: { resourceUri } },
}, async () => {
const articles = [{
title: "MCP Apps: Interactive Journal Discovery",
slug: "mcp-ui-server-driven-interactive-components",
}];
return {
content: [{ type: "text", text: articles.map((item) => item.title).join("\n") }],
structuredContent: { articles },
};
});
registerAppResource(server, "journal-view", resourceUri, {
mimeType: RESOURCE_MIME_TYPE,
}, async () => ({
contents: [{
uri: resourceUri,
mimeType: RESOURCE_MIME_TYPE,
text: bundledHtml,
_meta: { ui: { csp: { connectDomains: [], resourceDomains: [] } } },
}],
}));
return server;
}Build the iframe View
Save this HTML and view.ts together, then bundle JavaScript and dependencies inline using the official quickstart's build setup before passing the result as bundledHtml. Browsers cannot execute this bare TypeScript or resolve npm imports directly. The empty external-resource CSP matches a self-contained View, not arbitrary CDN scripts.
<!doctype html>
<html lang="en">
<head><meta charset="utf-8"><title>Journal discovery</title></head>
<body>
<div id="articles"></div>
<button id="refresh" type="button" disabled>Refresh</button>
<p id="error" role="alert"></p>
<script type="module" src="./view.ts"></script>
</body>
</html>// view.ts: bundle this script into the HTML before serving the resource
import { App } from "@modelcontextprotocol/ext-apps";
import * as z from "zod/v4";
const root = document.querySelector<HTMLElement>("#articles");
const button = document.querySelector<HTMLButtonElement>("#refresh");
const error = document.querySelector<HTMLElement>("#error");
if (!root || !button || !error) throw new Error("Missing journal View elements.");
const Result = z.object({
articles: z.array(z.object({ title: z.string(), slug: z.string() })),
});
const app = new App({ name: "journal-view", version: "1.0.0" });
const reportError = (reason: unknown) => {
console.error("Journal View failed:", reason);
error.textContent = "The journal request failed. Please retry.";
};
const render = (value: unknown) => {
const { articles } = Result.parse(value);
root.replaceChildren(...articles.map((article) => {
const row = document.createElement("p");
row.textContent = article.title;
return row;
}));
error.textContent = "";
};
app.ontoolresult = (result) => {
try {
if (result.isError) throw new Error("The tool reported an error.");
render(result.structuredContent);
} catch (reason) {
reportError(reason);
}
};
button.addEventListener("click", async () => {
button.disabled = true;
try {
const result = await app.callServerTool({ name: "list_journal", arguments: {} });
if (result.isError) throw new Error("The tool reported an error.");
render(result.structuredContent);
} catch (reason) {
reportError(reason);
} finally {
button.disabled = false;
}
});
app.connect().then(() => { button.disabled = false; }).catch(reportError);Both the first tool result and a refresh reach the same render function. That function validates the article list before creating text nodes. The button is a new route to the tool, not a new source of trusted data or permission.
Connect through the host
The View's App connects to the host, receives initial tool results, and requests refresh through callServerTool. Register the result handler before connecting. Validate returned data, use text nodes instead of innerHTML, and show failures. React can render inside this View but is not required. Custom hosts must implement the sandbox, capability negotiation, and an AppBridge connection; rendering HTML or React directly in the host DOM is not equivalent.
Security and compatibility
MCP Apps support varies by host and must be negotiated. Enforce tool allowlists, permission checks, Origin/source checks in message handling, and narrowly scoped CSP at the host boundary. Shadow DOM and CSS scoping are not security sandboxes. UI clicks do not bypass backend authorization. Retire bridge connections on teardown and test unsupported hosts, denied actions, malformed data, and resource-load failures. Do not advertise a custom registry as universally interoperable.
About the embedded demonstration
This portfolio's embedded card is a local React simulation, not an MCP Apps host. Filters use fixed local data; no MCP server, tool transport, iframe sandbox, or AppBridge runs. The example-data tab illustrates protocol objects rather than captured traffic.
The visible card is only one piece of the integration. The host must connect it, constrain it, and authorize its requests. Keep that contract separate from the visual design, and you can explain precisely what a working MCP App does that a standalone React card does not.