PrefectHQ/fastmcp · error · AttributeError
module {__name__!r} has no attribute {name!r}
Error message
module {__name__!r} has no attribute {name!r} What it means
This AttributeError is raised by the lazy module-level __getattr__ of fastmcp.apps when code accesses an attribute on the `fastmcp.apps` module that it does not know how to lazily import. The only lazily provided attribute is `FastMCPApp`; anything else falls through to this raise. It typically means a misspelled import or an attribute that lives in a submodule (e.g. fastmcp.apps.app) was referenced at module level.
Source
Thrown at fastmcp_slim/fastmcp/apps/__init__.py:42
"AppConfig",
"FastMCPApp",
"PrefabAppConfig",
"ResourceCSP",
"ResourcePermissions",
"app_config_to_meta_dict",
"resolve_ui_mime_type",
]
if _TYPE_CHECKING:
from fastmcp.apps.app import FastMCPApp as FastMCPApp
def __getattr__(name: str) -> object:
if name == "FastMCPApp":
from fastmcp.apps.app import FastMCPApp
return FastMCPApp
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
View on GitHub (pinned to 1f02114297)
Solutions
- Use the exact exported name `FastMCPApp` (from fastmcp.apps import FastMCPApp) or import from the defining submodule, e.g. `from fastmcp.apps.app import ...`.
- Check `dir(fastmcp.apps)` to see which attributes actually exist at module level.
- Verify the installed fastmcp version supports the attribute (upgrade if it was added later).
Example fix
// before from fastmcp.apps import AppFastMCP // after from fastmcp.apps import FastMCPApp
Defensive patterns
Strategy: type-guard
Validate before calling
import fastmcp.apps
attr = "FastMCPApp"
if not hasattr(fastmcp.apps, attr):
raise ImportError(f"fastmcp.apps has no attribute {attr!r}; use FastMCPApp or import from fastmcp.apps.app") Type guard
def has_apps_attr(name: str) -> bool:
import fastmcp.apps
return hasattr(fastmcp.apps, name) Try / catch
try:
from fastmcp.apps import FastMCPApp
except AttributeError as e:
from fastmcp.apps.app import FastMCPApp # or fix the name Prevention
- Import FastMCPApp by its exact name or from fastmcp.apps.app
- Run a quick `python -c 'from fastmcp.apps import FastMCPApp'` smoke check in CI
- Use IDE auto-import from the defining submodule, not the package root
- Pin and review the fastmcp version when upgrading import paths
When it happens
Trigger: Accessing `fastmcp.apps.<anything-other-than-FastMCPApp>` that is not an explicitly imported name, e.g. `from fastmcp.apps import FastMCPApp misspelled as FastmcpApp/AppFastMCP`, or `import fastmcp.apps; fastmcp.apps.some_helper`.
Common situations: Typos in imports after upgrading versions; assuming all public symbols are re-exported from the package __init__; IDE auto-import picking the package instead of the correct submodule; code written against an older/newer layout of the apps feature.
Related errors
- module {__name__!r} has no attribute {name!r}
- Setting {parent_attr} does not exist.
- Cannot resolve tool reference: {fn!r}
- Cannot specify both a name as first argument and as keyword
- First argument to @{decorator_name} must be a function, stri
AI-assisted analysis of PrefectHQ/fastmcp@1f02114297 (2026-08-29).
Data as JSON: /api/errors/2bd492f4e24147bd.
Report an issue: GitHub.