mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-15 18:19:10 +02:00
112 lines
3.4 KiB
Text
112 lines
3.4 KiB
Text
---
|
|
title: types
|
|
sidebarTitle: types
|
|
---
|
|
|
|
# `fastmcp.utilities.types`
|
|
|
|
|
|
Common types used across FastMCP.
|
|
|
|
## Functions
|
|
|
|
### `get_cached_typeadapter` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#L35"><Icon icon="github" size="14" /></a></sup>
|
|
|
|
```python
|
|
get_cached_typeadapter(cls: T) -> TypeAdapter[T]
|
|
```
|
|
|
|
|
|
TypeAdapters are heavy objects, and in an application context we'd typically
|
|
create them once in a global scope and reuse them as often as possible.
|
|
However, this isn't feasible for user-generated functions. Instead, we use a
|
|
cache to minimize the cost of creating them as much as possible.
|
|
|
|
|
|
### `issubclass_safe` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#L45"><Icon icon="github" size="14" /></a></sup>
|
|
|
|
```python
|
|
issubclass_safe(cls: type, base: type) -> bool
|
|
```
|
|
|
|
|
|
Check if cls is a subclass of base, even if cls is a type variable.
|
|
|
|
|
|
### `is_class_member_of_type` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#L55"><Icon icon="github" size="14" /></a></sup>
|
|
|
|
```python
|
|
is_class_member_of_type(cls: type, base: type) -> bool
|
|
```
|
|
|
|
|
|
Check if cls is a member of base, even if cls is a type variable.
|
|
|
|
Base can be a type, a UnionType, or an Annotated type. Generic types are not
|
|
considered members (e.g. T is not a member of list\[T]).
|
|
|
|
|
|
### `find_kwarg_by_type` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#L77"><Icon icon="github" size="14" /></a></sup>
|
|
|
|
```python
|
|
find_kwarg_by_type(fn: Callable, kwarg_type: type) -> str | None
|
|
```
|
|
|
|
|
|
Find the name of the kwarg that is of type kwarg_type.
|
|
|
|
Includes union types that contain the kwarg_type, as well as Annotated types.
|
|
|
|
|
|
## Classes
|
|
|
|
### `FastMCPBaseModel` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#L28"><Icon icon="github" size="14" /></a></sup>
|
|
|
|
|
|
Base model for FastMCP models.
|
|
|
|
|
|
### `Image` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#L94"><Icon icon="github" size="14" /></a></sup>
|
|
|
|
|
|
Helper class for returning images from tools.
|
|
|
|
|
|
**Methods:**
|
|
|
|
#### `to_image_content` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#L131"><Icon icon="github" size="14" /></a></sup>
|
|
|
|
```python
|
|
to_image_content(self, mime_type: str | None = None, annotations: Annotations | None = None) -> ImageContent
|
|
```
|
|
|
|
Convert to MCP ImageContent.
|
|
|
|
|
|
### `Audio` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#L153"><Icon icon="github" size="14" /></a></sup>
|
|
|
|
|
|
Helper class for returning audio from tools.
|
|
|
|
|
|
**Methods:**
|
|
|
|
#### `to_audio_content` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#L190"><Icon icon="github" size="14" /></a></sup>
|
|
|
|
```python
|
|
to_audio_content(self, mime_type: str | None = None, annotations: Annotations | None = None) -> AudioContent
|
|
```
|
|
|
|
### `File` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#L211"><Icon icon="github" size="14" /></a></sup>
|
|
|
|
|
|
Helper class for returning audio from tools.
|
|
|
|
|
|
**Methods:**
|
|
|
|
#### `to_resource_content` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/types.py#L250"><Icon icon="github" size="14" /></a></sup>
|
|
|
|
```python
|
|
to_resource_content(self, mime_type: str | None = None, annotations: Annotations | None = None) -> EmbeddedResource
|
|
```
|