client
fastmcp.client.client
Classes
Client
MCP client that delegates connection management to a Transport instance.
The Client class is responsible for MCP protocol logic, while the Transport handles connection establishment and management. Client provides methods for working with resources, prompts, tools and other MCP capabilities.
Args: transport: Connection source specification, which can be:
- ClientTransport: Direct transport instance
- FastMCP: In-process FastMCP server
- AnyUrl | str: URL to connect to
- Path: File path for local socket
- MCPConfig: MCP server configuration
- dict: Transport configuration roots: Optional RootsList or RootsHandler for filesystem access sampling_handler: Optional handler for sampling requests log_handler: Optional handler for log messages message_handler: Optional handler for protocol messages progress_handler: Optional handler for progress notifications timeout: Optional timeout for requests (seconds or timedelta) init_timeout: Optional timeout for initial connection (seconds or timedelta). Set to 0 to disable. If None, uses the value in the FastMCP global settings.
Examples:
# Connect to FastMCP server client =
Methods:
session
Get the current active session. Raises RuntimeError if not connected.
initialize_result
Get the result of the initialization request.
set_roots
Set the roots for the client. This does not automatically call send_roots_list_changed
.
set_sampling_callback
Set the sampling callback for the client.
is_connected
Check if the client is currently connected.