{"record":{"id":"ef40c445a4eb8479","repo":"PrefectHQ/fastmcp","slug":"the-function-fn-name-has-params-0-as-its","errorCode":null,"errorMessage":"The function '{fn_name}' has '{params[0]}' as its first parameter. Use the standalone @prompt decorator and register the bound method:\n\n    from fastmcp.prompts import prompt\n\n    class MyClass:\n        @prompt\n        def {fn_name}(...):\n            ...\n\n    obj = MyClass()\n    mcp.add_prompt(obj.{fn_name})\n\nSee https://gofastmcp.com/servers/prompts#using-with-methods","messagePattern":"The function '(.+?)' has '(.+?)' as its first parameter\\. Use the standalone @prompt decorator and register the bound method:\n\n    from fastmcp\\.prompts import prompt\n\n    class MyClass:\n        @prompt\n        def (.+?)\\(\\.\\.\\.\\):\n            \\.\\.\\.\n\n    obj = MyClass\\(\\)\n    mcp\\.add_prompt\\(obj\\.(.+?)\\)\n\nSee https://gofastmcp\\.com/servers/prompts#using-with-methods","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"fastmcp_slim/fastmcp/server/providers/local_provider/decorators/prompts.py","lineNumber":171,"sourceCode":"            ```\n        \"\"\"\n        if isinstance(name_or_fn, classmethod):\n            raise TypeError(\n                \"To decorate a classmethod, use @classmethod above @prompt. \"\n                \"See https://gofastmcp.com/servers/prompts#using-with-methods\"\n            )\n\n        def decorate_and_register(\n            fn: AnyFunction, prompt_name: str | None\n        ) -> FunctionPrompt | AnyFunction:\n            # Check for unbound method\n            try:\n                params = list(inspect.signature(fn).parameters.keys())\n            except (ValueError, TypeError):\n                params = []\n            if params and params[0] in (\"self\", \"cls\"):\n                fn_name = getattr(fn, \"__name__\", \"function\")\n                raise TypeError(\n                    f\"The function '{fn_name}' has '{params[0]}' as its first parameter. \"\n                    f\"Use the standalone @prompt decorator and register the bound method:\\n\\n\"\n                    f\"    from fastmcp.prompts import prompt\\n\\n\"\n                    f\"    class MyClass:\\n\"\n                    f\"        @prompt\\n\"\n                    f\"        def {fn_name}(...):\\n\"\n                    f\"            ...\\n\\n\"\n                    f\"    obj = MyClass()\\n\"\n                    f\"    mcp.add_prompt(obj.{fn_name})\\n\\n\"\n                    f\"See https://gofastmcp.com/servers/prompts#using-with-methods\"\n                )\n\n            from fastmcp.prompts.function_prompt import PromptMeta\n\n            metadata = PromptMeta(\n                name=prompt_name,\n                version=version,\n                title=title,","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/server/providers/local_provider/decorators/prompts.py#L153-L189","documentation":"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.","triggerScenarios":"Applying `@provider.prompt` directly to a method defined with `self`/`cls` as the first parameter inside a class body.","commonSituations":"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.","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"],"exampleFix":"// before\nclass MyClass:\n    @provider.prompt\n    def greet(self, name): ...\n// after\nfrom fastmcp.prompts import prompt\nclass MyClass:\n    @prompt\n    def greet(self, name): ...\nobj = MyClass()\nmcp.add_prompt(obj.greet)","handlingStrategy":"validation","validationCode":"import inspect\nparams = list(inspect.signature(fn).parameters)\nif params and params[0] in ('self', 'cls'):\n    raise TypeError('use standalone @prompt + add_prompt(obj.fn)')","typeGuard":"def is_bound_or_plain(fn) -> bool:\n    import inspect\n    p = list(inspect.signature(fn).parameters)\n    return not p or p[0] not in ('self', 'cls')","tryCatchPattern":"try:\n    provider.prompt(method)\nexcept TypeError as e:\n    if \"first parameter\" in str(e):\n        mcp.add_prompt(prompt(method.__get__(obj, type(obj))))","preventionTips":["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"],"tags":["python","methods","decorators","prompts"],"backgroundTag":"decorator-on-unbound-method","analyzedSha":"1f021142978e0861cd910c8df4e8074bc7cf3978","analyzedAt":"2026-08-29T14:31:16.082Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}