fastmcp.tools.tool_transform
Functions
forward
x and y, but the transformed
tool has args a and b, and an transform_args was provided that maps x to
a and y to b, then forward(a=1, b=2) will call the parent tool with
x=1 and y=2.
Args:
**kwargs: Arguments to forward to the parent tool (using transformed names).
- The ToolResult from the parent tool execution.
RuntimeError: If called outside a transformed tool context.TypeError: If provided arguments don’t match the transformed schema.
forward_raw
x and y, then forward_raw(x=1, y=2) will call the parent tool with x=1 and y=2.
Args:
**kwargs: Arguments to pass directly to the parent tool (using original names).
- The ToolResult from the parent tool execution.
RuntimeError: If called outside a transformed tool context.
apply_transformations_to_tools
Classes
ArgTransform
Configuration for transforming a parent tool’s argument.
This class allows fine-grained control over how individual arguments are transformed
when creating a new tool from an existing one. You can rename arguments, change their
descriptions, add default values, or hide them from clients while passing constants.
Attributes:
name: New name for the argument. Use None to keep original name, or … for no change.description: New description for the argument. Use None to remove description, or … for no change.default: New default value for the argument. Use … for no change.default_factory: Callable that returns a default value. Cannot be used with default.type: New type for the argument. Use … for no change.hide: If True, hide this argument from clients but pass a constant value to parent.required: If True, make argument required (remove default). Use … for no change.examples: Examples for the argument. Use … for no change.
ArgTransformConfig
A model for requesting a single argument transform.
Methods:
to_arg_transform
TransformedTool
A tool that is transformed from another tool.
This class represents a tool that has been created by transforming another tool.
It supports argument renaming, schema modification, custom function injection,
structured output control, and provides context for the forward() and forward_raw() functions.
The transformation can be purely schema-based (argument renaming, dropping, etc.)
or can include a custom function that uses forward() to call the parent tool
with transformed arguments. Output schemas and structured outputs are automatically
inherited from the parent tool but can be overridden or disabled.
Attributes:
parent_tool: The original tool that this tool was transformed from.fn: The function to execute when this tool is called (either the forwarding function for pure transformations or a custom user function).forwarding_fn: Internal function that handles argument transformation and validation when forward() is called from custom functions.
run
arguments: Dictionary of arguments to pass to the tool’s function.
- ToolResult object containing content and optional structured output.
from_tool
tool: The parent tool to transform.transform_fn: Optional custom function. Can use forward() and forward_raw() to call the parent tool. Functions with **kwargs receive transformed argument names.name: New name for the tool. Defaults to parent tool’s name.title: New title for the tool. Defaults to parent tool’s title.transform_args: Optional transformations for parent tool arguments. Only specified arguments are transformed, others pass through unchanged:- Simple rename (str)
- Complex transformation (rename/description/default/drop) (ArgTransform)
- Drop the argument (None)
description: New description. Defaults to parent’s description.tags: New tags. Defaults to parent’s tags.annotations: New annotations. Defaults to parent’s annotations.output_schema: Control output schema for structured outputs:- None (default): Inherit from transform_fn if available, then parent tool
- dict: Use custom output schema
- False: Disable output schema and structured outputs
serializer: Deprecated. Return ToolResult from your tools for full control over serialization.meta: Control meta information:- NotSet (default): Inherit from parent tool
- dict: Use custom meta information
- None: Remove meta information
- TransformedTool with the specified transformations.

