Skip to content

Add GenerativeUI provider, bump prefab-ui 0.14.0#3647

Merged
jlowin merged 7 commits intomainfrom
generative-ui-provider
Mar 27, 2026
Merged

Add GenerativeUI provider, bump prefab-ui 0.14.0#3647
jlowin merged 7 commits intomainfrom
generative-ui-provider

Conversation

@jlowin
Copy link
Copy Markdown
Member

@jlowin jlowin commented Mar 27, 2026

The LLM writes Prefab Python code, the sandbox executes it, the user watches the UI stream in. GenerativeUI is a Provider that wraps prefab_ui.generative — all business logic (component introspection, sandbox execution, tool descriptions) lives in Prefab and is versioned with the component library.

from fastmcp import FastMCP
from fastmcp.apps.generative import GenerativeUI

mcp = FastMCP("Prefab Studio")
mcp.add_provider(GenerativeUI())

Two tools registered automatically: generate_prefab_ui (accepts code, runs sandbox, returns PrefabApp) and search_prefab_components (introspects the real Prefab component classes at runtime). The generative renderer resource and CSP (including connect_domains for Pyodide WASM fetch) are wired up automatically.

Also bumps prefab-ui to ≥0.14.0 which removes set_initial_state in favor of PrefabApp(state={...}). All examples and docs migrated.

jlowin added 4 commits March 24, 2026 21:57
GenerativeUI is a Provider that adds generative UI capabilities:
- generate_ui tool: accepts Prefab Python code, runs in Pyodide sandbox
- components tool: searchable component library via introspection
- Generative renderer resource with CSP for Pyodide CDN

Usage:
    mcp = FastMCP("Server")
    mcp.add_provider(GenerativeUI())
GenerativeUI is a Provider that wraps prefab_ui.generative as MCP tools:
- generate_prefab_ui: LLM writes Prefab Python, sandbox executes, UI renders
- search_prefab_components: introspects Prefab component library
- Generative renderer resource with CSP for Pyodide

Bumps prefab-ui to 0.14.0 which removes set_initial_state — all examples
and docs migrated to PrefabApp(state={...}) + Rx("key"). Wire format now
uses $prefab envelope and pf-app-root wrapper.
@marvin-context-protocol marvin-context-protocol Bot added feature Major new functionality. Reserved for 2-4 significant PRs per release. Not for issues. breaking change Breaks backward compatibility. Requires minor version bump. Critical for maintainer attention. provider Related to the FastMCP Provider class labels Mar 27, 2026
@jlowin jlowin removed the breaking change Breaks backward compatibility. Requires minor version bump. Critical for maintainer attention. label Mar 27, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d46b41324b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/fastmcp/apps/generative.py Outdated
Comment on lines +101 to +103
if self._setup_done:
return
self._setup_done = True
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Defer setup-complete flag until registration succeeds

Setting _setup_done = True before component registration means any setup-time exception leaves this provider permanently half-initialized. For example, if a caller configures tool_name and components_tool_name to the same value, _add_component raises once, but subsequent list/get calls skip setup and operate on incomplete state (often missing the renderer resource). Mark setup complete only after all registrations succeed (or reset the flag on failure) so retries are safe and deterministic.

Useful? React with 👍 / 👎.

@jlowin jlowin merged commit ce7758e into main Mar 27, 2026
10 checks passed
@jlowin jlowin deleted the generative-ui-provider branch March 27, 2026 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Major new functionality. Reserved for 2-4 significant PRs per release. Not for issues. provider Related to the FastMCP Provider class

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant