PrefectHQ/fastmcp · error · ImportError

Approval requires prefab-ui. Install with: pip install 'fast

Error message

Approval requires prefab-ui. Install with: pip install 'fastmcp[apps]'

What it means

Importing fastmcp.apps.approval requires the optional prefab-ui dependency, which provides the UI component primitives (Row, Text, If, STATE, etc.). If prefab_ui cannot be imported, the module re-raises the ImportError with this install hint, chained to the original exception.

Source

Thrown at fastmcp_slim/fastmcp/apps/approval.py:41

    from prefab_ui.actions import SetState
    from prefab_ui.actions.mcp import SendMessage
    from prefab_ui.app import PrefabApp
    from prefab_ui.components import (
        H3,
        Button,
        Card,
        CardContent,
        CardFooter,
        CardHeader,
        Column,
        Muted,
        Row,
        Text,
    )
    from prefab_ui.components.control_flow import If
    from prefab_ui.rx import STATE
except ImportError as _exc:
    raise ImportError(
        "Approval requires prefab-ui. Install with: pip install 'fastmcp[apps]'"
    ) from _exc


from fastmcp.apps.app import FastMCPApp


class Approval(FastMCPApp):
    """A Provider that adds human-in-the-loop approval to a server.

    The LLM calls the ``request_approval`` tool with a summary and
    optional details. The user sees an approval card with Approve and
    Reject buttons. Clicking either sends a message back into the
    conversation (via ``SendMessage``), triggering the LLM's next turn.

    The message appears as if the user sent it, so the LLM sees
    something like ``'"Deploy v3.2 to production" is APPROVED'``.

View on GitHub (pinned to 1f02114297)

Solutions

  1. Install the extra: `pip install 'fastmcp[apps]'` (or `uv add 'fastmcp[apps]'`).
  2. Verify with `python -c "import prefab_ui"` that the package is importable.
  3. If prefab-ui is intentionally omitted, remove imports of fastmcp.apps.approval from your code path.

Example fix

// before
pip install fastmcp
// after
pip install 'fastmcp[apps]'
Defensive patterns

Strategy: fallback

Validate before calling

def prefab_available() -> bool:
    import importlib.util
    return importlib.util.find_spec("prefab_ui") is not None

Try / catch

try:
    from fastmcp.apps.approval import Approval
except ImportError:
    Approval = None
    logger.warning("prefab-ui missing; approval UI disabled. Install 'fastmcp[apps]'")

Prevention

When it happens

Trigger: `import fastmcp.apps.approval` or `from fastmcp.apps.approval import Approval` in an environment where the `prefab-ui` package is not installed.

Common situations: Installing fastmcp without the [apps] extra; deploying to a fresh container/venv that omitted the extra; a broken or incompatible prefab-ui install.

Understand the failure class

Background: "X is not installed. Please install it with pip install Y": missing optional dependency errors — ImportError/ValueError raised when a library's optional extra was never installed — this error's family across 22 libraries.

Related errors


AI-assisted analysis of PrefectHQ/fastmcp@1f02114297 (2026-08-29). Data as JSON: /api/errors/62a72bdf5aecfc0e. Report an issue: GitHub.