{"record":{"id":"5afe201d831b3691","repo":"PrefectHQ/fastmcp","slug":"the-function-fn-name-has-params-0-as-its-5afe20","errorCode":null,"errorMessage":"The function '{fn_name}' has '{params[0]}' as its first parameter. Use the standalone @resource decorator and register the bound method:\n\n    from fastmcp.resources import resource\n\n    class MyClass:\n        @resource('{uri}')\n        def {fn_name}(...):\n            ...\n\n    obj = MyClass()\n    mcp.add_resource(obj.{fn_name})\n\nSee https://gofastmcp.com/servers/resources#using-with-methods","messagePattern":"The function '(.+?)' has '(.+?)' as its first parameter\\. Use the standalone @resource decorator and register the bound method:\n\n    from fastmcp\\.resources import resource\n\n    class MyClass:\n        @resource\\('(.+?)'\\)\n        def (.+?)\\(\\.\\.\\.\\):\n            \\.\\.\\.\n\n    obj = MyClass\\(\\)\n    mcp\\.add_resource\\(obj\\.(.+?)\\)\n\nSee https://gofastmcp\\.com/servers/resources#using-with-methods","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"fastmcp_slim/fastmcp/server/providers/local_provider/decorators/resources.py","lineNumber":177,"sourceCode":"        if isinstance(annotations, dict):\n            annotations = Annotations(**annotations)\n\n        if inspect.isroutine(uri):\n            raise TypeError(\n                \"The @resource decorator was used incorrectly. \"\n                \"It requires a URI as the first argument. \"\n                \"Use @resource('uri') instead of @resource\"\n            )\n\n        def decorator(fn: AnyFunction) -> Any:\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 @resource decorator and register the bound method:\\n\\n\"\n                    f\"    from fastmcp.resources import resource\\n\\n\"\n                    f\"    class MyClass:\\n\"\n                    f\"        @resource('{uri}')\\n\"\n                    f\"        def {fn_name}(...):\\n\"\n                    f\"            ...\\n\\n\"\n                    f\"    obj = MyClass()\\n\"\n                    f\"    mcp.add_resource(obj.{fn_name})\\n\\n\"\n                    f\"See https://gofastmcp.com/servers/resources#using-with-methods\"\n                )\n\n            from fastmcp.resources.function_resource import ResourceMeta\n\n            metadata = ResourceMeta(\n                uri=uri,\n                name=name,\n                version=version,","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/server/providers/local_provider/decorators/resources.py#L159-L195","documentation":"The @resource decorator was applied to an unbound method whose first parameter is `self` (or `cls`). FastMCP does not bind methods automatically for resources at registration time inside a class body, so it refuses and points to the standalone-decorator + bound-method registration pattern.","triggerScenarios":"Applying @resource('uri') to a method defined inside a class (first param self/cls), e.g. decorating an instance or class method in the class body and expecting the server to register it.","commonSituations":"Organizing resources in a class-based service; porting module-level @resource functions into a class without changing the registration approach.","solutions":["Decorate the method with the standalone @resource decorator and register the bound method: mcp.add_resource(obj.method).","Move the resource to a module-level function if no instance state is needed.","For classmethods, decorate after @classmethod so the first param is not raw `cls` (staticmethod also works since it has no self)."],"exampleFix":"// before\nclass MyClass:\n    @resource('config://app')\n    def get_config(self) -> str:\n        ...\n\n// after\nfrom fastmcp.resources import resource\n\nclass MyClass:\n    @resource('config://app')\n    def get_config(self) -> str:\n        ...\n\nobj = MyClass()\nmcp.add_resource(obj.get_config)","handlingStrategy":"validation","validationCode":"import inspect\n\ndef validate_not_unbound_method(fn):\n    params = list(inspect.signature(fn).parameters)\n    if params and params[0] in ('self', 'cls'):\n        raise TypeError('decorate in class body is not supported; register the bound method')\n    return fn","typeGuard":"def is_unbound_method(fn) -> bool:\n    try:\n        params = list(inspect.signature(fn).parameters)\n    except (ValueError, TypeError):\n        return False\n    return bool(params) and params[0] in ('self', 'cls')","tryCatchPattern":"try:\n    register_class_resources(MyService, mcp)\nexcept TypeError as e:\n    if \"has 'self' as its first parameter\" in str(e):\n        logging.error('register bound methods: mcp.add_resource(obj.method)')\n    raise","preventionTips":["Register bound methods after instantiation: mcp.add_resource(obj.method).","Use staticmethod or module-level functions when no instance state is needed.","Don't rely on decorating methods inside class bodies for registration."],"tags":["python","fastmcp","resources","methods"],"backgroundTag":"decorator-applied-to-method","analyzedSha":"1f021142978e0861cd910c8df4e8074bc7cf3978","analyzedAt":"2026-08-29T14:31:16.082Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}