{"record":{"id":"b197f6c41bc063fd","repo":"PrefectHQ/fastmcp","slug":"generativeui-requires-prefab-ui-install-with-pip","errorCode":null,"errorMessage":"GenerativeUI requires prefab-ui. Install with: pip install 'fastmcp[apps]'","messagePattern":"GenerativeUI requires prefab-ui\\. Install with: pip install 'fastmcp\\[apps\\]'","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"fastmcp_slim/fastmcp/apps/generative.py","lineNumber":25,"sourceCode":"Requires ``fastmcp[apps]`` (prefab-ui).\n\nUsage::\n\n    from fastmcp import FastMCP\n    from fastmcp.apps.generative import GenerativeUI\n\n    mcp = FastMCP(\"My Server\")\n    mcp.add_provider(GenerativeUI())\n\"\"\"\n\ntry:\n    import prefab_ui.generative as _gen\n    from prefab_ui.renderer import (\n        get_generative_renderer_csp,\n        get_generative_renderer_html,\n    )\nexcept ImportError as _exc:\n    raise ImportError(\n        \"GenerativeUI requires prefab-ui. Install with: pip install 'fastmcp[apps]'\"\n    ) from _exc\n\nimport json\nfrom collections.abc import AsyncIterator, Sequence\nfrom contextlib import asynccontextmanager\nfrom typing import Any\n\nfrom fastmcp.apps.config import AppConfig, ResourceCSP, app_config_to_meta_dict\nfrom fastmcp.server.providers.base import Provider\nfrom fastmcp.server.providers.local_provider import LocalProvider\nfrom fastmcp.tools.base import Tool\nfrom fastmcp.utilities.logging import get_logger\nfrom fastmcp.utilities.mime import UI_MIME_TYPE\n\nlogger = get_logger(__name__)\n\n","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/apps/generative.py#L7-L43","documentation":"GenerativeUI in fastmcp/apps/generative.py imports prefab_ui.generative and the prefab renderer helpers at module import time. If prefab-ui is absent, the ImportError is re-raised with an explicit install hint rather than a confusing bare module error. This keeps generative-UI support opt-in via the 'apps' extra.","triggerScenarios":"Importing fastmcp.apps.generative or constructing a GenerativeUI component in an environment without prefab_ui installed.","commonSituations":"Fresh venv or Docker image with plain fastmcp installed; upgrading fastmcp without reinstalling extras; following docs examples that use GenerativeUI without the apps extra.","solutions":["Install with pip install 'fastmcp[apps]'","If using fastmcp-slim, install the extra that includes prefab-ui","Re-run uv sync / pip install after changing dependency groups"],"exampleFix":"# before\nfrom fastmcp.apps.generative import GenerativeUI  # ImportError\n\n# after\n# pip install 'fastmcp[apps]'\nfrom fastmcp.apps.generative import GenerativeUI","handlingStrategy":"fallback","validationCode":"import importlib.util\nif importlib.util.find_spec('prefab_ui') is None:\n    raise SystemExit(\"Install with: pip install 'fastmcp[apps]'\")","typeGuard":null,"tryCatchPattern":"try:\n    from fastmcp.apps.generative import GenerativeUI\nexcept ImportError as exc:\n    if 'prefab-ui' in str(exc):\n        print(\"Run: pip install 'fastmcp[apps]'\")\n    else:\n        raise","preventionTips":["Pin the [apps] extra in pyproject/requirements","Test imports in a clean venv mirroring production","Keep prefab-ui updated alongside fastmcp"],"tags":["dependency","optional-extra","import-error","prefab-ui"],"backgroundTag":"missing-optional-dependency","analyzedSha":"1f021142978e0861cd910c8df4e8074bc7cf3978","analyzedAt":"2026-08-29T14:31:16.082Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}