Why Prefab
Prefab began as a DSL for building MCP Apps as part of FastMCP. MCP Apps are an extension of the Model Context Protocol that lets MCP servers render fully interactive UIs directly inside the chat — dashboards, forms, data tables, visualizations — not as static text, but as live interfaces the user can interact with while talking to an agent. Building an MCP App means shipping a self-contained UI bundle. For TypeScript SDK users, that’s natural — they’re already in the JavaScript ecosystem. But the vast majority of MCP servers are written in Python, and for those developers, building an MCP App means spinning up an entirely new project in an entirely new language, tightly coupled to their server with no shared types or enforcement. Prefab eliminates that gap entirely: describe your UI in Python, right next to your server logic, and Prefab compiles it to a production React bundle.The design philosophy
The goal isn’t to port React to Python. Developers who want to build rich, bespoke frontends will — and should — reach for the best tools in the JavaScript ecosystem. Prefab is built on a different insight: the vast majority of interactive experiences appropriate for MCP are not full-fledged web applications. They are forms of information delivery, visualization, and collection. When an agent pulls a large dataset from a database, the user today must choose between asking the agent to summarize it (losing detail) or dumping it into the chat (losing structure). An interactive data table with sorting and filtering is a better answer. When an agent needs structured input, a form beats a multi-turn conversation. When results need context, summary cards and charts communicate more than paragraphs of text. These use cases don’t need the infinite complexity of a full frontend stack. They need a relatively small number of composable components — layout, typography, forms, data display, charts — with enough interactivity for data delivery and collection to cover the vast majority of scenarios. Prefab is a JSON protocol by design, not just a Python library. This means agents can dynamically construct new UIs on the fly — rendering interfaces that no developer predefined. An agent can decide, mid-conversation, to show a chart, build a form, or compose a dashboard from components, all by producing JSON that the renderer already knows how to paint.The landscape
There is a rich ecosystem of projects bringing frontend development to Python — Streamlit, Gradio, NiceGUI, Reflex, and many others. Most assume a running Python server that manages state and serves the UI. FastUI pioneered a different approach: a declarative component protocol rendered by a separate frontend. Prefab builds directly on that insight, from a different starting point — MCP and agent-native use cases where the UI may not have a server at all. The renderer compiles JSON to real React — production components with state management, forms, and declarative interactivity — and ships as a self-contained static bundle. The Python side has no transport dependencies: it works with MCP servers via FastMCP, with REST APIs via FastAPI, or with anything else that can produce JSON. Prefab is made with 💙 by Prefect.How It Works
The core idea is a pipeline: JSON → React. For Python authors, it’s Python → JSON → React.- A component tree is described — in Python via the DSL, or as raw JSON from any source
- The tree serializes to Prefab’s JSON wire format
- A React renderer (shipped as
@prefecthq/prefab-uion npm) compiles the JSON into a live interface
{{ query }}, the renderer interpolates the current value of query from client-side state. Actions like CallTool and SetState update that state, keeping the UI reactive.
Here’s a simpler example — type in the input and watch the heading update in real time:
Installation
What’s in the Box
Quickstart
Install, create an app, see it render. Two minutes, no prerequisites.
Components
35+ components: layout, typography, forms, data display, and interactive elements. Nest them with Python context managers.
Actions
Declarative interactivity — state updates, server calls, navigation, and toast notifications. Chain them with lifecycle callbacks.
Expressions
Templates, operators, and pipes — build reactive UIs with
{{ }} syntax, no server required.