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 is the fallback AttributeError from fastmcp.dependencies.__getattr__: any attribute access on the module that is neither an exported name nor one of the names moved to fastmcp-tasks raises 'module fastmcp.dependencies has no attribute <name>'.

Source

Thrown at fastmcp_slim/fastmcp/dependencies.py:55

    "Progress",
    "ProgressLike",
    "Shared",
    "TokenClaim",
]

# Docket-specific dependencies moved to the fastmcp-tasks package. Point users
# there instead of raising a bare AttributeError.
_MOVED_TO_TASKS = {"CurrentDocket", "CurrentWorker"}


def __getattr__(name: str) -> Any:
    if name in _MOVED_TO_TASKS:
        raise ImportError(
            f"{name!r} moved to the fastmcp-tasks package. Install it with "
            f"`pip install 'fastmcp[tasks]'` and import from "
            f"`fastmcp_tasks.dependencies`."
        )
    raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

View on GitHub (pinned to 1f02114297)

Solutions

  1. Check the exact exported name via `dir(fastmcp.dependencies)` or the docs and fix the spelling
  2. If the name is CurrentDocket/CurrentWorker, install 'fastmcp[tasks]' and import from fastmcp_tasks.dependencies (you'd get the ImportError variant instead)
  3. Search the fastmcp source for the symbol to find its current module

Example fix

// before
from fastmcp.dependencies import api_key

// after
from fastmcp.dependencies import ApiKey
Defensive patterns

Strategy: validation

Validate before calling

import fastmcp.dependencies
name = "ApiKey"
if not hasattr(fastmcp.dependencies, name):
    print(f"{name} not in fastmcp.dependencies; check dir():", [n for n in dir(fastmcp.dependencies) if not n.startswith('_')])

Type guard

def dependency_exists(name: str) -> bool:
    import fastmcp.dependencies
    return hasattr(fastmcp.dependencies, name)

Try / catch

try:
    from fastmcp.dependencies import ApiKey
except (ImportError, AttributeError) as e:
    raise ImportError(f"Check the exact dependency name in fastmcp docs: {e}") from e

Prevention

When it happens

Trigger: `from fastmcp.dependencies import <Name>` or `fastmcp.dependencies.<Name>` where <Name> doesn't exist — misspelled dependency names (e.g. ApiKey vs APIKey), names that never existed, or names moved somewhere else entirely.

Common situations: Typos in dependency imports; guessing at names not in the module's exports; IDE auto-import picking the wrong module; older docs referencing renamed dependencies.

Related errors


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