Skip to content

πŸš€ The fast, Pythonic way to build MCP servers and clients.

docs: correct the apps pages against main (#6409)

nate nowackf3b18e455eda
diff --git a/docs/apps/architecture.mdx b/docs/apps/architecture.mdx
index bf2287a0f..d47bfe950 100644
--- a/docs/apps/architecture.mdx
+++ b/docs/apps/architecture.mdx
@@ -15,7 +15,7 @@ You don't need this page to build apps. It's for when something isn't rendering
An MCP app moves through five stages from Python to pixels:
-```
+```text
Python components β†’ JSON tree β†’ structuredContent β†’ Renderer iframe β†’ Host UI
```
@@ -47,17 +47,17 @@ When a Prefab tool runs, its return value β€” a `PrefabApp` or a bare `Component
### `PrefabApp.to_json()`
-The entry point is `PrefabApp.to_json()`. It walks the component tree and produces a JSON object with three top-level keys: `view` (the component tree), `state` (initial state values), and `_meta` (routing metadata).
+The entry point is `PrefabApp.to_json()`. It walks the component tree and produces a JSON object with a `$prefab` protocol version, `view` (the component tree), and, when set, `state` (initial state values), `defs`, and theme keys. FastMCP then adds routing metadata under `_meta`, described below.
-FastMCP passes a `tool_resolver` callback to `to_json()`. Whenever the tree contains a `CallTool` action that references a function (not a string), the resolver converts it to a `ResolvedTool` with the function's registered name. For `FastMCPApp` backend tools, that registered name is then wrapped in the deterministic hashed format described below. The resolver also handles `unwrap_result` β€” a flag telling the renderer to unwrap single-value results from the `{"result": value}` envelope FastMCP uses for schema compliance.
+FastMCP passes a `tool_resolver` callback to `to_json()`. The resolver runs on every `CallTool` action in the tree and returns a `ResolvedTool` carrying the tool's name: a function reference resolves to the function's registered name, and a string passes through. For tools that belong to a `FastMCPApp`, that name is then wrapped in the deterministic hashed format described below.
### Hashed backend tool references
-FastMCP still tags app tools with `meta["fastmcp"]["app"]`, but backend routing no longer depends on sending the app name through each tool call. During serialization, FastMCP passes a resolver to `PrefabApp.to_json()`. When the tree contains `CallTool(save_contact)`, the resolver turns it into a deterministic hashed name such as `__<hash>_save_contact`, where the hash is derived from the app name and backend tool name.
+Backend routing does not depend on sending the app name through each tool call. When a `FastMCPApp` tree contains `CallTool(save_contact)`, the resolver turns it into a deterministic hashed name such as `__<hash>_save_contact`, where the hash is the first 12 hex characters of a SHA-256 digest of the app name and backend tool name.
The `__<12 lowercase hex>_<name>` pattern is reserved for these generated addresses. `FastMCPApp` rejects registered backend and UI tool names matching it, so the resolver can distinguish registered names from addresses. This reservation concerns the name sent in tool calls; a component key such as `tool:save@` is a separate lookup identifier. Other double-underscore names, such as `__save`, remain valid.
-That hashed name rides along inside `structuredContent` all the way to the renderer. When the renderer calls the backend tool, it sends the hashed tool name in the normal MCP `tools/call` request. The server recognizes that format and routes through the app-tool lookup path described below.
+FastMCP records each hashed reference in `structuredContent` under `_meta.fastmcp.toolNames`. On the way out, each server rewrites the reference to the name it lists that tool under, as described in [Late-bound tool names](#late-bound-tool-names). A reference no server could rewrite reaches the renderer in hashed form, and the server routes a `tools/call` with that name through the [hashed lookup fallback](#the-hashed-lookup-fallback).
### ToolResult assembly
@@ -87,7 +87,7 @@ The reason is structural. Identity is derived from the app name and the tool's r
FastMCP declines to bind rather than picking a copy, so buttons stop working instead of quietly invoking the wrong tenant's tool. Expect a message naming the cause:
-```
+```text
Ambiguous app tool 'save': 2 components share the identity '10c0803009ff'.
The same app is composed more than once, so this call cannot be routed to a
single tool.
@@ -99,7 +99,7 @@ Give each copy its own app name. Two tenants running the same product want `Fast
Upgrading a server updates both address generation and lookup automatically. If you deploy an app backend and a proxy gateway separately, upgrade both to use the `__` address format; gateways cannot rewrite identity addresses emitted in the earlier `<hash>_<local_name>` format.
-The identity-addressed form `__<hash>_<local_name>` remains callable. FastMCP first tries normal tool resolution; if no tool matches and the name has that shape, it calls `get_tool_by_hash(hash, local_name)`, which resolves the tool through the same lookup as its listed name. Transforms, enabled state, and authorization apply to a hashed name exactly as they do to a name call.
+The identity-addressed form `__<hash>_<local_name>` remains callable. FastMCP first tries normal tool resolution; if no tool matches and the name has that shape, it calls `get_tool_by_hash(hash, local_name)`, which resolves the tool through the same lookup as its listed name. Only tools whose `meta["ui"]["visibility"]` includes `"app"` answer to a hashed name. Transforms, enabled state, and authorization apply to a hashed name exactly as they do to a name call.
When one identity is claimed by more than one tool β€” which happens when the same app is composed into two branches β€” the call is refused rather than resolved, since picking either one would silently route into the wrong branch.
@@ -125,13 +125,13 @@ The resource also carries CSP metadata (via `get_renderer_csp()`) declaring the
The renderer lives in a sandboxed iframe and communicates with the host using `postMessage`. The protocol follows the [MCP Apps extension](https://modelcontextprotocol.io/docs/extensions/apps) spec:
-The host pushes the tool result (with `structuredContent`) into the iframe. The renderer parses the component tree, initializes state, and renders the UI. When the user interacts β€” submitting a form, clicking a button β€” and the interaction triggers a `CallTool` action, the renderer sends a `callServerTool` message back to the host via `postMessage`. The host forwards it as a regular MCP `tools/call` request to the server, using the hashed backend name that FastMCP serialized into the action.
+The host pushes the tool result (with `structuredContent`) into the iframe. The renderer parses the component tree, initializes state, and renders the UI. When the user interacts β€” submitting a form, clicking a button β€” and the interaction triggers a `CallTool` action, the renderer sends a `tools/call` request to the host via `postMessage`. The host forwards it as a regular MCP `tools/call` request to the server, using the tool name in the action.
The response flows back the same way: server β†’ host β†’ iframe via `postMessage`, and the renderer updates state with the result.
### AppBridge
-The `@modelcontextprotocol/ext-apps` JavaScript SDK provides the `App` class (sometimes called AppBridge) that manages the `postMessage` handshake. It handles connection negotiation, tool result delivery, server tool calls, and host context (safe area insets, theme preferences). The Prefab renderer uses it internally; you only touch it directly when building [custom HTML apps](/apps/low-level).
+The `@modelcontextprotocol/ext-apps` JavaScript SDK provides both ends of the `postMessage` handshake: the `App` class runs inside the iframe, and the `AppBridge` class runs in the host. Together they handle connection negotiation, tool result delivery, server tool calls, and host context (safe area insets, theme preferences). The Prefab renderer uses `App` internally; you only touch it directly when building [custom HTML apps](/apps/low-level).
## The dev server
@@ -141,10 +141,10 @@ The `@modelcontextprotocol/ext-apps` JavaScript SDK provides the `App` class (so
Two HTTP servers. Your MCP server runs on port 8000 with the Streamable HTTP transport. The dev UI runs on port 8080 and serves a picker page that lists your app tools.
-A reverse proxy at `/mcp` on the dev server forwards requests to your MCP server. This matters because the renderer iframe runs on `localhost:8080` and your MCP server runs on `localhost:8000` β€” without the proxy, the renderer's `callServerTool` requests would be cross-origin and the browser would block them. The proxy keeps everything same-origin from the iframe's perspective.
+A reverse proxy at `/mcp` on the dev server forwards requests to your MCP server. This matters because the dev UI and your MCP server listen on different ports: the host page's MCP client sends every request, including the renderer's tool calls relayed over `postMessage`, to `/mcp` on its own origin, and the proxy passes them on. Without the proxy, those requests would be cross-origin and the browser would block them.
### The launch flow
-When you select a tool and click launch, the dev UI calls the tool through the proxy, receives the `structuredContent` response, and opens a new tab. That tab loads the tool's renderer resource (via the proxy), creates an AppBridge, and pushes the tool result into the renderer. From here on it matches what a real host provides: the renderer displays the UI, and any `CallTool` actions route back through the proxy to your server.
+When you select a tool and click launch, the dev UI stores the tool name and arguments and opens a new tab. That tab connects to your server through the proxy, creates an AppBridge, and loads the tool's renderer resource. Once the renderer initializes, the tab calls the tool and pushes the result into the renderer. From here on it matches what a real host provides: the renderer displays the UI, and any `CallTool` actions route back through the proxy to your server.
Auto-reload is on by default, so changes to your server code restart the MCP server automatically. The dev UI keeps running β€” relaunch the tool to see changes.
diff --git a/docs/apps/development.mdx b/docs/apps/development.mdx
index c27fab931..c81600b16 100644
--- a/docs/apps/development.mdx
+++ b/docs/apps/development.mdx
@@ -31,9 +31,9 @@ The dev server does three things:
The **picker page** connects to your MCP server, finds all tools with UI metadata, and renders a form for each one. The forms are auto-generated from the tool's input schema β€” text fields, dropdowns, checkboxes, all wired up.
-When you submit a form, the dev server **calls your tool** via the MCP protocol and opens the result in a new tab. Each result page comes from a picker launch and stays available, including on reload, until the dev server stops. The result page loads the tool's UI resource (the Prefab renderer or your custom HTML) inside an AppBridge β€” the same protocol that real MCP hosts use. The resource runs in a sandboxed iframe, so it can't use `localStorage`, open popups, or show `alert` and `confirm` dialogs.
+When you submit a form, the dev UI opens a new tab that **calls your tool** via the MCP protocol and renders the result. Each result page comes from a picker launch and stays available, including on reload, until the dev server stops. The result page loads the tool's UI resource (the Prefab renderer or your custom HTML) inside an AppBridge β€” the same protocol that real MCP hosts use. The resource runs in a sandboxed iframe, so it can't use `localStorage`, open popups, or show `alert` and `confirm` dialogs.
-A **reverse proxy** on `/mcp` forwards requests from the browser to your MCP server, avoiding CORS issues that would otherwise block the iframe-based renderer from talking to a different port.
+A **reverse proxy** on `/mcp` forwards requests from the browser to your MCP server, so the dev UI's MCP client stays same-origin instead of making cross-origin requests to a different port.
## MCP inspector
diff --git a/docs/apps/examples.mdx b/docs/apps/examples.mdx
index 90c25d7dd..c41c9207c 100644
--- a/docs/apps/examples.mdx
+++ b/docs/apps/examples.mdx
@@ -14,32 +14,32 @@ Each tile below is a working FastMCP server you can run with `fastmcp dev apps`
<Columns cols={2}>
<Tile href="#sales-dashboard" title="Sales Dashboard" description="Metrics, charts, and deal pipeline">
<div style={{overflow: "hidden", width: "100%"}}>
- <img src="/apps/images/app-example-sales-dashboard.png" alt="" />
+ <img src="/apps/images/app-example-sales-dashboard.png" alt="Sales dashboard with KPI cards, a monthly revenue chart, and a revenue-by-segment donut chart" />
</div>
</Tile>
<Tile href="#system-monitor" title="System Monitor" description="Live CPU, memory, disk with auto-refresh">
- <img src="/apps/images/app-example-system-dashboard.png" alt="" />
+ <img src="/apps/images/app-example-system-dashboard.png" alt="System monitor with CPU, memory, disk, and uptime stats above a CPU and memory chart" />
</Tile>
<Tile href="#quiz" title="Quiz" description="LLM-generated trivia with scoring">
- <img src="/apps/images/app-example-quiz.png" alt="" />
+ <img src="/apps/images/app-example-quiz.png" alt="Quiz question with multiple-choice answer buttons" />
</Tile>
<Tile href="#interactive-map" title="Interactive Map" description="Geocoded addresses on Leaflet">
- <img src="/apps/images/app-example-map.png" alt="" />
+ <img src="/apps/images/app-example-map.png" alt="Leaflet map of Washington DC with a location marker" />
</Tile>
<Tile href="/apps/providers/file-upload" title="File Upload" description="Drag-and-drop upload provider">
- <img src="/apps/images/app-file-upload.png" alt="" />
+ <img src="/apps/images/app-file-upload.png" alt="File upload drop zone" />
</Tile>
<Tile href="/apps/providers/approval" title="Approval" description="Human-in-the-loop confirmation">
- <img src="/apps/images/app-approval.png" alt="" />
+ <img src="/apps/images/app-approval.png" alt="Confirm Payment card with Cancel and approve buttons" />
</Tile>
<Tile href="/apps/providers/choice" title="Choice" description="Clickable option selection">
- <img src="/apps/images/app-choice.png" alt="" />
+ <img src="/apps/images/app-choice.png" alt="Lunch question with four clickable options" />
</Tile>
<Tile href="/apps/providers/form" title="Form Input" description="Pydantic model forms">
- <img src="/apps/images/app-form.png" alt="" />
+ <img src="/apps/images/app-form.png" alt="Form generated from a Pydantic model" />
</Tile>
<Tile href="/apps/generative" title="Generative UI" description="LLM writes the UI at runtime">
- <img src="/apps/images/app-showcase.png" alt="" />
+ <img src="/apps/images/app-showcase.png" alt="Component showcase with forms, charts, toggles, and a data table" />
</Tile>
</Columns>
diff --git a/docs/apps/fastmcp-app.mdx b/docs/apps/fastmcp-app.mdx
index 199bff1bc..dc702138e 100644
--- a/docs/apps/fastmcp-app.mdx
+++ b/docs/apps/fastmcp-app.mdx
@@ -92,7 +92,7 @@ A fair question. Any [Interactive Tool](/apps/prefab) can call a server tool β€”
App tool visibility is not a security boundary. Backend tools remain callable through direct MCP requests by clients that know their names, subject to the server's authentication and authorization checks. Use [authorization](/servers/authorization) and server-side validation to enforce access and approval requirements; [visibility metadata](/apps/low-level#tool-visibility) only declares the intended audience.
-Composition is handled by never writing the name down. `CallTool` takes a function reference, and FastMCP resolves it when the UI is serialized β€” to whatever that tool is actually called by then. Mount the server under a namespace and the button calls `notes_add_note`; put a gateway in front and it calls whatever the gateway lists. Since you never wrote a name, renaming cannot break it. [The architecture page](/apps/architecture) covers how that resolution works.
+Composition is handled at serialization. Inside a `FastMCPApp`, FastMCP resolves every `CallTool` reference, by name or by function, to whatever that tool is actually called when the UI reaches the host. Mount the server under a namespace and the button calls `notes_add_note`; put a gateway in front and it calls whatever the gateway lists. Renaming cannot break it. [The architecture page](/apps/architecture) covers how that resolution works.
The one rule that comes with this: **an app name must be unique within a server.** Composing the same app twice breaks its UI β€” two copies of `FastMCPApp("notes")` are indistinguishable no matter what namespaces you mount them under, so FastMCP declines to bind rather than picking one. Name apps for what they serve: `FastMCPApp("notes-acme")` and `FastMCPApp("notes-globex")`. [The architecture page](/apps/architecture) explains why identity works this way.
@@ -112,7 +112,7 @@ def dashboard() -> PrefabApp:
return PrefabApp(view=view)
```
-`@app.ui()` supports the same options as `@mcp.tool`: `name`, `description`, `title`, `tags`, `icons`, `auth`, and `timeout`.
+`@app.ui()` accepts `name`, `description`, `title`, `tags`, `icons`, `annotations`, `auth`, and `timeout`.
## `@app.tool()` β€” backend tools
@@ -141,14 +141,14 @@ App tool names matching `__<12 lowercase hex>_<name>` (for example, `__abcdef012
## `CallTool` β€” UI β†’ backend
-`CallTool` is how the UI invokes a backend tool. Pass the tool's name (or a direct function reference):
+`CallTool` is how the UI invokes a backend tool. Pass the tool's name or the function itself; inside a `FastMCPApp`, both resolve to the tool's current address when the UI is serialized:
```python
from prefab_ui.actions.mcp import CallTool
CallTool("save_contact", arguments={"name": "Alice", "email": "[email protected]"})
-# Or a function reference β€” resolves to a stable global key
+# Or pass the function itself
CallTool(save_contact, arguments={...})
```
@@ -317,18 +317,18 @@ def create_bug(data: BugReport) -> str:
## Composition and namespacing
-The reason `FastMCPApp` exists β€” and why you'd pick it over plain `@mcp.tool(app=True)` with string-based `CallTool` β€” is composition safety.
+The reason `FastMCPApp` exists β€” and why you'd pick it over a plain `@mcp.tool(app=True)` that calls other tools β€” is composition safety.
When you mount a server under a namespace, tool names get prefixed:
```python
platform = FastMCP("Platform")
-platform.mount("contacts", contacts_server)
+platform.mount(contacts_server, namespace="contacts")
# "save_contact" becomes "contacts_save_contact"
```
-`CallTool("save_contact")` would now be broken. But `CallTool(save_contact)` with a function reference resolves to a globally stable identifier that bypasses the namespace. Your app works the same whether standalone or mounted.
+In a plain `@mcp.tool(app=True)`, `CallTool("save_contact")` would now point at a tool that no longer exists. Inside a `FastMCPApp`, the same call is addressed by the app's identity and rewritten to `contacts_save_contact` on the way out, so the app works the same whether standalone or mounted.
### Mounting
diff --git a/docs/apps/generative.mdx b/docs/apps/generative.mdx
index acb0e3270..21b2c6760 100644
--- a/docs/apps/generative.mdx
+++ b/docs/apps/generative.mdx
@@ -80,15 +80,18 @@ The model writes real Python β€” loops, f-strings, computation, helper functions
Before writing code, the LLM can call `search_prefab_components` to discover what's available:
-```
+```text
search_prefab_components("Chart")
-β†’ 7 components matching 'Chart':
- AreaChart β€” from prefab_ui.components.charts import AreaChart
- BarChart β€” from prefab_ui.components.charts import BarChart
+β†’ 9 components matching 'Chart':
+
+ ## Charts
+ Import: `from prefab_ui.components.charts import <name>`
+ AreaChart β€” Area chart with one or more series.
+ BarChart β€” Bar chart with one or more series.
...
```
-Passing `detail=True` returns full field descriptions and docstrings. The search tool introspects Prefab classes at runtime, so it's always up to date with the installed version.
+Space-separated terms match independently, so `"Card Badge Metric"` returns all three. A query that matches five or fewer components returns full docstrings and arguments; a broader one returns this compact listing. Pass `detail=True` or `detail=False` to override. The search tool introspects Prefab classes at runtime, so it matches the installed version.
## Passing data
@@ -118,7 +121,7 @@ GenerativeUI(
## Requirements
-Generative UI needs `fastmcp[apps]`, which pulls in `prefab-ui`. The server-side Pyodide sandbox (for final validation) requires Deno β€” it installs automatically on first use.
+Generative UI needs `fastmcp[apps]`, which pulls in `prefab-ui`. The server-side Pyodide sandbox (for final validation) requires [Deno](https://deno.land) on your `PATH`; FastMCP does not install it, and `generate_prefab_ui` calls fail until it is present. Pyodide itself downloads on first use.
The streaming renderer loads Pyodide from CDN in the browser. The CSP is configured automatically by the provider β€” no manual setup.
diff --git a/docs/apps/prefab.mdx b/docs/apps/prefab.mdx
index 87a595e17..4bb741bb3 100644
--- a/docs/apps/prefab.mdx
+++ b/docs/apps/prefab.mdx
@@ -65,6 +65,9 @@ When numbers tell a better story as a visual, swap in a chart. The API is the sa
<PrefabDemoFrame demo="bar-chart" height="430px" title="Bar chart demo" />
```python
+from prefab_ui.components.charts import BarChart, ChartSeries
+
+
@mcp.tool(app=True)
def quarterly_revenue(year: int) -> BarChart:
"""Show quarterly revenue as a bar chart."""
@@ -91,6 +94,9 @@ Each `ChartSeries` plots a different key from the data. `BarChart`, `LineChart`,
<PrefabDemoFrame demo="pie-chart" height="410px" title="Pie chart demo" />
```python
+from prefab_ui.components.charts import PieChart
+
+
@mcp.tool(app=True)
def ticket_breakdown() -> PieChart:
"""Show open tickets by category."""
@@ -119,6 +125,13 @@ Tables and charts are useful on their own, but the real power comes from composi
<PrefabDemoFrame demo="dashboard" height="680px" title="Sales dashboard demo" />
```python expandable
+from prefab_ui.app import PrefabApp
+from prefab_ui.components import (
+ Badge, Column, DataTable, DataTableColumn, Metric, Row, Separator,
+)
+from prefab_ui.components.charts import BarChart, ChartSeries
+
+
@mcp.tool(app=True)
def sales_dashboard() -> PrefabApp:
"""Show sales KPIs, trends, and deals."""
@@ -189,8 +202,15 @@ Everything above renders once from the data your Python provides. But interactiv
Try switching regions in the dropdown, and toggling the switch on and off.
```python expandable
+from prefab_ui.app import PrefabApp
+from prefab_ui.components import (
+ Column, Metric, Row, Select, SelectOption, Switch, Text,
+)
+from prefab_ui.components.charts import BarChart, ChartSeries
+from prefab_ui.components.control_flow import If
from prefab_ui.rx import Rx
+
@mcp.tool(app=True)
def regional_sales() -> PrefabApp:
"""Sales by region with a live filter."""
@@ -251,8 +271,10 @@ The `state` dict on `PrefabApp` declares initial values. The `Select` writes to
Interactive tools render in a sandboxed iframe with a strict CSP. If your tool loads external resources β€” embedding iframes, fetching from APIs, loading scripts β€” add the required domains:
```python
+from prefab_ui.app import PrefabApp
from fastmcp.apps import PrefabAppConfig, ResourceCSP
+
@mcp.tool(app=PrefabAppConfig(
csp=ResourceCSP(frame_domains=["https://example.com"]),
))
@@ -267,8 +289,11 @@ def dashboard_with_embed() -> PrefabApp:
By default, the LLM sees `"[Rendered Prefab UI]"` as the tool result. If the model needs to reason about the data, return a `ToolResult` with a text summary alongside the UI:
```python
+from prefab_ui.components import Column
+from prefab_ui.components.charts import BarChart, ChartSeries
from fastmcp.tools import ToolResult
+
@mcp.tool(app=True)
def sales_overview(year: int) -> ToolResult:
"""Show sales visually, summarize for the model."""
diff --git a/docs/apps/providers/approval.mdx b/docs/apps/providers/approval.mdx
index 8f848d07c..5d1f5fa39 100644
--- a/docs/apps/providers/approval.mdx
+++ b/docs/apps/providers/approval.mdx
@@ -43,9 +43,11 @@ Approval is an advisory gate, not an enforcement mechanism. The conversation isn
## Configuration
-The constructor sets defaults; the LLM can override all of these per-call via tool arguments.
+The constructor sets defaults; the LLM can override every option except `name` per call via tool arguments.
```python
+from fastmcp.apps.approval import Approval
+
Approval(
name="Approval", # App name
title="Approval Required", # Card heading
@@ -56,17 +58,17 @@ Approval(
)
```
-The LLM can customize each invocation:
-
-```python
-request_approval(
- summary="Delete 47 files from /tmp",
- details="This cannot be undone.",
- title="Destructive Action",
- approve_text="Delete",
- approve_variant="destructive",
- reject_text="Keep files",
-)
+The LLM can customize each invocation through the arguments it passes to `request_approval`:
+
+```json
+{
+ "summary": "Delete 47 files from /tmp",
+ "details": "This cannot be undone.",
+ "title": "Destructive Action",
+ "approve_text": "Delete",
+ "approve_variant": "destructive",
+ "reject_text": "Keep files"
+}
```
## How it works
diff --git a/docs/apps/providers/choice.mdx b/docs/apps/providers/choice.mdx
index 692ae921d..5823a957a 100644
--- a/docs/apps/providers/choice.mdx
+++ b/docs/apps/providers/choice.mdx
@@ -44,6 +44,8 @@ This is an advisory interaction, not an enforcement mechanism. The conversation
The constructor sets defaults; the LLM can override `title` per-call.
```python
+from fastmcp.apps.choice import Choice
+
Choice(
name="Choice", # App name
title="Choose an Option", # Default card heading
@@ -51,14 +53,14 @@ Choice(
)
```
-The LLM provides the options per-call:
+The LLM provides the options per call in the arguments it passes to `choose`:
-```python
-choose(
- prompt="What should we have for lunch?",
- options=["Pizza", "Tacos", "Ramen", "Salad"],
- title="The Important Questions",
-)
+```json
+{
+ "prompt": "What should we have for lunch?",
+ "options": ["Pizza", "Tacos", "Ramen", "Salad"],
+ "title": "The Important Questions"
+}
```
## How it works
diff --git a/docs/apps/providers/file-upload.mdx b/docs/apps/providers/file-upload.mdx
index dcd0cb7aa..366496310 100644
--- a/docs/apps/providers/file-upload.mdx
+++ b/docs/apps/providers/file-upload.mdx
@@ -76,10 +76,10 @@ On a handshake-era connection (`mode="legacy"`, or a client that predates MCP 20
MCP 2026-07-28 connections, which FastMCP clients negotiate by default, have no session. Files are scoped to the authenticated user instead, the same identity [`UserSession`](/servers/sessions) uses. Without authentication, stdio servers keep one store for the process, because a stdio server serves a single client. An unauthenticated HTTP request carries nothing that identifies its client between requests, so the default storage rejects it with an error rather than sharing files across clients. Add [authentication](/servers/auth/authentication) to the server, or override `_get_scope_key`.
<Warning>
-In **stateless HTTP** mode, each request creates a new session object with a new ID. Files stored during one request (e.g. the UI upload) will be invisible to the next request (e.g. the LLM calling `list_files`). You **must** override `_get_scope_key` to use a stable identifier like a user ID from your auth token.
+On handshake-era connections to a **stateless HTTP** server, each request creates a new session with a new ID. Files stored during one request (e.g. the UI upload) are invisible to the next request (e.g. the LLM calling `list_files`). For these clients you **must** override `_get_scope_key` to use a stable identifier, such as a user ID from your auth token.
</Warning>
-For stateless deployments, override `_get_scope_key` to return a stable identifier. To scope files by authenticated user, read the caller from `get_access_token()`.
+To scope files by a stable identifier of your own, override `_get_scope_key`. To scope files by authenticated user, read the caller from `get_access_token()`.
Reject the request when there is no subject to key on. `get_access_token()` returns `None` on an unauthenticated request, and `subject` is optional even on a valid token, since not every verifier populates it. Returning a fallback in either case would put every such caller in one shared bucket, so they would see each other's uploads.
@@ -100,6 +100,8 @@ If your provider carries the user identity in a different claim, read it from `t
For process-wide shared storage (all users see all files):
```python
+from fastmcp.apps.file_upload import FileUpload
+
class SharedUpload(FileUpload):
def _get_scope_key(self, ctx):
return "__shared__"
@@ -112,9 +114,13 @@ The default implementation stores files in memory for the lifetime of the server
```python
import base64
+import boto3
+
from fastmcp.apps.file_upload import FileUpload
from fastmcp.server.dependencies import get_access_token
+s3 = boto3.client("s3")
+
class S3Upload(FileUpload):
def _get_scope_key(self, ctx):
token = get_access_token()
diff --git a/docs/apps/providers/form.mdx b/docs/apps/providers/form.mdx
index 1a28b9963..f457bb7b6 100644
--- a/docs/apps/providers/form.mdx
+++ b/docs/apps/providers/form.mdx
@@ -41,7 +41,7 @@ This registers two tools:
| `collect_bugreport` | Model | Opens the form UI |
| `submit_form` | App only | Validates and processes the submission |
-The tool name is derived from the model class name, lowercased: `collect_{modelname}`. So `BugReport` becomes `collect_bugreport`, `ShippingAddress` becomes `collect_shippingaddress`. Use `tool_name` to override if needed. The LLM calls it with a prompt explaining what it needs, and the user gets a form with fields matching the model.
+The tool name is derived from the model class name, lowercased: `collect_{modelname}`. So `BugReport` becomes `collect_bugreport`, `ShippingAddress` becomes `collect_shippingaddress`. Use `tool_name` to override if needed. The LLM calls it with a prompt explaining what it needs, and the user gets a form with fields matching the model. The LLM can also pass `title` and `submit_text` to override the card heading and button label, and `default`, a partial dict of field values that pre-fills the form for the user to confirm or edit. `default` requires `prefab-ui>=0.19.1` and is ignored on older versions.
## Field mapping
@@ -63,14 +63,25 @@ Use `Field()` metadata to control labels (`title`), placeholders (`description`)
By default, the validated model is returned as JSON. Provide an `on_submit` callback to process the data server-side:
```python
+from pydantic import BaseModel
+from fastmcp import FastMCP
+from fastmcp.apps.form import FormInput
+
+class BugReport(BaseModel):
+ title: str
+ description: str
+
+reports: list[BugReport] = []
+
def save_report(report: BugReport) -> str:
- db.insert(report.model_dump())
- return f"Bug #{db.last_id} filed: {report.title}"
+ reports.append(report)
+ return f"Bug #{len(reports)} filed: {report.title}"
+mcp = FastMCP("My Server")
mcp.add_provider(FormInput(model=BugReport, on_submit=save_report))
```
-The callback receives a validated model instance and returns a string that becomes the tool result.
+The callback receives a validated model instance and returns a string that becomes the result of the `submit_form` call.
## Configuration
@@ -86,13 +97,29 @@ FormInput(
)
```
-Set `send_message=True` to push the result back into the conversation via `SendMessage`, triggering the LLM's next turn. Without it, the result is just the tool return value.
+Set `send_message=True` to push the result back into the conversation via `SendMessage`, triggering the LLM's next turn. Without it, the result goes only to the form UI, which shows "Submitted.", and the LLM does not see the submission.
## Multiple forms
Add multiple providers for different models β€” each gets its own tool:
```python
+from pydantic import BaseModel
+from fastmcp import FastMCP
+from fastmcp.apps.form import FormInput
+
+class ShippingAddress(BaseModel):
+ street: str
+ city: str
+
+class BugReport(BaseModel):
+ title: str
+ description: str
+
+class ContactInfo(BaseModel):
+ name: str
+ email: str
+
mcp = FastMCP(
"My Server",
providers=[