--- title: __init__ sidebarTitle: __init__ --- # `fastmcp.server.transforms` Transform system for component transformations. Transforms modify components (tools, resources, prompts) using a middleware pattern. Each transform wraps the next in the chain via `call_next`, allowing transforms to intercept, modify, or replace component queries. Unlike middleware (which operates on requests), transforms are observable by the system for task registration, tag filtering, and component introspection. Example: ```python from fastmcp import FastMCP from fastmcp.server.transforms import Namespace server = FastMCP("Server") mount = server.mount(other_server) mount.add_transform(Namespace("api")) # Tools become api_toolname ``` ## Classes ### `GetToolNext` Protocol for get_tool call_next functions. ### `GetResourceNext` Protocol for get_resource call_next functions. ### `GetResourceTemplateNext` Protocol for get_resource_template call_next functions. ### `GetPromptNext` Protocol for get_prompt call_next functions. ### `Transform` Base class for component transformations. Transforms use a middleware pattern with `call_next` to chain operations. Each transform can intercept, modify, or pass through component queries. For list operations, call `call_next()` to get components from downstream, then transform the result. For get operations, optionally transform the name/uri before calling `call_next`, then transform the result. **Methods:** #### `list_tools` ```python list_tools(self, call_next: ListToolsNext) -> Sequence[Tool] ``` List tools with transformation applied. **Args:** - `call_next`: Callable to get tools from downstream transforms/provider. **Returns:** - Transformed sequence of tools. #### `get_tool` ```python get_tool(self, name: str, call_next: GetToolNext) -> Tool | None ``` Get a tool by name. **Args:** - `name`: The requested tool name (may be transformed). - `call_next`: Callable to get tool from downstream. - `version`: Optional version filter to apply. **Returns:** - The tool if found, None otherwise. #### `list_resources` ```python list_resources(self, call_next: ListResourcesNext) -> Sequence[Resource] ``` List resources with transformation applied. **Args:** - `call_next`: Callable to get resources from downstream transforms/provider. **Returns:** - Transformed sequence of resources. #### `get_resource` ```python get_resource(self, uri: str, call_next: GetResourceNext) -> Resource | None ``` Get a resource by URI. **Args:** - `uri`: The requested resource URI (may be transformed). - `call_next`: Callable to get resource from downstream. - `version`: Optional version filter to apply. **Returns:** - The resource if found, None otherwise. #### `list_resource_templates` ```python list_resource_templates(self, call_next: ListResourceTemplatesNext) -> Sequence[ResourceTemplate] ``` List resource templates with transformation applied. **Args:** - `call_next`: Callable to get templates from downstream transforms/provider. **Returns:** - Transformed sequence of resource templates. #### `get_resource_template` ```python get_resource_template(self, uri: str, call_next: GetResourceTemplateNext) -> ResourceTemplate | None ``` Get a resource template by URI. **Args:** - `uri`: The requested template URI (may be transformed). - `call_next`: Callable to get template from downstream. - `version`: Optional version filter to apply. **Returns:** - The resource template if found, None otherwise. #### `list_prompts` ```python list_prompts(self, call_next: ListPromptsNext) -> Sequence[Prompt] ``` List prompts with transformation applied. **Args:** - `call_next`: Callable to get prompts from downstream transforms/provider. **Returns:** - Transformed sequence of prompts. #### `get_prompt` ```python get_prompt(self, name: str, call_next: GetPromptNext) -> Prompt | None ``` Get a prompt by name. **Args:** - `name`: The requested prompt name (may be transformed). - `call_next`: Callable to get prompt from downstream. - `version`: Optional version filter to apply. **Returns:** - The prompt if found, None otherwise.