Something went wrong. Try again.
mirror of github.com/PrefectHQ/fastmcp
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194---title: __init__sidebarTitle: __init__---
# `fastmcp.server.transforms`
Transform system for component transformations.
Transforms modify components (tools, resources, prompts). List operations use a purefunction pattern where transforms receive sequences and return transformed sequences.Get operations use a middleware pattern with `call_next` to chain lookups.
Unlike middleware (which operates on requests), transforms are observable by thesystem 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` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/server/transforms/__init__.py#L36" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
Protocol for get_tool call_next functions.
### `GetResourceNext` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/server/transforms/__init__.py#L44" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
Protocol for get_resource call_next functions.
### `GetResourceTemplateNext` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/server/transforms/__init__.py#L52" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
Protocol for get_resource_template call_next functions.
### `GetPromptNext` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/server/transforms/__init__.py#L60" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
Protocol for get_prompt call_next functions.
### `Transform` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/server/transforms/__init__.py#L68" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
Base class for component transformations.
List operations use a pure function pattern: transforms receive sequencesand return transformed sequences. Get operations use a middleware patternwith `call_next` to chain lookups.
**Methods:**
#### `list_tools` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/server/transforms/__init__.py#L95" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonlist_tools(self, tools: Sequence[Tool]) -> Sequence[Tool]```
List tools with transformation applied.
**Args:**- `tools`: Sequence of tools to transform.
**Returns:**- Transformed sequence of tools.
#### `get_tool` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/server/transforms/__init__.py#L106" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonget_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` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/server/transforms/__init__.py#L125" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonlist_resources(self, resources: Sequence[Resource]) -> Sequence[Resource]```
List resources with transformation applied.
**Args:**- `resources`: Sequence of resources to transform.
**Returns:**- Transformed sequence of resources.
#### `get_resource` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/server/transforms/__init__.py#L136" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonget_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` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/server/transforms/__init__.py#L159" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonlist_resource_templates(self, templates: Sequence[ResourceTemplate]) -> Sequence[ResourceTemplate]```
List resource templates with transformation applied.
**Args:**- `templates`: Sequence of resource templates to transform.
**Returns:**- Transformed sequence of resource templates.
#### `get_resource_template` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/server/transforms/__init__.py#L172" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonget_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` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/server/transforms/__init__.py#L195" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonlist_prompts(self, prompts: Sequence[Prompt]) -> Sequence[Prompt]```
List prompts with transformation applied.
**Args:**- `prompts`: Sequence of prompts to transform.
**Returns:**- Transformed sequence of prompts.
#### `get_prompt` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/server/transforms/__init__.py#L206" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonget_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.