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.
Examples:
Rename argument ‘old_name’ to ‘new_name’
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.
Methods:
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
: New serializer. Defaults to parent’s serializer.meta
: Control meta information:- NotSet (default): Inherit from parent tool
- dict: Use custom meta information
- None: Remove meta information
- TransformedTool with the specified transformations.