Skip to content

fix: remove CSP from tool metadata, keep on resource only#3754

Merged
jlowin merged 2 commits intomainfrom
fix/tool-meta-csp-cleanup
Apr 3, 2026
Merged

fix: remove CSP from tool metadata, keep on resource only#3754
jlowin merged 2 commits intomainfrom
fix/tool-meta-csp-cleanup

Conversation

@jlowin
Copy link
Copy Markdown
Member

@jlowin jlowin commented Apr 3, 2026

The MCP Apps spec defines McpUiToolMeta as {resourceUri, visibility} only — CSP belongs on UIResourceMeta, not the tool. We were putting CSP on both the tool and the renderer resource; the resource was already correct, so this just strips the redundant CSP from the tool's _meta.ui.

Two call sites: _expand_prefab_ui_meta (auto-wired prefab tools) and FastMCPApp.ui() (explicit app tools). Both now build AppConfig with only resource_uri/visibility, matching the spec's tool interface.

Note this is technically a breaking change though unused and undocumented.

Closes #3735

Per the MCP Apps spec, McpUiToolMeta only defines resourceUri and
visibility. CSP belongs on the UIResourceMeta (the renderer resource),
where we already set it correctly via _ensure_prefab_renderer.

Closes #3735
@jlowin jlowin added the bug Something isn't working. Reports of errors, unexpected behavior, or broken functionality. label Apr 3, 2026
@marvin-context-protocol marvin-context-protocol Bot added the mcp apps Related to MCP Apps - user-facing applications with frontend bundles served by MCP servers. label Apr 3, 2026
@jlowin jlowin added breaking change Breaks backward compatibility. Requires minor version bump. Critical for maintainer attention. and removed mcp apps Related to MCP Apps - user-facing applications with frontend bundles served by MCP servers. labels Apr 3, 2026
@jlowin jlowin merged commit 333aadd into main Apr 3, 2026
8 checks passed
@jlowin jlowin deleted the fix/tool-meta-csp-cleanup branch April 3, 2026 14:22
@Mars9934
Copy link
Copy Markdown

Mars9934 commented Apr 9, 2026

Hi @jlowin , not sure if this change is working quite right. In MCP Inspector, I still see the csp being set for the Tool:
image

And more importantly, still not seeing the customized frameDomains for the Resource:
image
I think it's cause _ensure_prefab_renderer isn't getting tool.meta so it only has default CSP from get_renderer_csp.

For reference, my tool declaration is:

@mcp.tool(app=PrefabAppConfig(csp=ResourceCSP(frame_domains=["https://example1234.com"])))

jlowin added a commit that referenced this pull request Apr 10, 2026
Replaces the singleton ui://prefab/renderer.html with per-tool
renderer resources synthesized on demand from the address registry.
Each prefab tool gets a unique URI ui://prefab/tool/<hash>/renderer.html
where the hash is deterministic from the tool's mount-point address.

Nothing is materialized or stored: list_resources walks the registry
and returns synthesized TextResource entries; read_resource intercepts
matching URIs and produces fresh content + CSP from the tool's stored
meta; list_tools rewrites tool meta via model_copy so the wire format
exposes the per-tool URI without ever mutating the original Tool object.

Closes the bug from PR #3754: PrefabAppConfig(csp=...) now actually
applies to the rendered resource, all four *_domains fields are
preserved (the old singleton silently dropped frame_domains and
base_uri_domains), and CSP is stripped from the tool wire format
where it never belonged.

Closes #3735.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change Breaks backward compatibility. Requires minor version bump. Critical for maintainer attention. bug Something isn't working. Reports of errors, unexpected behavior, or broken functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CSP should be set for an App's resource instead of tool

2 participants