{"record":{"id":"7c7759a7cf2765db","repo":"PrefectHQ/fastmcp","slug":"the-resource-decorator-was-used-incorrectly-it-r","errorCode":null,"errorMessage":"The @resource decorator was used incorrectly. It requires a URI as the first argument. Use @resource('uri') instead of @resource","messagePattern":"The @resource decorator was used incorrectly\\. It requires a URI as the first argument\\. Use @resource\\('uri'\\) instead of @resource","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"fastmcp_slim/fastmcp/server/providers/local_provider/decorators/resources.py","lineNumber":163,"sourceCode":"\n        Example:\n            ```python\n            provider = LocalProvider()\n\n            @provider.resource(\"data://config\")\n            def get_config() -> str:\n                return '{\"setting\": \"value\"}'\n\n            @provider.resource(\"data://{city}/weather\")\n            def get_weather(city: str) -> str:\n                return f\"Weather for {city}\"\n            ```\n        \"\"\"\n        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\"","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/server/providers/local_provider/decorators/resources.py#L145-L181","documentation":"The @resource decorator requires a URI string as its first positional argument. When applied bare as @resource (directly above a function), Python passes the function itself as `uri`; FastMCP detects this (inspect.isroutine) and raises to teach the correct usage.","triggerScenarios":"Writing `@resource` instead of `@resource('scheme://path')` above a function, then registering it on a FastMCP instance.","commonSituations":"Copying the @tool pattern (which supports bare @tool) and applying it to @resource, which always requires a URI; typos when converting a plain function into a resource.","solutions":["Add the URI argument: use @resource('your-scheme://your-uri') instead of @resource.","If configuration is needed, use @resource('uri', name=..., description=...) — parentheses are mandatory."],"exampleFix":"// before\n@resource\ndef get_config() -> str:\n    ...\n\n// after\n@resource('config://app')\ndef get_config() -> str:\n    ...","handlingStrategy":"validation","validationCode":"uri = 'config://app'\nif not isinstance(uri, str):\n    raise TypeError('first arg to @resource must be a URI string')\n\n@resource(uri)\ndef get_config() -> str:\n    ...","typeGuard":"def has_uri_args(decorated) -> bool:\n    return callable(decorated) and not inspect.isroutine(decorated)","tryCatchPattern":"try:\n    mcp.add_resource(my_fn)\nexcept TypeError as e:\n    if 'requires a URI' in str(e):\n        raise ValueError('forgot the URI: use @resource(\"uri\")') from e\n    raise","preventionTips":["Remember @resource always needs a URI, unlike @tool which supports bare usage.","Lint for bare @resource lines in code review.","Keep the URI scheme in a constant to avoid typo'd decorator usage."],"tags":["python","fastmcp","resources","decorator-misuse"],"backgroundTag":"decorator-missing-argument","analyzedSha":"1f021142978e0861cd910c8df4e8074bc7cf3978","analyzedAt":"2026-08-29T14:31:16.082Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}