> ## Documentation Index
> Fetch the complete documentation index at: https://gofastmcp.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# base

# `fastmcp.tools.base`

## Functions

### `default_serializer` <sup>[https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp\_slim/fastmcp/tools/base.py#L72](https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/tools/base.py#L72)</sup>

```python theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
default_serializer(data: Any) -> str
```

## Classes

### `ToolResult` <sup>[https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp\_slim/fastmcp/tools/base.py#L95](https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/tools/base.py#L95)</sup>

**Methods:**

#### `from_mcp_result` <sup>[https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp\_slim/fastmcp/tools/base.py#L160](https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/tools/base.py#L160)</sup>

```python theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
from_mcp_result(cls, result: CallToolResult) -> ToolResult
```

Wrap a protocol result while preserving its exact wire representation.

#### `to_mcp_result` <sup>[https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp\_slim/fastmcp/tools/base.py#L171](https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/tools/base.py#L171)</sup>

```python theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
to_mcp_result(self) -> list[ContentBlock] | tuple[list[ContentBlock], dict[str, Any]] | CallToolResult
```

### `InputRequiredToolResult` <sup>[https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp\_slim/fastmcp/tools/base.py#L193](https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/tools/base.py#L193)</sup>

The full result of a single multi-round-trip leg (SEP-2322).

The protocol is stateless: each MRTR leg is a complete request→response
cycle. When a guard tool returns an `InputRequiredResult` from its body to
ask the client for input, that ask is the *legitimate result* of this tool
call — not a pause, not an error, not a third control-flow outcome. FastMCP
wraps it in this `ToolResult` subclass so it flows through the middleware
chain as an ordinary return value: `call_next(...)` returns it, default
middleware completes normally on the leg, and middleware authors can
identify an ask with a simple `isinstance(result, InputRequiredToolResult)`
check.

Invariant: the wrapped `InputRequiredResult` is never serialized as tool
content. `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` on
this subclass — they carry nothing.

### `Tool` <sup>[https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp\_slim/fastmcp/tools/base.py#L231](https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/tools/base.py#L231)</sup>

Internal tool registration info.

**Methods:**

#### `to_mcp_tool` <sup>[https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp\_slim/fastmcp/tools/base.py#L268](https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/tools/base.py#L268)</sup>

```python theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
to_mcp_tool(self, **overrides: Any) -> MCPTool
```

Convert the FastMCP tool to an MCP tool.

#### `from_function` <sup>[https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp\_slim/fastmcp/tools/base.py#L311](https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/tools/base.py#L311)</sup>

```python theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
from_function(cls, fn: Callable[..., Any]) -> FunctionTool
```

Create a Tool from a function.

#### `run` <sup>[https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp\_slim/fastmcp/tools/base.py#L349](https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/tools/base.py#L349)</sup>

```python theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
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).

A tool that requests client input (SEP-2322 multi-round-trip) does so by
returning an `InputRequiredResult` from its body; the run machinery wraps
that in an `InputRequiredToolResult` — a `ToolResult` subclass — so it
stays inside the declared `ToolResult` result type and flows through the
middleware chain as an ordinary result (see `FunctionTool.run`).

#### `convert_result` <sup>[https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp\_slim/fastmcp/tools/base.py#L367](https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/tools/base.py#L367)</sup>

```python theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
convert_result(self, raw_value: Any) -> ToolResult
```

Convert a raw result to ToolResult.

Handles ToolResult passthrough and converts raw values using the tool's
attributes (output\_schema) for proper conversion.

#### `from_tool` <sup>[https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp\_slim/fastmcp/tools/base.py#L443](https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/tools/base.py#L443)</sup>

```python theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
from_tool(cls, tool: Tool | Callable[..., Any]) -> TransformedTool
```

#### `get_span_attributes` <sup>[https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp\_slim/fastmcp/tools/base.py#L489](https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/tools/base.py#L489)</sup>

```python theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
get_span_attributes(self) -> dict[str, Any]
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.