Skip to content

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

Keep GenerativeUI CSP on the renderer resource only (#5612)

Asem ahmed34ab786037fa
diff --git a/fastmcp_slim/fastmcp/apps/generative.py b/fastmcp_slim/fastmcp/apps/generative.py
index 0ad78f12d..b1e0c7693 100644
--- a/fastmcp_slim/fastmcp/apps/generative.py
+++ b/fastmcp_slim/fastmcp/apps/generative.py
@@ -101,8 +101,9 @@ class GenerativeUI(Provider):
if self._setup_done:
return
+ # CSP belongs on the renderer resource, not the tool (MCP Apps spec).
csp = _build_csp()
- app_config = AppConfig(resource_uri=_gen.RESOURCE_URI, csp=csp)
+ app_config = AppConfig(resource_uri=_gen.RESOURCE_URI)
# -- generate_ui tool --
# Wraps prefab_ui.generative.execute with sandbox lifecycle management.
diff --git a/tests/apps/test_generative.py b/tests/apps/test_generative.py
new file mode 100644
index 000000000..80035fc54
--- /dev/null
+++ b/tests/apps/test_generative.py
@@ -0,0 +1,28 @@
+"""GenerativeUI provider metadata."""
+
+import pytest
+
+from fastmcp import Client, FastMCP
+
+pytest.importorskip("prefab_ui.generative")
+from fastmcp.apps.generative import GenerativeUI # noqa: E402
+
+
+async def test_csp_is_on_renderer_resource_not_tool():
+ """CSP belongs on the ui:// resource; tool meta carries only resourceUri."""
+ mcp = FastMCP("test", providers=[GenerativeUI()])
+
+ async with Client(mcp) as client:
+ tools = await client.list_tools()
+ resources = await client.list_resources()
+
+ tool = next(t for t in tools if t.name == "generate_prefab_ui")
+ assert tool.meta is not None
+ assert set(tool.meta["ui"]) == {"resourceUri"}
+
+ renderer = next(
+ r for r in resources if str(r.uri) == tool.meta["ui"]["resourceUri"]
+ )
+ assert renderer.meta is not None
+ assert renderer.meta["ui"]["csp"]["resourceDomains"]
+ assert renderer.meta["ui"]["csp"]["connectDomains"]