Skip to content

Proposal: Stream HTML resources for MCP Apps #603

Closed

Description

@domfarolino

Problem

MCP Apps relies on resources/read returning the full app content as a single HTML string or base64 blob. This approach ignores the inherent streamability of both HTTP and HTML, and introduces a performance bottleneck for larger applications.

Web performance best practices rely heavily on streaming HTML, and browsers are designed to parse HTML chunks as they arrive over the network, build the DOM progressively, and initiate requests for subresources (like CSS and JS) as soon as their tags are parsed (possibly by a preload parser).

But by forcing the HTML to be fully buffered into a JSON string property:

  1. Time to first paint is delayed: The user sees a blank screen until the entire JSON payload is downloaded and parsed.
  2. Memory overhead: Large strings are kept in memory for parsing.
  3. Loss of parallelism: The browser cannot begin fetching styles or scripts referenced in the top of the HTML until the full document is received.

Workarounds

Since normal HTTP is streamable, the host could stream the JSON response of a UI resource and extract the HTML string contents on the fly, all using fetch() + ReadableStream + some hacks or the coming streamHTMLUnsafe() API. But this gets messy:

  • We'd need a chunk-aware parser to ignore everything until we hit the "text": " key. From there, we'd stream characters directly until we hit the matching unescaped closing quote.
  • Escaping: HTML content in JSON must have quotes and special characters escaped, meaning we couldn't just dump the raw character stream; we would have to unescape characters on the fly (e.g., turning \" back into ").
  • Base64: If the content is a base64 blob, we'd have to handle this specially and apply the right decoding strategy. base64 is actually easy to decode as a stream, but all of this adds nuisance to the implementation.

Proposal: Stream HTML content directly from URL

To unlock the performance of streaming while avoiding changes to the MCP Resource interface where "text" is defined, I propose introducing a way for the server to convey to the host, a streamable URL containing the actual HTML body.

You can imagine a new key like htmlUri sitting alongside resourceUri in the McpUiToolMeta that points to the HTML resource.

{
  "name": "my-tool",
  "description": "...",
  "_meta": {
    "ui": {
      "resourceUri": "ui://my-app-resource",
      "htmlUri": "http://localhost:3001/streamable-app.html"
    }
  }
}

With this tool response, the host would trigger a resources/read to resourceUri, and in parallel, a fetch() to htmlUri. Then once it receives the UI metadata, it could pipe the response body into the frame and progressively render the app, letting the HTML parser incrementally discover and fetch any external resources.

Backwards compatibility

Of course we'd need to find a way for the host to communicate this capability to the server, so that the server knows it understands the htmlUri field, and will use it to fetch the body instead of "text" in the resource body. I presume this could be done with something in https://modelcontextprotocol.io/specification/draft/basic/lifecycle#capability-negotiation or some other purpose-built mechanism.

But for now, is there any interest in this? /cc @AbhiGemTest @bricedp.

P.S. Prefetching mitigation

I've heard that some implementers maybe prefetch all View UI content before it is needed (do I remember this correctly from discussions last week, @ochafik?). Perhaps for those hosts, this isn't really an issue since the UI content is available ✨ instantly 🪄. But as long as this isn't mandated, and for hosts that implement a different strategy because they detect that the user is on slow internet or is otherwise data-constrained, it seems like some kind of native streaming support would best take advantage of the platform primitives that power most of the web!

