mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-09 15:19:10 +02:00
* Initialize 2.14 deprecation removal branch * Remove deprecated FASTMCP_SERVER_ environment variable prefix (#2330) * Remove deprecated Context.get_http_request method (#2332) * Remove fastmcp.Image top-level import (deprecated 2.8.1) (#2334) * Remove test warnings (#2331) * Create new branch and fix issue * Remove deprecated client parameter from FastMCPProxy (#2333) * Remove deprecated run_streamable_http_async method (#2338) * Remove deprecated sse_app method (#2337) * Remove deprecated run_sse_async method (#2335) * Remove deprecated run_sse_async method * Update CLI and tests to use run_http_async(transport="sse") - Change CLI to call run_http_async with transport="sse" instead of run_sse_async - Update test to mock run_http_async with create=True for v1 servers * Revert CLI changes - v1 servers do have run_sse_async - Keep CLI calling run_sse_async() for v1 compatibility - Update test to mock run_sse_async (which exists on v1) * Remove unnecessary type ignore for run_sse_async Method exists on v1 FastMCP class, no type error * Remove unused imports after test deletion * Remove deprecated streamable_http_app method (#2336) * Remove deprecated dependencies parameter from FastMCP constructor (#2340) * Remove output_schema=False support (deprecated 2.11.4) (#2339) * Remove deprecated client parameter from FastMCPProxy (#2333) * Delete deprecated test_output_schema_false.py Tests functionality that has been removed * Remove deprecated BearerAuthProvider module (#2341) * Remove resource_prefix_format="protocol" support (deprecated 2.4.0) (#2342) * Remove resource_prefix_format="protocol" support (fixes #2195) Removes deprecated protocol format (prefix+resource://path) and keeps only path format (resource://prefix/path). Since only one format remains: - Removed resource_prefix_format from settings, FastMCP.__init__, and helpers - Simplified add_resource_prefix, remove_resource_prefix, has_resource_prefix - Removed MountedServer.resource_prefix_format field - Deleted tests for protocol format All resource prefixes now use path format exclusively. * Clean up resource_prefix_format references - Remove from test files - Update documentation to remove protocol format section - Move custom HTTP routes note to mounting section - Remove resource_prefix_format from settings docs * Use inline version note instead of badge for prefix format * Remove obsolete test functions and update docs - Delete test functions that no longer assert anything - Remove proxy.mdx reference to deleted prefix format section * Format error messages per ruff * Remove from_client classmethod (deprecated 2.8.0) (#2343) * Remove deprecated from_client classmethod (fixes #2192) * Remove unused Client import * Remove add_resource_fn method (deprecated 2.7.0) (#2345) * Update SDK * Add missing imports for exclude_args deprecation warning
117 lines
5 KiB
Text
117 lines
5 KiB
Text
---
|
|
title: tool
|
|
sidebarTitle: tool
|
|
---
|
|
|
|
# `fastmcp.tools.tool`
|
|
|
|
## Functions
|
|
|
|
### `default_serializer` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#L60" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
default_serializer(data: Any) -> str
|
|
```
|
|
|
|
## Classes
|
|
|
|
### `ToolResult` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#L64" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
**Methods:**
|
|
|
|
#### `to_mcp_result` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#L97" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
to_mcp_result(self) -> list[ContentBlock] | tuple[list[ContentBlock], dict[str, Any]] | CallToolResult
|
|
```
|
|
|
|
### `Tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#L113" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
|
|
Internal tool registration info.
|
|
|
|
|
|
**Methods:**
|
|
|
|
#### `enable` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#L131" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
enable(self) -> None
|
|
```
|
|
|
|
#### `disable` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#L139" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
disable(self) -> None
|
|
```
|
|
|
|
#### `to_mcp_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#L147" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
to_mcp_tool(self, **overrides: Any) -> MCPTool
|
|
```
|
|
|
|
Convert the FastMCP tool to an MCP tool.
|
|
|
|
|
|
#### `from_function` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#L175" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
from_function(fn: Callable[..., Any], name: str | None = None, title: str | None = None, description: str | None = None, icons: list[Icon] | None = None, tags: set[str] | None = None, annotations: ToolAnnotations | None = None, exclude_args: list[str] | None = None, output_schema: dict[str, Any] | NotSetT | None = NotSet, serializer: ToolResultSerializerType | None = None, meta: dict[str, Any] | None = None, enabled: bool | None = None) -> FunctionTool
|
|
```
|
|
|
|
Create a Tool from a function.
|
|
|
|
|
|
#### `run` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#L205" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
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` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#L218" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
from_tool(cls, tool: Tool) -> TransformedTool
|
|
```
|
|
|
|
### `FunctionTool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#L252" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
**Methods:**
|
|
|
|
#### `from_function` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#L256" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
from_function(cls, fn: Callable[..., Any], name: str | None = None, title: str | None = None, description: str | None = None, icons: list[Icon] | None = None, tags: set[str] | None = None, annotations: ToolAnnotations | None = None, exclude_args: list[str] | None = None, output_schema: dict[str, Any] | NotSetT | None = NotSet, serializer: ToolResultSerializerType | None = None, meta: dict[str, Any] | None = None, enabled: bool | None = None) -> FunctionTool
|
|
```
|
|
|
|
Create a Tool from a function.
|
|
|
|
|
|
#### `run` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#L318" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
run(self, arguments: dict[str, Any]) -> ToolResult
|
|
```
|
|
|
|
Run the tool with arguments.
|
|
|
|
|
|
### `ParsedFunction` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#L385" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
**Methods:**
|
|
|
|
#### `from_function` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/tools/tool.py#L393" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
from_function(cls, fn: Callable[..., Any], exclude_args: list[str] | None = None, validate: bool = True, wrap_non_object_output_schema: bool = True) -> ParsedFunction
|
|
```
|