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.
- 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
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
env
parameter:
Basic Usage
To use STDIO transport, you create a transport instance with the command and arguments needed to run your server: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: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:
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 aroundStdioTransport
with pre-configured commands:
PythonStdioTransport
- Usespython
command for.py
filesNodeStdioTransport
- Usesnode
command for.js
filesUvStdioTransport
- Usesuv
for Python packages (usesenv_vars
parameter)UvxStdioTransport
- Usesuvx
for Python packages (usesenv_vars
parameter)NpxStdioTransport
- Usesnpx
for Node packages (usesenv_vars
parameter)
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
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
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
Tool Transformation with FastMCP and MCPConfig
FastMCP supports basic tool transformations to be defined alongside the MCP Servers in the MCPConfig file.weather_get_forecast
tool to only retrieve the weather for Miami
and hiding the city
argument from the client.
Allowlisting and Blocklisting Tools
Tools can be allowlisted or blocklisted from the client by applyingtags
to the tools on the server. In the following example, we’re allowlisting only tools marked with the forecast
tag, all other tools will be unavailable to the client.