Activity

  1. added
    enhancement
    on Apr 6, 2026
  2. self-assigned this
    on Apr 6, 2026
  3. liady commented on Apr 6, 2026

    @liady
    Contributor

    Hi @domfarolino, thanks for opening this! We indeed looked into external URLs solutions in the past, and in fact the original MCP-UI spec had an external URL type that the server could specify instead of sending an HTML payload (and the client would then render this URL in an iframe). Early clients like Goose and Postman supported this feature as well.

    In MCP Apps we chose to keep only the raw HTML payload, since most hosts prefered to be able to pre-fetch / pre-cache the HTML contents itself, for auditability, security and performance reasons.

    As you mentioned - in hosts where the resource HTML is already present in the time of the tool call the streaming problem is "solved" - since this HTML is either being fed into an iframe's srcDoc, or is served from a pre-hosted URL, which already utilizes the browser's streaing capabilities.
    Also important to note that in hosts that support internal iframes inside the raw HTML content - there's a "workaround" for the server to "mimic" an external URL behavior.

    If we generalize this issue - it sounds like we need to re-open the (more general) discussion about supporting external URLs as a new type of resource payload (in addition to the current raw HTML). These should probably be in the resource level, and not on the tool, either as meta or a different type. This will solve the streaming requirement as well. There was a similar issue opened in January. There are "hacks" around it but no official support.

    What do you think about generalizing it to a general support request for external URLs inresources? Sounds like these overlap almost completely (in requirements and pros/cons considerations). We could indeed use capabilities negotiation so the servers will know what to send.

    If there is a strong use case (for example a major host that doesn't care about pre-fetching/caching/auditability of resources) - I think we can indeed explore it again.

  4. icopp commented on May 1, 2026

    @icopp

    For whatever it's worth as context from an end user, I've been trying to put together basic MCP App embeds for my company to allow an "AI native" workflow around the way we handle rich media (in particular, media players that dynamically compose the rendered video in real time), and the "only an HTML blob" structure has been kind of a nightmare from the start and eaten up a huge amount of time compared to what I thought would have been the basic structure of iframes + CSP stuff + postMessage payloads.

    The idea of any host pre-caching things is an anti-feature I've been actively working around, because we fix and add functionality to our media handling all the time. Even with strict idiomatic handling with everything driven off tool inputs/results (so that a given result never has to worry about supporting future features), any embed that just has the HTML and JS cached as a single blob means that next week (or maybe the next day, if there's bad timing vs a release) it'll be missing bugfixes.

    There's also been the general complications of the implied workflow expecting pre-built static HTML and that having cascading implications for the whole build stack. To get that to work with our more general frontend stack in a way that avoids having multiple kinds of build tooling simultaneously, I've ended up doing hacky stuff similar to the Vercel Next MCP Apps example project (though I suspect I'm still missing something, since I've been running into repeated issues with local inspector apps like MCPJam).

    On a side note, the idea of hosts auditing resources in any useful way feels unlikely to me. As can be seen by these workarounds being possible in the first place, it's both possible and likely that any really complicated embedded rendering will just be an empty shell that fetches everything from a CSP-approved server at runtime, for the same kind of code update reasons but also because if you've got a huge amount of JS it'll be the only way to get a decent immediate loading experience.

  5. arindamb23 commented on May 13, 2026

    @arindamb23

    Problem

    MCP Apps relies on resources/read returning the full app content as a single HTML string or base64 blob. This approach ignores the inherent streamability of both HTTP and HTML, and introduces a performance bottleneck for larger applications.

    Web performance best practices rely heavily on streaming HTML, and browsers are designed to parse HTML chunks as they arrive over the network, build the DOM progressively, and initiate requests for subresources (like CSS and JS) as soon as their tags are parsed (possibly by a preload parser).

    But by forcing the HTML to be fully buffered into a JSON string property:

    1. Time to first paint is delayed: The user sees a blank screen until the entire JSON payload is downloaded and parsed.
    2. Memory overhead: Large strings are kept in memory for parsing.
    3. Loss of parallelism: The browser cannot begin fetching styles or scripts referenced in the top of the HTML until the full document is received.

    Workarounds

    Since normal HTTP is streamable, the host could stream the JSON response of a UI resource and extract the HTML string contents on the fly, all using fetch() + ReadableStream + some hacks or the coming streamHTMLUnsafe() API. But this gets messy:

    • We'd need a chunk-aware parser to ignore everything until we hit the "text": " key. From there, we'd stream characters directly until we hit the matching unescaped closing quote.
    • Escaping: HTML content in JSON must have quotes and special characters escaped, meaning we couldn't just dump the raw character stream; we would have to unescape characters on the fly (e.g., turning \" back into ").
    • Base64: If the content is a base64 blob, we'd have to handle this specially and apply the right decoding strategy. base64 is actually easy to decode as a stream, but all of this adds nuisance to the implementation.

    Proposal: Stream HTML content directly from URL

    To unlock the performance of streaming while avoiding changes to the MCP Resource interface where "text" is defined, I propose introducing a way for the server to convey to the host, a streamable URL containing the actual HTML body.

    You can imagine a new key like htmlUri sitting alongside resourceUri in the McpUiToolMeta that points to the HTML resource.

    {
    "name": "my-tool",
    "description": "...",
    "_meta": {
    "ui": {
    "resourceUri": "ui://my-app-resource",
    "htmlUri": "http://localhost:3001/streamable-app.html"
    }
    }
    }
    With this tool response, the host would trigger a resources/read to resourceUri, and in parallel, a fetch() to htmlUri. Then once it receives the UI metadata, it could pipe the response body into the frame and progressively render the app, letting the HTML parser incrementally discover and fetch any external resources.

    Backwards compatibility

    Of course we'd need to find a way for the host to communicate this capability to the server, so that the server knows it understands the htmlUri field, and will use it to fetch the body instead of "text" in the resource body. I presume this could be done with something in https://modelcontextprotocol.io/specification/draft/basic/lifecycle#capability-negotiation or some other purpose-built mechanism.

    But for now, is there any interest in this? /cc @AbhiGemTest @bricedp.

    P.S. Prefetching mitigation

    I've heard that some implementers maybe prefetch all View UI content before it is needed (do I remember this correctly from discussions last week, @ochafik?). Perhaps for those hosts, this isn't really an issue since the UI content is available ✨ instantly 🪄. But as long as this isn't mandated, and for hosts that implement a different strategy because they detect that the user is on slow internet or is otherwise data-constrained, it seems like some kind of native streaming support would best take advantage of the platform primitives that power most of the web!

    For anyone hitting this today: while waiting for native htmlUri streaming, the existing ontoolinputpartial primitive (documented for

     tag updates in the Patterns guide) can also be used to stream complete HTML documents into a sandboxed iframe via iframe.srcdoc updates throttled at ~60ms (~16fps). The host's JSON-healing handles unclosed tags so partial markup parses safely. Working pattern shipped May 2026 in our internal multi-tenant MCP platform — happy to share a code snippet if useful. Native htmlUri would be architecturally cleaner (true HTTP streaming, no JSON-healing tax, no postMessage round-trips per chunk), but the workaround works in production today on Claude.ai.

  6. arindamb23 commented on May 13, 2026

    @arindamb23

    For anyone hitting this today: while waiting for native htmlUri streaming, the existing ontoolinputpartial primitive (documented for

     tag updates in the Patterns guide) can also be used to stream complete HTML documents into a sandboxed iframe via iframe.srcdoc updates throttled at ~60ms (~16fps). The host's JSON-healing handles unclosed tags so partial markup parses safely. Working pattern shipped May 2026 in our internal multi-tenant MCP platform — happy to share a code snippet if useful. Native htmlUri would be architecturally cleaner (true HTTP streaming, no JSON-healing tax, no postMessage round-trips per chunk), but the workaround works in production today on Claude.ai.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions