Skip to main content
MCP Apps SDK An MCP App View is an HTML document that the host fetches with resources/read and renders in a sandboxed iframe. Every time it appears in a conversation, the host has to read that resource, parse it, run its scripts, finish the ui/initialize handshake, and wait for the tool result. Each step adds time before the user sees anything useful. This page covers where that time goes and what you control.

Where Load Time Goes

The tool call usually dominates. A slow API call inside the tool handler delays the result no matter how small the bundle is, so measure both (see Measuring).

Ship One Self-Contained HTML File

The MCP Apps spec delivers the View as HTML text in a resources/read response. Relative script and stylesheet URLs have nothing to resolve against, and the host’s default CSP blocks external scripts unless you list their origins. The reliable shape is a single HTML document with scripts and styles inline. With plain Vite, vite-plugin-singlefile produces this shape. sunpeak build does it for you. For each resource it:
  • builds an IIFE bundle with Vite, targeting es2020, minified
  • injects the compiled CSS into the bundle, so there’s no separate stylesheet
  • wraps the bundle in an HTML shell with a single inline <script>
  • writes dist/{resource}/{resource}.html and a metadata file whose uri includes a build timestamp, such as ui://review-mhx2k9q1
Two consequences follow from the single-file IIFE format:
  • Dynamic import() and React.lazy() don’t create separate chunks. Everything ends up in the one file. Lazy components can still delay execution, but not download.
  • Static assets imported from your source, such as import logo from './logo.png', are inlined as base64 data URIs. A 200 KB PNG adds about 270 KB to every load of that View.
The timestamped URI means each deploy gets a new resource URI. Hosts that cache resource HTML by URI fetch the new version instead of serving a stale one.

Bundle Size Budget

For reference, the four resources in the sunpeak starter template build to these sizes: Most of the baseline is React, the MCP Apps SDK, and its Zod schemas. A single large dependency, like a map library, can quadruple it. Before adding a package to a View, check its built size and ask whether the server could do the work instead. Ways to cut size:
  • Move work to the server. Parse files, render Markdown, compute aggregates, and format large tables in the tool handler. Send the View the result, not the library.
  • Prefer smaller packages. Date formatting with Intl instead of a date library. Native <dialog> and CSS instead of a component kit.
  • Split heavy features into separate resources. If only one tool needs a chart or a map, give that tool its own resource. Other tools keep the smaller bundle.
  • Watch for duplicate dependencies. Two versions of the same library both end up in the file. Check your lockfile after upgrades.

Images, Fonts, and Other Assets

Since imported assets get inlined, host large images and fonts on a CDN or your own server and reference them by URL. Then allow the origin in the resource’s _meta.ui.csp.resourceDomains:
Set width and height (or a CSS aspect-ratio) so the layout doesn’t jump when images arrive. Layout jumps trigger extra size-changed notifications, and the host may visibly resize the iframe for each one. Small icons are fine to inline. An SVG icon set or a few small PNGs cost less than an extra network round trip from inside the sandbox. For assets that come from the MCP server itself, such as generated images or files, use readServerResource() so they flow through the host’s MCP connection rather than a separate fetch.

Render Before the Result Arrives

Users see an empty frame until your View renders something. Render a skeleton on mount, update from streaming input if the host sends it, and fill in data when the tool result lands.
Streaming tool input gives you arguments while the model is still writing them. It’s best-effort and hosts may not send it at all, so treat it as a preview and never as the final value. Keep top-level module work small. Code that runs at import time, like building lookup tables or parsing large JSON constants, delays the first paint and the handshake.

Keep Payloads Small

The tool result goes through the host to the View as JSON over postMessage. Large results take longer to serialize and parse, and anything in content or structuredContent may also go to the model, which costs tokens and context. See content, structuredContent, and _meta for how each field reaches the model and the View. For lists, return the first page in the tool result and let the View request more. Use an app-only tool (_meta.ui.visibility: ["app"]) for the paging call so the model doesn’t see it.

Avoid Resize Loops

With autoResize on (the default in App and sunpeak’s AppProvider), the SDK watches your document and sends ui/notifications/size-changed when its size changes. A layout that depends on the iframe’s own height can loop: content grows, the host grows the iframe, content grows again. Common causes:
  • height: 100vh or h-screen on a container while the host lets height grow
  • elements sized as a percentage of a parent with no fixed height
  • animations or carousels that change height every frame
Use content height when the host gives you only maxHeight, and fill the space only when the host sets a fixed height. The Layout and Display page has the full contract.

Zod Parsing Under Strict CSP

The MCP Apps SDK validates every message with Zod. Zod’s fastest object parser uses new Function(), which needs CSP unsafe-eval, and host CSPs usually don’t allow it. So the App constructor turns on Zod’s jitless mode by default, which works under the default CSP but parses more slowly. AppOptions.allowUnsafeEval: true skips that and keeps the JIT parser. Only set it if you know the host’s CSP permits unsafe-eval. Otherwise the first message parse throws and the View never connects. For most Views, message parsing is not the bottleneck and the default is the right choice.

Measuring

In sunpeak dev

sunpeak dev adds a small overlay to the bottom-right corner of each resource with:
  • Resource: when the resource HTML was generated, which catches stale cached HTML in a host
  • Tool: how long the most recent tool call took, in milliseconds
If the Tool number is large, profile the handler. If it’s small but the View still feels slow, look at bundle size and first render. To see production numbers, run the inspector against built bundles and real handlers:

In the browser

Record a trace in the Chrome DevTools Performance panel while the inspector renders your tool. The trace includes the sandboxed iframes, so performance.mark() calls inside your View show up in its Timings track:

In tests

Bundle size is easy to track in CI. A check after sunpeak build fails the build when a resource grows past your budget:

Checklist

  • The View renders a skeleton or partial state before the tool result arrives.
  • Large images and fonts load from an allowed CDN domain, not base64 imports.
  • Heavy dependencies live in their own resource or on the server.
  • Tool results keep model-visible fields short and move render-only data to _meta.
  • Paged or on-demand data loads through app-only tools.
  • The layout doesn’t use viewport height when the host lets height grow.
  • CI tracks the gzipped size of each built resource.