PrefectHQ/fastmcp · error · TypeError
The function '{fn_name}' has '{params[0]}' as its first para
Error message
The function '{fn_name}' has '{params[0]}' as its first parameter. Use the standalone @prompt decorator and register the bound method:
from fastmcp.prompts import prompt
class MyClass:
@prompt
def {fn_name}(...):
...
obj = MyClass()
mcp.add_prompt(obj.{fn_name})
See https://gofastmcp.com/servers/prompts#using-with-methods What it means
When `decorate_and_register` inspects the function and finds its first parameter is `self` or `cls`, it assumes an undecorated instance/class method was passed and raises a TypeError with the correct standalone-decorator pattern, since provider-scoped decoration can't bind methods.
Source
Thrown at fastmcp_slim/fastmcp/server/providers/local_provider/decorators/prompts.py:171
```
"""
if isinstance(name_or_fn, classmethod):
raise TypeError(
"To decorate a classmethod, use @classmethod above @prompt. "
"See https://gofastmcp.com/servers/prompts#using-with-methods"
)
def decorate_and_register(
fn: AnyFunction, prompt_name: str | None
) -> FunctionPrompt | AnyFunction:
# Check for unbound method
try:
params = list(inspect.signature(fn).parameters.keys())
except (ValueError, TypeError):
params = []
if params and params[0] in ("self", "cls"):
fn_name = getattr(fn, "__name__", "function")
raise TypeError(
f"The function '{fn_name}' has '{params[0]}' as its first parameter. "
f"Use the standalone @prompt decorator and register the bound method:\n\n"
f" from fastmcp.prompts import prompt\n\n"
f" class MyClass:\n"
f" @prompt\n"
f" def {fn_name}(...):\n"
f" ...\n\n"
f" obj = MyClass()\n"
f" mcp.add_prompt(obj.{fn_name})\n\n"
f"See https://gofastmcp.com/servers/prompts#using-with-methods"
)
from fastmcp.prompts.function_prompt import PromptMeta
metadata = PromptMeta(
name=prompt_name,
version=version,
title=title,View on GitHub (pinned to 1f02114297)
Solutions
- Use the standalone `@prompt` decorator inside the class and register the bound method: `mcp.add_prompt(obj.fn)`
- Remove `self` by making it a `@staticmethod` if no instance state is needed
- Register the prompt outside the class in `__init__` after instantiation
Example fix
// before
class MyClass:
@provider.prompt
def greet(self, name): ...
// after
from fastmcp.prompts import prompt
class MyClass:
@prompt
def greet(self, name): ...
obj = MyClass()
mcp.add_prompt(obj.greet) Defensive patterns
Strategy: validation
Validate before calling
import inspect
params = list(inspect.signature(fn).parameters)
if params and params[0] in ('self', 'cls'):
raise TypeError('use standalone @prompt + add_prompt(obj.fn)') Type guard
def is_bound_or_plain(fn) -> bool:
import inspect
p = list(inspect.signature(fn).parameters)
return not p or p[0] not in ('self', 'cls') Try / catch
try:
provider.prompt(method)
except TypeError as e:
if "first parameter" in str(e):
mcp.add_prompt(prompt(method.__get__(obj, type(obj)))) Prevention
- Never apply provider-scoped decorators inside class bodies with self/cls
- Use the documented pattern: standalone @prompt in the class, register bound method later
- Consider @staticmethod when instance state isn't needed
When it happens
Trigger: Applying `@provider.prompt` directly to a method defined with `self`/`cls` as the first parameter inside a class body.
Common situations: Defining prompts as methods on a class and trying to register them at class-definition time; converting module-level prompts into class methods without updating the decorator.
Related errors
- To decorate a classmethod, use @classmethod above @prompt. S
- Cannot specify both a name as first argument and as keyword
- 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/ef40c445a4eb8479.
Report an issue: GitHub.