tool_transform
fastmcp.tools.tool_transform
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.
Examples:
Rename argument ‘old_name’ to ‘new_name’
Change description only
Add a default value (makes argument optional)
Add a default factory (makes argument optional)
Change the type
Hide the argument entirely from clients
Hide argument but pass a constant value to parent
Hide argument but pass a factory-generated value to parent
Make an optional parameter required (removes any default)
Combine multiple transformations
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, 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.
Methods:
from_tool
Create a transformed tool from a parent tool.
Args:
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.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.serializer
: New serializer. Defaults to parent’s serializer.
Returns:
- TransformedTool with the specified transformations.
Examples: