Something went wrong. Try again.
mirror of github.com/PrefectHQ/fastmcp
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129---title: basesidebarTitle: base---
# `fastmcp.tools.base`
## Functions
### `default_serializer` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/tools/base.py#L72" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythondefault_serializer(data: Any) -> str```
## Classes
### `ToolResult` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/tools/base.py#L95" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
**Methods:**
#### `from_mcp_result` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/tools/base.py#L160" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonfrom_mcp_result(cls, result: CallToolResult) -> ToolResult```
Wrap a protocol result while preserving its exact wire representation.
#### `to_mcp_result` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/tools/base.py#L171" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonto_mcp_result(self) -> list[ContentBlock] | tuple[list[ContentBlock], dict[str, Any]] | CallToolResult```
### `InputRequiredToolResult` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/tools/base.py#L193" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
The full result of a single multi-round-trip leg (SEP-2322).
The protocol is stateless: each MRTR leg is a complete request→responsecycle. When a guard tool returns an `InputRequiredResult` from its body toask the client for input, that ask is the *legitimate result* of this toolcall — not a pause, not an error, not a third control-flow outcome. FastMCPwraps it in this `ToolResult` subclass so it flows through the middlewarechain as an ordinary return value: `call_next(...)` returns it, defaultmiddleware completes normally on the leg, and middleware authors canidentify an ask with a simple `isinstance(result, InputRequiredToolResult)`check.
Invariant: the wrapped `InputRequiredResult` is never serialized as toolcontent. `content` is always empty; the wire handler (`_on_call_tool`)reads `.input_required` and returns it to the runner as the`input_required` result. Do not read `.content` / `.structured_content` onthis subclass — they carry nothing.
### `Tool` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/tools/base.py#L231" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
Internal tool registration info.
**Methods:**
#### `to_mcp_tool` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/tools/base.py#L268" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonto_mcp_tool(self, **overrides: Any) -> MCPTool```
Convert the FastMCP tool to an MCP tool.
#### `from_function` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/tools/base.py#L311" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonfrom_function(cls, fn: Callable[..., Any]) -> FunctionTool```
Create a Tool from a function.
#### `run` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/tools/base.py#L349" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonrun(self, arguments: dict[str, Any]) -> ToolResult```
Run the tool with arguments.
This method is not implemented in the base Tool class and must beimplemented by subclasses.
`run()` can EITHER return a list of ContentBlocks, or a tuple of(list of ContentBlocks, dict of structured output).
A tool that requests client input (SEP-2322 multi-round-trip) does so byreturning an `InputRequiredResult` from its body; the run machinery wrapsthat in an `InputRequiredToolResult` — a `ToolResult` subclass — so itstays inside the declared `ToolResult` result type and flows through themiddleware chain as an ordinary result (see `FunctionTool.run`).
#### `convert_result` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/tools/base.py#L367" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonconvert_result(self, raw_value: Any) -> ToolResult```
Convert a raw result to ToolResult.
Handles ToolResult passthrough and converts raw values using the tool'sattributes (output_schema) for proper conversion.
#### `from_tool` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/tools/base.py#L443" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonfrom_tool(cls, tool: Tool | Callable[..., Any]) -> TransformedTool```
#### `get_span_attributes` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/tools/base.py#L489" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonget_span_attributes(self) -> dict[str, Any]```