{"record":{"id":"652e3cfaff4e012a","repo":"PrefectHQ/fastmcp","slug":"resourcesastools-requires-a-fastmcp-server-instanc","errorCode":null,"errorMessage":"ResourcesAsTools 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: ResourcesAsTools(mcp)","messagePattern":"ResourcesAsTools 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: ResourcesAsTools\\(mcp\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"fastmcp_slim/fastmcp/server/transforms/resources_as_tools.py","lineNumber":67,"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(ResourcesAsTools(mcp))\n        # Now has list_resources and read_resource 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                \"ResourcesAsTools 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: ResourcesAsTools(mcp)\"\n            )\n        self._provider = provider\n\n    def __repr__(self) -> str:\n        return f\"ResourcesAsTools({self._provider!r})\"\n\n    async def list_tools(self, tools: Sequence[Tool]) -> Sequence[Tool]:\n        \"\"\"Add resource tools to the tool list.\"\"\"\n        return [\n            *tools,\n            self._make_list_resources_tool(),\n            self._make_read_resource_tool(),\n        ]\n","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/server/transforms/resources_as_tools.py#L49-L85","documentation":"ResourcesAsTools exposes a server's resources as tools and, like PromptsAsTools, must route generated tools through the server's middleware chain for auth and visibility — so it only accepts a FastMCP instance. Any other Provider raises TypeError.","triggerScenarios":"ResourcesAsTools(provider) where provider is a raw Provider/transform rather than a FastMCP server.","commonSituations":"Passing a resource provider directly instead of the server that owns it; misreading the API as accepting any Provider.","solutions":["Pass your FastMCP server: ResourcesAsTools(mcp)","Mount the provider into a FastMCP server first, then wrap that server","Check argument order in your transform pipeline"],"exampleFix":"// before\nResourcesAsTools(resource_provider)\n// after\nResourcesAsTools(mcp)","handlingStrategy":"type-guard","validationCode":"from fastmcp.server.server import FastMCP\nassert isinstance(mcp, FastMCP), \"ResourcesAsTools 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 = ResourcesAsTools(mcp)\nexcept TypeError as e:\n    logger.error(\"bad transform arg: %s\", e)","preventionTips":["Pass the FastMCP server instance, not a resource provider","Review transform docs for accepted types","Wire transforms after the server is constructed"],"tags":["python","resources","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"}