PrefectHQ/fastmcp · error · TypeError

Cannot specify both a name as first argument and as keyword

Error message

Cannot specify both a name as first argument and as keyword argument. Use either @prompt('{name_or_fn}') or @prompt(name='{name}'), not both.

What it means

`@prompt` accepts the name either positionally or via the `name=` keyword, not both. Supplying both — e.g. `prompt('x', name='y')` — raises this TypeError to prevent ambiguous naming.

Source

Thrown at fastmcp_slim/fastmcp/server/providers/local_provider/decorators/prompts.py:207

                title=title,
                description=description,
                icons=icons,
                tags=tags,
                meta=meta,
                auth=auth,
                enabled=enabled,
            )
            target = fn.__func__ if hasattr(fn, "__func__") else fn
            target.__fastmcp__ = metadata  # type: ignore[attr-defined]  # ty:ignore[unresolved-attribute]
            self.add_prompt(fn)
            return fn

        if inspect.isroutine(name_or_fn):
            return decorate_and_register(name_or_fn, name)

        elif isinstance(name_or_fn, str):
            if name is not None:
                raise TypeError(
                    f"Cannot specify both a name as first argument and as keyword argument. "
                    f"Use either @prompt('{name_or_fn}') or @prompt(name='{name}'), not both."
                )
            prompt_name = name_or_fn
        elif name_or_fn is None:
            prompt_name = name
        else:
            raise TypeError(f"Invalid first argument: {type(name_or_fn)}")

        return partial(
            self.prompt,
            name=prompt_name,
            version=version,
            title=title,
            description=description,
            icons=icons,
            tags=tags,
            meta=meta,

View on GitHub (pinned to 1f02114297)

Solutions

  1. Remove one of the two names — keep `@prompt('custom_name')` or `@prompt(name='custom_name')`, not both
  2. If building a wrapper, forward only `**kwargs` and let the caller supply `name` once

Example fix

// before
@provider.prompt('greet', name='greeting')
async def p(): ...
// after
@provider.prompt(name='greeting')
async def p(): ...
Defensive patterns

Strategy: validation

Validate before calling

if name is not None and isinstance(name_or_fn, str):
    raise TypeError('pass the name once: positional or name=, not both')

Try / catch

try:
    deco = provider.prompt('greet', name='greeting')
except TypeError as e:
    if 'both' in str(e): deco = provider.prompt(name='greeting')

Prevention

When it happens

Trigger: Calling `provider.prompt('custom', name='other')` or stacking wrappers that pass the name positionally while also forwarding `name=` through `partial`/functools.

Common situations: Wrapping the decorator in a helper that already sets `name=` while callers also pass a positional name; refactoring from positional to keyword style and leaving both in place.

Related errors


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