Feature

Prefect's Prefab builds MCP app UIs in Python, not React

Source · Generative UI... in Python? — Jeremiah Lowin, Prefect
AI Engineer · Jeremiah Lowin · Prefect · 2026-09-10 uploaded · 18min

한국어·English

Jeremiah Lowin argues that shipping generative UIs to enterprise Python engineers doesn't require pretending they'll write React. He describes Prefab, an open-source Python DSL that composes MCP app interfaces from prebuilt components, and reveals that streaming Python over the wire beats streaming JSON by roughly 70% in size.

  • MCP apps basics — MCP apps, introduced in January this year, let a tool result bypass the agent's context window entirely and reach the user directly as HTML, CSS, and JavaScript.
  • Coming extension — Lowin says a July MCP release will let the agent itself interact with the rendered app, opening use cases like playing chess against the agent inside a visual UI.
  • FastMCP's problem — FastMCP, which Lowin's company maintains, has a user base that is mostly Python engineers, so shipping React from Python was never a serious option.
  • Scoping the users — Because FastMCP users mainly share and collect information in enterprises rather than build branded consumer products, Lowin scoped the tool to tables, forms, and charts.
  • Prefab intro — Prefab, open sourced a few months ago, is a Python DSL where nested context managers build UI structure and each component is a class that renders as a Shadcn component.
  • Reactive variables — An RX class gives client-side reactivity and data binding between components with no JavaScript written.
  • The pipeline — Python builds a declarative representation, which serializes into a JSON protocol, which a React app renders as the actual MCP app; the JSON, not the Python, was the original point.
  • Self-hosted docs — Prefab's documentation for its roughly 130-140 components is rendered entirely in Prefab, and any code example can be popped into a live-editable playground.
  • Interactive tool demo — Returning a Prefab data table component instead of a dictionary from a FastMCP tool automatically triggers FastMCP to generate the full MCP app, shown live in the Goose client with sorting, filtering, and pagination.
  • Composing charts — Adding a pie chart next to the data table required importing a Grid and PieChart class and nesting them, following what Lowin calls Prefect's principle of one line of code, one noticeable change.
  • FastMCP app / uploads — A FastMCP app pairs app.ui and app.tool methods as a full backend, and a built-in upload component fixes what Lowin calls 'the world's most expensive copy paste operation'—an agent retyping a megabyte of text character by character into an MCP server.
  • Fully generative UI — In a demo, Claude streamed a JSON UI protocol live into a rendered interface with no UI defined in advance, healing and rendering the JSON in real time as it arrived.
  • Python beats JSON — Lowin's team found the Python representation of a UI is about 70% smaller than the JSON representation, so FastMCP now streams and sandboxes Python instead of JSON for major token, cost, and latency savings.

In their words

The Python is actually an accident that I discovered after the fact because it was a weird idiosyncratic thing that I wanted. The point of this was can we create a serializable representation of a UI and that's the JSON protocol again.7:54
Jeremiah Lowin slide · Generative UI... in Python? — Jeremiah Lowin, Prefect 7:54
Jeremiah Lowin slide · 7:54 · AI Engineer
So as you can see because only the agent has access to an MCP server you can't simply upload a file to an MCP server. It has to go through the brain of the agent. And so what ends up happening is a lot of people create basically an upload tool on their MCP server forget that the agent has to actually call it. And what you end up doing is the world's most expensive copy paste operation. You give the agent a megabyte of text. the agent retypes it character by character into the MCP and now yes in fact you have uploaded it but it's extremely extremely inefficient.13:28
What we ended up discovering is that the Python representation of a UI is about 70% smaller than the JSON representation.15:59
Jeremiah Lowin slide · Generative UI... in Python? — Jeremiah Lowin, Prefect 15:59
Jeremiah Lowin slide · 15:59 · AI Engineer

Disclosure · Lowin is founder and CEO of Prefect and author of FastMCP; the talk promotes Prefect's open-source Prefab and FastMCP projects.

One thing to add — One thing to add — the pivot from streaming JSON to streaming Python is the most concrete engineering result here, since it directly cuts token cost and latency rather than just improving developer ergonomics. It's also notable that Lowin frames the Python DSL as an "accident," which suggests the serializable JSON layer, not the Python syntax, is the durable design decision.</note> </invoke>

One thing to try tonight
Install the latest FastMCP, import a Prefab component like the data table, and return it instead of a dictionary from a tool function to see an MCP app render automatically in a supporting client.