{"record":{"id":"9e2a7ba150a85837","repo":"PrefectHQ/fastmcp","slug":"mcp-resource-got-unexpected-keyword-argument-s","errorCode":null,"errorMessage":"mcp_resource() got unexpected keyword argument(s): {sorted(unknown)!r}. Valid keyword arguments are: {sorted(_RESOURCE_VALID_KWARGS)}","messagePattern":"mcp_resource\\(\\) got unexpected keyword argument\\(s\\): (.+?)\\. Valid keyword arguments are: (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"fastmcp_slim/fastmcp/contrib/mcp_mixin/mcp_mixin.py","lineNumber":110,"sourceCode":"    Accepts all parameters supported by ``Resource.from_function``.  Any new\n    parameters added to ``Resource.from_function`` are automatically forwarded\n    without requiring changes here.\n\n    Args:\n        uri: Resource URI (required).\n        name: Resource name.  Defaults to the decorated method name.\n        enabled: If ``False``, the resource is skipped during registration.\n        **kwargs: Additional keyword arguments forwarded verbatim to\n            ``Resource.from_function`` (e.g. ``description``, ``tags``,\n            ``mime_type``, ``auth``, ``version``, …).\n\n    Raises:\n        TypeError: If an unrecognised keyword argument is supplied.  The error\n            is raised immediately at decoration time rather than later.\n    \"\"\"\n    unknown = set(kwargs) - _RESOURCE_VALID_KWARGS\n    if unknown:\n        raise TypeError(\n            f\"mcp_resource() got unexpected keyword argument(s): {sorted(unknown)!r}. \"\n            f\"Valid keyword arguments are: {sorted(_RESOURCE_VALID_KWARGS)}\"\n        )\n\n    def decorator(func: Callable[..., Any]) -> Callable[..., Any]:\n        call_args: dict[str, Any] = {\n            \"uri\": uri,\n            \"name\": name or get_fn_name(func),\n            **kwargs,\n        }\n        if enabled is not None:\n            call_args[_MIXIN_ENABLED_KEY] = enabled\n        setattr(func, _MCP_REGISTRATION_RESOURCE_ATTR, call_args)\n        return func\n\n    return decorator\n\n","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/contrib/mcp_mixin/mcp_mixin.py#L92-L128","documentation":"mcp_resource() validates its keyword arguments at decoration time against the live parameter set of Resource.from_function (excluding fn and uri). Any keyword not accepted by Resource.from_function triggers this TypeError immediately, giving fail-fast feedback before registration.","triggerScenarios":"Decorating a class method with @mcp_resource(uri, ...) and passing a kwarg Resource.from_function rejects — misspelled options, kwargs removed/renamed in a newer fastmcp, or kwargs valid for mcp_tool but not for resources (e.g. `annotations=` or `timeout=` if the resource signature lacks them).","commonSituations":"Version upgrades that changed Resource.from_function's parameters; copying kwargs between mcp_tool/mcp_resource/mcp_prompt decorators; typos such as `mime_tyep=`.","solutions":["Use the 'Valid keyword arguments are:' list in the message to correct or drop the offending kwarg(s)","Compare against inspect.signature(Resource.from_function) for your fastmcp version","Fix typos (e.g. mime_tyep -> mime_type)","Remember `uri` is positional and `enabled` is mixin-only; don't pass uri again as a kwarg"],"exampleFix":"// before\n@mcp_resource(\"config://app\", mime_tyep=\"application/json\")\ndef get_config(self) -> str: ...\n\n// after\n@mcp_resource(\"config://app\", mime_type=\"application/json\")\ndef get_config(self) -> str: ...","handlingStrategy":"validation","validationCode":"import inspect\nfrom fastmcp.resources.base import Resource\nvalid = set(inspect.signature(Resource.from_function).parameters) - {\"fn\", \"uri\"}\nbad = set(my_kwargs) - valid\nif bad:\n    raise TypeError(f\"Invalid mcp_resource kwargs: {bad}\")","typeGuard":"def has_valid_resource_kwargs(kwargs: dict) -> bool:\n    import inspect\n    from fastmcp.resources.base import Resource\n    valid = set(inspect.signature(Resource.from_function).parameters) - {\"fn\", \"uri\"}\n    return set(kwargs) <= valid","tryCatchPattern":null,"preventionTips":["Don't share kwarg dicts between mcp_tool/mcp_resource/mcp_prompt","Pin and review fastmcp changelog for from_function signature changes","Add an import-time smoke test decorating dummy resource methods"],"tags":["python","decorator","type-error","fastmcp"],"backgroundTag":"unexpected-keyword-argument","analyzedSha":"1f021142978e0861cd910c8df4e8074bc7cf3978","analyzedAt":"2026-08-29T14:31:16.082Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}