fastmcp.tools.tool

Functions

default_serializer

default_serializer(data: Any) -> str

Classes

ToolResult

Methods:

to_mcp_result

to_mcp_result(self) -> list[ContentBlock] | tuple[list[ContentBlock], dict[str, Any]]

Tool

Internal tool registration info. Methods:

enable

enable(self) -> None

disable

disable(self) -> None

to_mcp_tool

to_mcp_tool(self, **overrides: Any) -> MCPTool

from_function

from_function(fn: Callable[..., Any], name: str | None = None, title: str | None = None, description: str | None = None, tags: set[str] | None = None, annotations: ToolAnnotations | None = None, exclude_args: list[str] | None = None, output_schema: dict[str, Any] | None | NotSetT | Literal[False] = NotSet, serializer: Callable[[Any], str] | None = None, meta: dict[str, Any] | None = None, enabled: bool | None = None) -> FunctionTool
Create a Tool from a function.

run

run(self, arguments: dict[str, Any]) -> ToolResult
Run the tool with arguments. This method is not implemented in the base Tool class and must be implemented by subclasses. run() can EITHER return a list of ContentBlocks, or a tuple of (list of ContentBlocks, dict of structured output).

from_tool

from_tool(cls, tool: Tool, transform_fn: Callable[..., Any] | None = None, name: str | None = None, title: str | None | NotSetT = NotSet, transform_args: dict[str, ArgTransform] | None = None, description: str | None | NotSetT = NotSet, tags: set[str] | None = None, annotations: ToolAnnotations | None = None, output_schema: dict[str, Any] | None | Literal[False] = None, serializer: Callable[[Any], str] | None = None, meta: dict[str, Any] | None | NotSetT = NotSet, enabled: bool | None = None) -> TransformedTool

FunctionTool

Methods:

from_function

from_function(cls, fn: Callable[..., Any], name: str | None = None, title: str | None = None, description: str | None = None, tags: set[str] | None = None, annotations: ToolAnnotations | None = None, exclude_args: list[str] | None = None, output_schema: dict[str, Any] | None | NotSetT | Literal[False] = NotSet, serializer: Callable[[Any], str] | None = None, meta: dict[str, Any] | None = None, enabled: bool | None = None) -> FunctionTool
Create a Tool from a function.

run

run(self, arguments: dict[str, Any]) -> ToolResult
Run the tool with arguments.

ParsedFunction

Methods:

from_function

from_function(cls, fn: Callable[..., Any], exclude_args: list[str] | None = None, validate: bool = True, wrap_non_object_output_schema: bool = True) -> ParsedFunction