Skip to content

Add PrefabAppConfig for customizable Prefab tool setup#3648

Merged
jlowin merged 2 commits intomainfrom
prefab-app-config
Mar 27, 2026
Merged

Add PrefabAppConfig for customizable Prefab tool setup#3648
jlowin merged 2 commits intomainfrom
prefab-app-config

Conversation

@jlowin
Copy link
Copy Markdown
Member

@jlowin jlowin commented Mar 27, 2026

Closes #3623.

The gap: app=True auto-wires everything but isn't customizable. app=AppConfig(...) is fully customizable but doesn't auto-wire the renderer or CSP. If you need one extra CSP domain, you fall off a cliff.

PrefabAppConfig fills the middle: it auto-sets the renderer URI, merges the renderer's CSP with any additional domains you provide, and the renderer resource is auto-registered.

from fastmcp.apps import PrefabAppConfig, ResourceCSP

# Same as app=True
@mcp.tool(app=PrefabAppConfig())

# Add frame_domains for an Embed component
@mcp.tool(app=PrefabAppConfig(
    csp=ResourceCSP(frame_domains=["https://example.com"]),
))

Also fixes the renderer resource not being registered when using AppConfig with the Prefab renderer URI directly — any tool pointing to ui://prefab/renderer.html now triggers auto-registration.

PrefabAppConfig auto-wires the Prefab renderer URI and merges
renderer CSP with user-provided CSP domains. Fills the gap between
app=True (zero config, no customization) and app=AppConfig(...)
(full manual control, no auto-wiring).

Also auto-registers the renderer resource when any tool points to
the Prefab renderer URI, fixing #3623.
@marvin-context-protocol marvin-context-protocol Bot added enhancement Improvement to existing functionality. For issues and smaller PR improvements. provider Related to the FastMCP Provider class labels 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: 08f4d8610c

ℹ️ 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/config.py Outdated
Comment on lines +148 to +152
merged = ResourceCSP(
connect_domains=_merge_domains(
renderer_csp.get("connect_domains"),
user_csp.connect_domains,
),
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 Preserve custom CSP directives when merging renderer defaults

PrefabAppConfig rebuilds ResourceCSP from a fixed subset of fields, which drops any extra directives users pass (for example future-spec keys like workerDomains). ResourceCSP is configured with extra="allow" and existing tests rely on unknown directives round-tripping, so this introduces a regression specifically for PrefabAppConfig users who add non-core CSP keys.

Useful? React with 👍 / 👎.

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: 95bf66fd32

ℹ️ 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 on lines +143 to +146
elif isinstance(ui, dict) and ui.get("resourceUri") == PREFAB_RENDERER_URI:
# PrefabAppConfig or manual config pointing to the Prefab renderer —
# ensure the renderer resource is registered (CSP already set by caller)
_ensure_prefab_renderer(provider)
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 Skip prefab auto-registration when renderer URI is versioned

This new branch now auto-calls _ensure_prefab_renderer for any tool whose ui.resourceUri is ui://prefab/renderer.html, but _ensure_prefab_renderer only checks the unversioned key (resource:ui://prefab/renderer.html@). In setups that already register a versioned renderer resource at the same URI, adding such a tool now raises ValueError from version-mixing (LocalProvider._check_version_mixing), so app=AppConfig(resource_uri="ui://prefab/renderer.html") can fail even though the renderer is already present. This regression is triggered specifically when users version their renderer resource.

Useful? React with 👍 / 👎.

@jlowin jlowin merged commit b7cb7ce into main Mar 27, 2026
9 of 10 checks passed
@jlowin jlowin deleted the prefab-app-config branch March 27, 2026 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Improvement to existing functionality. For issues and smaller PR improvements. provider Related to the FastMCP Provider class

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow specifying CSP when using Prefab App for MCP tool

1 participant