PrefectHQ/fastmcp · error · ImportError
FastMCP server support is not installed. Install `fastmcp` o
Error message
FastMCP server support is not installed. Install `fastmcp` or `fastmcp-slim[server]`.
What it means
`fastmcp.server` is a lazy loader: accessing `Context` triggers a deferred import of fastmcp.server.context, which only exists when full server dependencies are installed. In a slim install (fastmcp-slim without the [server] extra) the import fails with ImportError, which is re-raised as ImportError with the message 'FastMCP server support is not installed. Install `fastmcp` or `fastmcp-slim[server]`.'
Source
Thrown at fastmcp_slim/fastmcp/server/__init__.py:19
import importlib
from typing import TYPE_CHECKING
from fastmcp import _install_hints
if TYPE_CHECKING:
from .context import Context as Context
from .server import FastMCP as FastMCP
from .server import create_proxy as create_proxy
def __getattr__(name: str) -> object:
if name in {"context", "dependencies"}:
return importlib.import_module(f"fastmcp.server.{name}")
if name == "Context":
try:
from .context import Context
except ImportError as exc:
raise ImportError(_install_hints.SERVER_SUPPORT) from exc
return Context
if name in {"FastMCP", "create_proxy"}:
try:
from .server import FastMCP, create_proxy
except ImportError as exc:
raise ImportError(_install_hints.SERVER_SUPPORT) from exc
return FastMCP if name == "FastMCP" else create_proxy
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
__all__ = ["Context", "FastMCP", "create_proxy"]
View on GitHub (pinned to 1f02114297)
Solutions
- Install server support: `pip install fastmcp-slim[server]` (or plain `pip install fastmcp`).
- Guard server-only imports so client-only code doesn't touch fastmcp.server attributes.
- Pin the full `fastmcp` package in server-related environments (requirements/pyproject).
- If you maintain the slim package, verify the optional extra name in install hints matches your install command.
Example fix
// before pip install fastmcp-slim from fastmcp.server import Context # ImportError // after pip install "fastmcp-slim[server]" from fastmcp.server import Context
Defensive patterns
Strategy: fallback
Validate before calling
import importlib.util
if importlib.util.find_spec('fastmcp.server.context') is None:
raise ImportError("Install server support: pip install 'fastmcp-slim[server]'") Try / catch
try:
from fastmcp.server import Context
except ImportError as e:
raise SystemExit(f'server deps missing: {e}') Prevention
- Install the [server] extra wherever server code runs.
- Add an import smoke test to CI for both slim and full installs.
- Document which environments need full fastmcp vs fastmcp-slim.
When it happens
Trigger: In a slim installation, execute `from fastmcp.server import Context` or `import fastmcp.server; fastmcp.server.Context` — the __getattr__ path at fastmcp_slim/fastmcp/server/__init__.py:19 converts the inner ImportError into the install-hint error.
Common situations: A project installed fastmcp-slim for client usage but shared code (or a tutorial) imports Context/FastMCP from fastmcp.server; CI uses the slim package while local dev uses full fastmcp; a dependency was slimmed down to shrink installs and server imports broke.
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
- module {__name__!r} has no attribute {name!r}
- module {__name__!r} has no attribute {name!r}
- Approval requires prefab-ui. Install with: pip install 'fast
- Choice requires prefab-ui. Install with: pip install 'fastmc
- FileUpload requires prefab-ui. Install with: pip install 'fa
AI-assisted analysis of PrefectHQ/fastmcp@1f02114297 (2026-08-29).
Data as JSON: /api/errors/7c52005c364a2f58.
Report an issue: GitHub.