{"record":{"id":"fc193ef70fc59371","repo":"PrefectHQ/fastmcp","slug":"promptsastools-requires-a-fastmcp-server-instance","errorCode":null,"errorMessage":"PromptsAsTools requires a FastMCP server instance, not a {type(provider).__name__}. The generated tools route through the server's middleware chain at runtime for auth and visibility. Pass your FastMCP server: PromptsAsTools(mcp)","messagePattern":"PromptsAsTools requires a FastMCP server instance, not a (.+?)\\. The generated tools route through the server's middleware chain at runtime for auth and visibility\\. Pass your FastMCP server: PromptsAsTools\\(mcp\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"fastmcp_slim/fastmcp/server/transforms/prompts_as_tools.py","lineNumber":64,"sourceCode":"    middleware, and visibility apply automatically.\n\n    This transform should be applied to a FastMCP server instance, not\n    a raw Provider, because the generated tools need the server's\n    middleware chain for auth and visibility filtering.\n\n    Example:\n        ```python\n        mcp = FastMCP(\"Server\")\n        mcp.add_transform(PromptsAsTools(mcp))\n        # Now has list_prompts and get_prompt tools\n        ```\n    \"\"\"\n\n    def __init__(self, provider: Provider) -> None:\n        from fastmcp.server.server import FastMCP\n\n        if not isinstance(provider, FastMCP):\n            raise TypeError(\n                \"PromptsAsTools requires a FastMCP server instance, not a\"\n                f\" {type(provider).__name__}. The generated tools route through\"\n                \" the server's middleware chain at runtime for auth and\"\n                \" visibility. Pass your FastMCP server: PromptsAsTools(mcp)\"\n            )\n        self._provider = provider\n\n    def __repr__(self) -> str:\n        return f\"PromptsAsTools({self._provider!r})\"\n\n    async def list_tools(self, tools: Sequence[Tool]) -> Sequence[Tool]:\n        \"\"\"Add prompt tools to the tool list.\"\"\"\n        return [\n            *tools,\n            self._make_list_prompts_tool(),\n            self._make_get_prompt_tool(),\n        ]\n","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/server/transforms/prompts_as_tools.py#L46-L82","documentation":"PromptsAsTools is a transform that exposes a server's prompts as callable tools; because the generated tools route through the server's middleware chain (auth, visibility) at runtime, it requires an actual FastMCP instance. Passing any other Provider raises TypeError at construction.","triggerScenarios":"PromptsAsTools(some_provider) where some_provider is not a FastMCP server — e.g., passing a Provider, a transform, or a mounted provider.","commonSituations":"Confusing PromptsAsTools with providers that accept Provider arguments; wiring transforms in a pipeline and passing the wrong object.","solutions":["Pass the FastMCP server instance: PromptsAsTools(mcp)","If you intended to transform a plain provider, mount it into a FastMCP server first and pass that server","Review the transform's signature — it accepts only FastMCP"],"exampleFix":"// before\nPromptsAsTools(my_provider)\n// after\nPromptsAsTools(mcp)  # mcp is your FastMCP server","handlingStrategy":"type-guard","validationCode":"from fastmcp.server.server import FastMCP\nassert isinstance(mcp, FastMCP), \"PromptsAsTools needs a FastMCP server\"","typeGuard":"def is_fastmcp(obj) -> bool:\n    from fastmcp.server.server import FastMCP\n    return isinstance(obj, FastMCP)","tryCatchPattern":"try:\n    t = PromptsAsTools(mcp)\nexcept TypeError as e:\n    logger.error(\"bad transform arg: %s\", e)","preventionTips":["Always pass the FastMCP instance (mcp), not a provider","Check transform constructors' expected types","Mount plain providers into a server before transforming"],"tags":["python","prompts","transforms","type-error"],"backgroundTag":"transform-requires-fastmcp-instance","analyzedSha":"1f021142978e0861cd910c8df4e8074bc7cf3978","analyzedAt":"2026-08-29T14:31:16.082Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}