Skip to main content

fastmcp.tools.function_tool

Standalone @tool decorator for FastMCP.

Functions

tool

Standalone decorator to mark a function as an MCP tool. Returns the original function with metadata attached. Register with a server using mcp.add_tool().

Classes

DecoratedTool

Protocol for functions decorated with @tool.

ToolMeta

Metadata attached to functions by the @tool decorator.

FunctionTool

Methods:

to_mcp_tool

Convert the FastMCP tool to an MCP tool. Extends the base implementation to add task execution mode if enabled.

from_function

Create a FunctionTool from a function. Args:
  • fn: The function to wrap
  • metadata: ToolMeta object with all configuration. If provided, individual parameters must not be passed.
  • name, title, etc.: Individual parameters for backwards compatibility. Cannot be used together with metadata parameter.

run

Run the tool with arguments.

register_with_docket

Register this tool with docket for background execution. FunctionTool registers the underlying function, which has the user’s Depends parameters for docket to resolve.

add_to_docket

Schedule this tool for background execution via docket. FunctionTool splats the arguments dict since .fn expects **kwargs. Args:
  • docket: The Docket instance
  • arguments: Tool arguments
  • fn_key: Function lookup key in Docket registry (defaults to self.key)
  • task_key: Redis storage key for the result
  • **kwargs: Additional kwargs passed to docket.add()