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
- Remove one of the two names — keep `@prompt('custom_name')` or `@prompt(name='custom_name')`, not both
- 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
- Pick one naming style per codebase (prefer name= keyword) and stick to it
- When writing wrappers around @prompt, forward **kwargs instead of duplicating name
- Review decorator refactors for leftover duplicate arguments
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
- To decorate a classmethod, use @classmethod above @prompt. S
- The function '{fn_name}' has '{params[0]}' as its first para
- Invalid first argument: {type(name_or_fn)}
- messages[{i}] must be Message, got {type(item).__name__}. Us
- messages must be str or list[Message], got {type(messages)._
AI-assisted analysis of PrefectHQ/fastmcp@1f02114297 (2026-08-29).
Data as JSON: /api/errors/237b3b8ccb5356fc.
Report an issue: GitHub.