
Setup
Install FastMCP with theapps extra, which pulls in Prefab UI:
A Tool That Returns a UI
When your tool has something to show (a table of results, a chart, a status dashboard) you can return an interactive UI instead of text. Build the visualization with Prefab components, return it from your tool, and setapp=True so FastMCP knows to render it. The user sees a live, interactive widget right in the conversation instead of a wall of JSON.
Create server.py:
server.py
app=True is doing a lot behind the scenes. It tells FastMCP to set up everything the MCP Apps protocol requires: the renderer resource, the content security policy, the metadata that tells the host “this tool returns a UI.” Without it, you’d wire all of that up by hand. With it, you just return Prefab components and FastMCP handles the rest. The host (Claude Desktop, Goose, etc.) loads the result in a sandboxed iframe where the user can sort columns, search, and interact, all client-side with no round-trips to your server.
The Prefab code itself reads top-to-bottom like a document. PrefabApp() is the root container and everything inside its with block becomes the app’s UI. Column arranges children vertically. Heading renders a title. DataTable takes rows of data and column definitions, and gives you sorting and search for free. The with blocks establish parent-child relationships: nesting components inside each other builds the layout tree.
Running It
FastMCP includes a dev server that renders your app tools in a browser, no MCP host needed:http://localhost:8080 where you can pick a tool and see the rendered UI. Try sorting the table columns and typing in the search box.
Making It Interactive
The table above is a static snapshot that renders once from the data your Python code provides. But Prefab apps can also respond to user interaction in real time, without any server round-trips. The key concept is state: a client-side key-value store that components read from and write to. When the user interacts with a component, it updates state. Other components that reference that state re-render instantly. See the Prefab state docs for the full guide. Here’s the same directory, but now clicking a row shows that person’s details in a card:
server.py
SetState + on_row_click is the interaction. When the user clicks a table row, SetState("selected", Rx("$event")) writes the clicked row’s data into the selected state key. $event is a special variable that contains the event payload (in this case, the row dict).
Rx("selected.name") reads from state reactively. It doesn’t hold a Python value. It compiles to a browser-side expression that re-evaluates live whenever selected changes. So Text(Rx("selected.name")) always shows the name of whoever was last clicked.
If(STATE.selected) conditionally renders the detail card only when something has been selected. Before any click, selected is None and the card is hidden.
The state dict on PrefabApp sets initial values when the app loads. Run fastmcp dev apps server.py again and try clicking a row.
Next Steps
You’ve built a tool that returns an interactive, reactive UI. This pattern covers a huge range of use cases: build a visualization in Prefab, return it from a tool, and the user gets dashboards, charts, data tables, and status displays right in the conversation. When you need the UI to talk back to your server (forms that save data, buttons that trigger actions, search that queries a database) you promote the tool to a FastMCPApp. That gives you managed backend tools, automatic visibility control, and stable routing so your UI’s button clicks reach the right server-side code.- Prefab UI covers the full component library: charts, forms, badges, progress bars, and the reactive state system in depth.
- FastMCPApp is the next step when your UI needs to interact with backend logic.
- App Providers are ready-made capabilities you can add with a single
add_provider()call.

