Client Transports
Understand the different ways FastMCP Clients can connect to servers.
The FastMCP Client
relies on a ClientTransport
object to handle the specifics of connecting to and communicating with an MCP server. FastMCP provides several built-in transport implementations for common connection methods.
While the Client
often infers the correct transport automatically (see Client Overview), you can also instantiate transports explicitly for more control.
Stdio Transports
These transports manage an MCP server running as a subprocess, communicating with it via standard input (stdin) and standard output (stdout). This is the standard mechanism used by clients like Claude Desktop.
Python Stdio
- Class:
fastmcp.client.transports.PythonStdioTransport
- Inferred From: Paths to
.py
files. - Use Case: Running a Python-based MCP server script (like one using FastMCP or the base
mcp
library) in a subprocess.
This is the most common way to interact with local FastMCP servers during development or when integrating with tools that expect to launch a server script.
The server script (my_mcp_server.py
in the example) must include logic to start the MCP server and listen on stdio, typically via mcp.run()
or fastmcp.server.run()
. The Client
only launches the script; it doesn’t inject the server logic.
Node.js Stdio
- Class:
fastmcp.client.transports.NodeStdioTransport
- Inferred From: Paths to
.js
files. - Use Case: Running a Node.js-based MCP server script in a subprocess.
Similar to the Python transport, but for JavaScript servers.
UVX Stdio (Experimental)
- Class:
fastmcp.client.transports.UvxStdioTransport
- Inferred From: Not automatically inferred. Must be instantiated explicitly.
- Use Case: Running an MCP server packaged as a Python tool using
uvx
(part of theuv
toolchain). This allows running tools without explicitly installing them into the current environment.
This is useful for executing MCP servers distributed as command-line tools or packages.
NPX Stdio (Experimental)
- Class:
fastmcp.client.transports.NpxStdioTransport
- Inferred From: Not automatically inferred. Must be instantiated explicitly.
- Use Case: Running an MCP server packaged as an NPM package using
npx
.
Similar to UvxStdioTransport
, but for the Node.js ecosystem.
Network Transports
These transports connect to servers running over a network, typically long-running services accessible via URLs.
SSE (Server-Sent Events)
- Class:
fastmcp.client.transports.SSETransport
- Inferred From:
http://
orhttps://
URLs - Use Case: Connecting to persistent MCP servers exposed over HTTP/S, often using FastMCP’s
mcp.run(transport="sse")
mode.
SSE is a simple, unidirectional protocol where the server pushes messages to the client over a standard HTTP connection.
WebSocket
- Class:
fastmcp.client.transports.WSTransport
- Inferred From:
ws://
orwss://
URLs - Use Case: Connecting to MCP servers using the WebSocket protocol for bidirectional communication.
WebSockets provide a persistent, full-duplex connection between client and server.
In-Memory Transports
FastMCP Transport
- Class:
fastmcp.client.transports.FastMCPTransport
- Inferred From: An instance of
fastmcp.server.FastMCP
. - Use Case: Connecting directly to a
FastMCP
server instance running in the same Python process.
This is extremely useful for:
- Testing: Writing unit or integration tests for your FastMCP server without needing subprocesses or network connections.
- Embedding: Using an MCP server as a component within a larger application.
Communication happens through efficient in-memory queues, making it very fast.
Choosing a Transport
- Local Development/Testing: Use
PythonStdioTransport
(inferred from.py
files) orFastMCPTransport
(for same-process testing). - Connecting to Remote/Persistent Servers: Use
SSETransport
(forhttp/s
) orWSTransport
(forws/s
). - Running Packaged Tools: Use
UvxStdioTransport
(Python/uv) orNpxStdioTransport
(Node/npm) if you need to run MCP servers without local installation. - Integrating with Claude Desktop (or similar): These tools typically expect to run a Python script, so your server should be runnable via
python your_server.py
, makingPythonStdioTransport
the relevant mechanism on the client side.