PrefectHQ/fastmcp · error · TypeError
Cannot specify name both as first argument and keyword
Error message
Cannot specify name both as first argument and keyword
What it means
The @prompt decorator accepts the prompt name either as the first positional argument (@prompt('my_name')) or as the name keyword (@prompt(name='my_name')), but not both. Supplying a string as name_or_fn while name is also non-None is ambiguous, so prompt() raises TypeError immediately.
Source
Thrown at fastmcp_slim/fastmcp/prompts/function_prompt.py:440
title=title,
description=description,
icons=icons,
tags=tags,
meta=meta,
auth=auth,
)
target = fn.__func__ if isinstance(fn, staticmethod | MethodType) else fn
cast(Any, target).__fastmcp__ = metadata
return fn
def decorator(fn: F, prompt_name: str | None) -> F:
return attach_metadata(fn, prompt_name)
if inspect.isroutine(name_or_fn):
return decorator(name_or_fn, name)
elif isinstance(name_or_fn, str):
if name is not None:
raise TypeError("Cannot specify name both as first argument and keyword")
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)}")
def wrapper(fn: F) -> F:
return decorator(fn, prompt_name)
return wrapper
View on GitHub (pinned to 1f02114297)
Solutions
- Remove the name keyword and keep only the positional string: @prompt('my_prompt')
- Or remove the positional string and use only the keyword: @prompt(name='my_prompt')
- If you meant to decorate a function directly, pass the function (a routine, not a string) first with an optional name keyword
Example fix
// before
@prompt('weather_prompt', name='weather')
def weather(): ...
// after
@prompt('weather')
def weather(): ... Defensive patterns
Strategy: validation
Validate before calling
def safe_prompt(first=None, name=None):
if isinstance(first, str) and name is not None:
raise TypeError('specify name positionally or as keyword, not both')
return prompt(first, name=name) Try / catch
try:
p = prompt('name_a', name='name_b')
except TypeError as e:
logger.error('decorator misused: %s', e)
p = prompt(name='name_b') # pick one canonical form Prevention
- Pick one style per codebase (positional string or name= keyword) and enforce it in review
- Never pass both a positional string and name= keyword
- Watch for IDE autocompletes that append name= to an existing positional name
When it happens
Trigger: Calling @prompt('my_prompt', name='other_name') or @prompt('my_prompt', name='other_name')(fn) — a string first argument plus a non-None name keyword.
Common situations: Merging two call styles during a refactor; IDE autocomplete adding name= alongside an existing positional name; copy-paste where one call form was partially converted to the other.
Related errors
- Invalid first argument: {type(name_or_fn)}
- To decorate a classmethod, use @classmethod above @prompt. S
- Missing required arguments: {missing}
- Got unexpected keyword argument(s): {', '.join(sorted(unknow
- Cannot specify both a name as first argument and as keyword
AI-assisted analysis of PrefectHQ/fastmcp@1f02114297 (2026-08-29).
Data as JSON: /api/errors/0483bfb80195266a.
Report an issue: GitHub.