Client Transports
Configure how FastMCP Clients connect to and communicate with servers.
New in version: 2.0.0
The FastMCP Client
communicates with MCP servers through transport objects that handle the underlying connection mechanics. While the client can automatically select a transport based on what you pass to it, instantiating transports explicitly gives you full control over configuration—environment variables, authentication, session management, and more.
Think of transports as configurable adapters between your client code and MCP servers. Each transport type handles a different communication pattern: subprocesses with pipes, HTTP connections, or direct in-memory calls.
Choosing the Right Transport
- Use STDIO Transport when you need to run local MCP servers with full control over their environment and lifecycle
- Use Remote Transports when connecting to production services or shared MCP servers running independently
- Use In-Memory Transport for testing FastMCP servers without subprocess or network overhead
- Use MCP JSON Configuration when you need to connect to multiple servers defined in configuration files
STDIO Transport
STDIO (Standard Input/Output) transport communicates with MCP servers through subprocess pipes. This is the standard mechanism used by desktop clients like Claude Desktop and is the primary way to run local MCP servers.
The Client Runs the Server
Critical Concept: When using STDIO transport, your client actually launches and manages the server process. This is fundamentally different from network transports where you connect to an already-running server. Understanding this relationship is key to using STDIO effectively.
With STDIO transport, your client:
- Starts the server as a subprocess when you connect
- Manages the server’s lifecycle (start, stop, restart)
- Controls the server’s environment and configuration
- Communicates through stdin/stdout pipes
This architecture enables powerful local integrations but requires understanding environment isolation and process management.
Environment Isolation
STDIO servers run in isolated environments by default. This is a security feature enforced by the MCP protocol to prevent accidental exposure of sensitive data.
When your client launches an MCP server:
- The server does NOT inherit your shell’s environment variables
- API keys, paths, and other configuration must be explicitly passed
- The working directory and system paths may differ from your shell
To pass environment variables to your server, use the env
parameter:
Basic Usage
To use STDIO transport, you create a transport instance with the command and arguments needed to run your server:
You can configure additional settings like environment variables, working directory, or command arguments:
For convenience, the client can also infer STDIO transport from file paths, but this doesn’t allow configuration:
Environment Variables
Since STDIO servers don’t inherit your environment, you need strategies for passing configuration. Here are two common approaches:
Selective forwarding passes only the variables your server actually needs:
Loading from .env files keeps configuration separate from code:
Session Persistence
STDIO transports maintain sessions across multiple client contexts by default (keep_alive=True
). This improves performance by reusing the same subprocess for multiple connections, but can be controlled when you need isolation.
By default, the subprocess persists between connections:
For complete isolation between connections, disable session persistence:
Use keep_alive=False
when you need complete isolation (e.g., in test suites) or when server state could cause issues between connections.
Specialized STDIO Transports
FastMCP provides convenience transports that are thin wrappers around StdioTransport
with pre-configured commands:
PythonStdioTransport
- Usespython
command for.py
filesNodeStdioTransport
- Usesnode
command for.js
filesUvxStdioTransport
- Usesuvx
for Python packages (usesenv_vars
parameter)NpxStdioTransport
- Usesnpx
for Node packages (usesenv_vars
parameter)
For most use cases, instantiate StdioTransport
directly with your desired command. These specialized transports are primarily useful for client inference shortcuts.
Remote Transports
Remote transports connect to MCP servers running as web services. This is a fundamentally different model from STDIO transports—instead of your client launching and managing a server process, you connect to an already-running service that manages its own environment and lifecycle.
Streamable HTTP Transport
New in version: 2.3.0
Streamable HTTP is the recommended transport for production deployments, providing efficient bidirectional streaming over HTTP connections.
- Class:
StreamableHttpTransport
- Server compatibility: FastMCP servers running with
mcp run --transport http
The transport requires a URL and optionally supports custom headers for authentication and configuration:
For convenience, FastMCP also provides authentication helpers:
SSE Transport (Legacy)
Server-Sent Events transport is maintained for backward compatibility but is superseded by Streamable HTTP for new deployments.
- Class:
SSETransport
- Server compatibility: FastMCP servers running with
mcp run --transport sse
SSE transport supports the same configuration options as Streamable HTTP:
Use Streamable HTTP for new deployments unless you have specific infrastructure requirements for SSE.
In-Memory Transport
In-memory transport connects directly to a FastMCP server instance within the same Python process. This eliminates both subprocess management and network overhead, making it ideal for testing and development.
- Class:
FastMCPTransport
Unlike STDIO transports, in-memory servers have full access to your Python process’s environment. They share the same memory space and environment variables as your client code—no isolation or explicit environment passing required.
MCP JSON Configuration Transport
New in version: 2.4.0
This transport supports the emerging MCP JSON configuration standard for defining multiple servers:
- Class:
MCPConfigTransport