Skip to main content

_is_pydantic_serializable

def _is_pydantic_serializable(type_annotation: Any):
Check if a type annotation is Pydantic serializable. Parameters:
  • type_annotation: The type annotation to check
Returns: Tuple[bool, str]: (is_serializable, error_message)

_validate_function_types

def _validate_function_types(func: Callable[..., Any]):
Validate function parameter and return types are Pydantic serializable. Parameters:
  • func (Callable[…, Any]): The function to validate.
Returns: List[str]: List of error messages for incompatible types.

MCPServer

class MCPServer:
Decorator class for registering functions of a class as tools in an MCP (Model Context Protocol) server. This class is typically used to wrap a toolkit or service class and automatically register specified methods (or methods derived from BaseToolkit) with a FastMCP server. Parameters:
  • function_names (Optional[list[str]]): A list of method names to expose via the MCP server. If not provided and the class is a subclass of BaseToolkit, method names will be inferred from the tools returned by get_tools().
  • server_name (Optional[str]): A name for the MCP server. If not provided, the class name of the decorated object is used.

init

def __init__(
    self,
    function_names: Optional[List[str]] = None,
    server_name: Optional[str] = None
):

make_wrapper

def make_wrapper(self, func: Callable[..., Any]):
Wraps a function (sync or async) to preserve its signature and metadata. This is used to ensure the MCP server can correctly call and introspect the method. Parameters:
  • func (Callable[…, Any]): The function to wrap.
Returns: Callable[…, Any]: The wrapped function, with preserved signature and async support.

call

def __call__(self, cls):
Decorates a class by injecting an MCP server instance and registering specified methods. Parameters:
  • cls (type): The class being decorated.
Returns: type: The modified class with MCP integration.