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:
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
call_next: Callable to get tools from downstream transforms/provider.
- Transformed sequence of tools.
get_tool
name: The requested tool name (may be transformed).call_next: Callable to get tool from downstream.version: Optional version filter to apply.
- The tool if found, None otherwise.
list_resources
call_next: Callable to get resources from downstream transforms/provider.
- Transformed sequence of resources.
get_resource
uri: The requested resource URI (may be transformed).call_next: Callable to get resource from downstream.version: Optional version filter to apply.
- The resource if found, None otherwise.
list_resource_templates
call_next: Callable to get templates from downstream transforms/provider.
- Transformed sequence of resource templates.
get_resource_template
uri: The requested template URI (may be transformed).call_next: Callable to get template from downstream.version: Optional version filter to apply.
- The resource template if found, None otherwise.
list_prompts
call_next: Callable to get prompts from downstream transforms/provider.
- Transformed sequence of prompts.
get_prompt
name: The requested prompt name (may be transformed).call_next: Callable to get prompt from downstream.version: Optional version filter to apply.
- The prompt if found, None otherwise.

