{"record":{"id":"4e8f0051506f2e71","repo":"PrefectHQ/fastmcp","slug":"expected-a-prefab-ui-component","errorCode":null,"errorMessage":"Expected a Prefab UI component","messagePattern":"Expected a Prefab UI component","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"fastmcp_slim/fastmcp/utilities/prefab.py","lineNumber":73,"sourceCode":"\n    prefab_types = _get_prefab_types()\n    return prefab_types is not None and isinstance(value, prefab_types[0])\n\n\ndef is_prefab_component(value: Any) -> bool:\n    \"\"\"Return whether a value is a Prefab component.\"\"\"\n    if not _could_be_prefab(value):\n        return False\n\n    prefab_types = _get_prefab_types()\n    return prefab_types is not None and isinstance(value, prefab_types[1])\n\n\ndef prefab_app_from_component(component: Any) -> Any:\n    \"\"\"Wrap a Prefab component in a Prefab app.\"\"\"\n    prefab_types = _get_prefab_types()\n    if prefab_types is None or not isinstance(component, prefab_types[1]):\n        raise TypeError(\"Expected a Prefab UI component\")\n    return prefab_types[0](view=component)\n","sourceCodeStart":55,"sourceCodeEnd":75,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/utilities/prefab.py#L55-L75","documentation":"`prefab_app_from_component` wraps a Prefab UI view component into a Prefab app, and raises this TypeError when the object passed is not an instance of the Prefab component type (or when the Prefab package isn't installed at all, in which case the type lookup returns None). It's a type guard protecting an API that only accepts genuine Prefab UI components.","triggerScenarios":"Calling the prefab app path (`__init__` or `convert_result`) with a return value that is not a Prefab component — e.g. a plain dict, a dataclass, or another framework's view object — or with Prefab support not installed (`fastmcp[ui]` extras missing) so `_get_prefab_types()` is None.","commonSituations":"A tool decorated to return a Prefab UI actually returns a fallback/plain value on some code path; the Prefab dependency wasn't installed; a refactoring replaced the component with a wrapper object; passing a Prefab *app* instead of a *component* (double wrapping attempt).","solutions":["Install the Prefab UI extra so the component types are importable (check `_get_prefab_types` requirements / package extras).","Return the actual Prefab component instance from your tool — not a dict, wrapper, or an already-wrapped app.","Verify the code path: if the tool can return non-UI values, branch so only Prefab components reach `convert_result`."],"exampleFix":"// before\nreturn {\"view\": my_view}  # plain dict\n// after\nreturn my_view  # actual Prefab UI component instance","handlingStrategy":"type-guard","validationCode":"def ensure_prefab_installed() -> bool:\n    from fastmcp.utilities.prefab import _get_prefab_types\n    return _get_prefab_types() is not None","typeGuard":"def is_prefab_component(obj: object) -> bool:\n    from fastmcp.utilities.prefab import _get_prefab_types\n    types = _get_prefab_types()\n    return types is not None and isinstance(obj, types[1])","tryCatchPattern":"try:\n    app = prefab_app_from_component(result)\nexcept TypeError as e:\n    if \"Expected a Prefab UI component\" in str(e):\n        logger.warning(\"Tool returned non-Prefab value %r; skipping UI wrap\", result)\n        app = None\n    else:\n        raise","preventionTips":["Install the UI/prefab extra so component types are available.","Ensure tools meant to return Prefab UIs have no fallback code paths returning plain values.","Don't double-wrap: pass the component, never an already-built app."],"tags":["prefab","ui","type-check"],"backgroundTag":"unexpected-argument-type","analyzedSha":"1f021142978e0861cd910c8df4e8074bc7cf3978","analyzedAt":"2026-08-29T14:31:16.082Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}