{"record":{"id":"d319c70c7be84bd8","repo":"PrefectHQ/fastmcp","slug":"expected-prompt-or-prompt-decorated-function-got","errorCode":null,"errorMessage":"Expected Prompt or @prompt-decorated function, got {type(prompt).__name__}. Use @prompt decorator or pass a Prompt instance.","messagePattern":"Expected Prompt or @prompt-decorated function, got (.+?)\\. Use @prompt decorator or pass a Prompt instance\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"fastmcp_slim/fastmcp/server/providers/local_provider/decorators/prompts.py","lineNumber":60,"sourceCode":"            from fastmcp.decorators import get_fastmcp_meta\n            from fastmcp.prompts.function_prompt import PromptMeta\n\n            meta = get_fastmcp_meta(prompt)\n            if meta is not None and isinstance(meta, PromptMeta):\n                enabled = meta.enabled\n                prompt = Prompt.from_function(\n                    prompt,\n                    name=meta.name,\n                    version=meta.version,\n                    title=meta.title,\n                    description=meta.description,\n                    icons=meta.icons,\n                    tags=meta.tags,\n                    meta=meta.meta,\n                    auth=meta.auth,\n                )\n            else:\n                raise TypeError(\n                    f\"Expected Prompt or @prompt-decorated function, got {type(prompt).__name__}. \"\n                    \"Use @prompt decorator or pass a Prompt instance.\"\n                )\n        self._add_component(prompt)\n        if not enabled:\n            self.disable(keys={prompt.key})\n        return prompt\n\n    @overload\n    def prompt(\n        self: LocalProvider,\n        name_or_fn: F,\n        *,\n        name: str | None = None,\n        version: str | int | None = None,\n        title: str | None = None,\n        description: str | None = None,\n        icons: list[mcp_types.Icon] | None = None,","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/server/providers/local_provider/decorators/prompts.py#L42-L78","documentation":"`add_prompt` accepts either a `Prompt` instance or a function already decorated with `@prompt`. Anything else (a raw undecorated function, a coroutine, a string, a class) hits this TypeError naming the offending type.","triggerScenarios":"Calling `provider.add_prompt(my_fn)` on a plain function that was never wrapped by `@prompt`; passing the result of a called decorator (`@prompt()` misuse); passing a non-prompt object like a Tool.","commonSituations":"Migrating from older FastMCP APIs where raw functions were accepted; confusion between `@prompt` and `@prompt()`; copy-paste from tool examples into prompt registration.","solutions":["Decorate the function with `@prompt` before passing it: `add_prompt(prompt(my_fn))` or `mcp.prompt(my_fn)`","Pass a `Prompt` instance (`Prompt(name=..., fn=...)`) instead of a raw callable","Check you didn't call the decorator: use `@prompt`, not `@prompt()` above the def, or `prompt` not `prompt()` when wrapping manually"],"exampleFix":"// before\nmcp.add_prompt(get_greeting)  # raw function\n// after\nfrom fastmcp.prompts import prompt\nmcp.add_prompt(prompt(get_greeting))","handlingStrategy":"type-guard","validationCode":"from fastmcp.prompts import Prompt\nif not isinstance(obj, Prompt) and not callable(obj):\n    raise ValueError('add_prompt needs a Prompt or @prompt-decorated function')","typeGuard":"def is_prompt_like(x) -> bool:\n    from fastmcp.prompts import Prompt\n    return isinstance(x, Prompt) or (callable(x) and getattr(x, '__fastmcp__', None) is not None)","tryCatchPattern":"try:\n    mcp.add_prompt(obj)\nexcept TypeError as e:\n    if 'Expected Prompt' in str(e):\n        mcp.add_prompt(prompt(obj))","preventionTips":["Always decorate functions with @prompt before registration","Remember @prompt (no parens) when decorating directly","Don't mix Tool and Prompt objects when registering"],"tags":["python","type-error","prompts","api-misuse"],"backgroundTag":"invalid-component-type","analyzedSha":"1f021142978e0861cd910c8df4e8074bc7cf3978","analyzedAt":"2026-08-29T14:31:16.082Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}