Skip to main content
New in version 2.0.0 The fastmcp.Client class provides a programmatic interface for interacting with any MCP server. It handles protocol details and connection management automatically, letting you focus on the operations you want to perform. The FastMCP Client is designed for deterministic, controlled interactions rather than autonomous behavior, making it ideal for testing MCP servers during development, building deterministic applications that need reliable MCP interactions, and creating the foundation for agentic or LLM-based clients with structured, type-safe operations.
This is a programmatic client that requires explicit function calls and provides direct control over all MCP operations. Use it as a building block for higher-level systems.

Creating a Client

You provide a server source and the client automatically infers the appropriate transport mechanism.
All client operations require using the async with context manager for proper connection lifecycle management.

Choosing a Transport

The client automatically selects a transport based on what you pass to it, but different transports have different characteristics that matter for your use case. In-memory transport connects directly to a FastMCP server instance within the same Python process. Use this for testing and development where you want to eliminate subprocess and network complexity. The server shares your process’s environment and memory space.
STDIO transport launches a server as a subprocess and communicates through stdin/stdout pipes. This is the standard mechanism used by desktop clients like Claude Desktop. The subprocess runs in an isolated environment, so you must explicitly pass any environment variables the server needs.
HTTP transport connects to servers running as web services. Use this for production deployments where the server runs independently and manages its own lifecycle.
See Transports for detailed configuration options including authentication headers, session persistence, and multi-server configurations.

Configuration-Based Clients

New in version 2.4.0 Create clients from MCP configuration dictionaries, which can include multiple servers. While there is no official standard for MCP configuration format, FastMCP follows established conventions used by tools like Claude Desktop.

Connection Lifecycle

The client uses context managers for connection management. When you enter the context, the client establishes a connection and performs an MCP initialization handshake with the server. This handshake exchanges capabilities, server metadata, and instructions.
For advanced scenarios where you need precise control over when initialization happens, disable automatic initialization and call initialize() manually:

Operations

FastMCP clients interact with three types of server components. Tools are server-side functions that the client can execute with arguments. Call them with call_tool() and receive structured results.
See Tools for detailed documentation including version selection, error handling, and structured output. Resources are data sources that the client can read, either static or templated. Access them with read_resource() using URIs.
See Resources for detailed documentation including templates and binary content. Prompts are reusable message templates that can accept arguments. Retrieve rendered prompts with get_prompt().
See Prompts for detailed documentation including argument serialization.

Callback Handlers

The client supports callback handlers for advanced server interactions. These let you respond to server-initiated requests and receive notifications.
Each handler type has its own documentation:
  • Sampling - Respond to server LLM requests
  • Elicitation - Handle server requests for user input
  • Progress - Monitor long-running operations
  • Logging - Handle server log messages
  • Roots - Provide local context to servers
The FastMCP Client is designed as a foundational tool. Use it directly for deterministic operations, or build higher-level agentic systems on top of its reliable, type-safe interface.