Proxy Servers
Use FastMCP to act as an intermediary or change transport for other MCP servers.
New in version: 2.0.0
FastMCP provides a powerful proxying capability that allows one FastMCP server instance to act as a frontend for another MCP server (which could be remote, running on a different transport, or even another FastMCP instance). This is achieved using the FastMCP.as_proxy()
class method.
What is Proxying?
Proxying means setting up a FastMCP server that doesn’t implement its own tools or resources directly. Instead, when it receives a request (like tools/call
or resources/read
), it forwards that request to a backend MCP server, receives the response, and then relays that response back to the original client.
Key Benefits
New in version: 2.10.3
- Session Isolation: Each request gets its own isolated session, ensuring safe concurrent operations
- Transport Bridging: Expose servers running on one transport via a different transport
- Advanced MCP Features: Automatic forwarding of sampling, elicitation, logging, and progress
- Security: Acts as a controlled gateway to backend servers
- Simplicity: Single endpoint even if backend location or transport changes
Quick Start
New in version: 2.10.3
The recommended way to create a proxy is using ProxyClient
, which provides full MCP feature support with automatic session isolation:
This single setup gives you:
- Safe concurrent request handling
- Automatic forwarding of advanced MCP features (sampling, elicitation, etc.)
- Session isolation to prevent context mixing
- Full compatibility with all MCP clients
You can also pass a FastMCP client transport (or parameter that can be inferred to a transport) to as_proxy()
. This will automatically create a ProxyClient
instance for you.
Finally, you can pass a regular FastMCP Client
instance to as_proxy()
. This will work for many use cases, but may break if advanced MCP features like sampling or elicitation are invoked by the server.
Session Isolation & Concurrency
New in version: 2.10.3
FastMCP proxies provide session isolation to ensure safe concurrent operations. The session strategy depends on how the proxy is configured:
Fresh Sessions
When you pass a disconnected client (which is the normal case), each request gets its own isolated backend session:
Session Reuse with Connected Clients
When you pass an already-connected client, the proxy will reuse that session for all requests:
Important: Using shared sessions with concurrent requests from multiple clients may lead to context mixing and race conditions. This approach should only be used in single-threaded scenarios or when you have explicit synchronization.
Transport Bridging
A common use case is bridging transports - exposing a server running on one transport via a different transport. For example, making a remote SSE server available locally via stdio:
Or expose a local server via HTTP for remote access:
Advanced MCP Features
New in version: 2.10.3
ProxyClient
automatically forwards advanced MCP protocol features between the backend server and clients connected to the proxy, ensuring full MCP compatibility.
Supported Features
- Roots: Forwards filesystem root access requests to the client
- Sampling: Forwards LLM completion requests from backend to client
- Elicitation: Forwards user input requests to the client
- Logging: Forwards log messages from backend through to client
- Progress: Forwards progress notifications during long operations
Customizing Feature Support
You can selectively disable forwarding by passing None
for specific handlers:
When you use a transport string directly with FastMCP.as_proxy()
, it automatically creates a ProxyClient
internally to ensure full feature support.
Configuration-Based Proxies
New in version: 2.4.0
You can create a proxy directly from a configuration dictionary that follows the MCPConfig schema. This is useful for quickly setting up proxies to remote servers without manually configuring each connection detail.
The MCPConfig format follows an emerging standard for MCP server configuration and may evolve as the specification matures. While FastMCP aims to maintain compatibility with future versions, be aware that field names or structure might change.
Multi-Server Configurations
You can create a proxy to multiple servers by specifying multiple entries in the config. They are automatically mounted with their config names as prefixes:
Mirrored Components
New in version: 2.10.5
When you access tools, resources, or prompts from a proxy server, they are “mirrored” from the remote server. Mirrored components cannot be modified directly since they reflect the state of the remote server. For example, you can not simply “disable” a mirrored component.
However, you can create a copy of a mirrored component and store it as a new locally-defined component. Local components always take precedence over mirored ones because the proxy server will check its own registry before it attempts to engage the remote server.
Therefore, to enable or disable a proxy tool, resource, or prompt, you should first create a local copy and add it to your own server. Here’s an example of how to do that for a tool:
FastMCPProxy
Class
Internally, FastMCP.as_proxy()
uses the FastMCPProxy
class. You generally don’t need to interact with this class directly, but it’s available if needed for advanced scenarios.
Direct Usage
Parameters
client
: [DEPRECATED] AClient
instance. Useclient_factory
instead for explicit session management.client_factory
: A callable that returns aClient
instance when called. This gives you full control over session creation and reuse strategies.
Explicit Session Management
FastMCPProxy
requires explicit session management - no automatic detection is performed. You must choose your session strategy:
For automatic session strategy selection, use the convenience method FastMCP.as_proxy()
instead.