You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `fastmcp.Client` provides a high-level, asynchronous interface for interacting with any Model Context Protocol (MCP) server, whether it's built with FastMCP or another implementation. It simplifies communication by handling protocol details and connection management.
Copy file name to clipboardExpand all lines: docs/clients/transports.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ icon: link
7
7
8
8
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.
9
9
10
-
While the `Client` often infers the correct transport automatically (see [Client Overview](/clients/overview#transport-inference)), you can also instantiate transports explicitly for more control.
10
+
While the `Client` often infers the correct transport automatically (see [Client Overview](/clients/client#transport-inference)), you can also instantiate transports explicitly for more control.
As your MCP applications grow, you might want to organize your tools, resources, and prompts into logical modules or reuse existing server components. FastMCP supports composition through two methods:
9
12
@@ -17,13 +20,31 @@ As your MCP applications grow, you might want to organize your tools, resources,
17
20
-**Teamwork**: Different teams can work on separate FastMCP servers that are later combined.
18
21
-**Organization**: Keep related functionality grouped together logically.
19
22
20
-
## Importing Subservers (Static Composition)
23
+
### Importing vs Mounting
24
+
25
+
The choice of importing or mounting depends on your use case and requirements. In general, importing is best for simpler cases because it copies the imported server's components into the main server, treating them as native integrations. Mounting is best for more complex cases where you need to delegate requests to the subserver at runtime.
FastMCP supports [MCP proxying](/patterns/proxy), which allows you to mirror a local or remote server in a local FastMCP instance. Proxies are fully compatible with both importing and mounting.
40
+
41
+
42
+
## Importing (Static Composition)
21
43
22
44
The `import_server()` method copies all components (tools, resources, templates, prompts) from one `FastMCP` instance (the *subserver*) into another (the *main server*). A `prefix` is added to avoid naming conflicts.
23
45
24
46
```python
25
47
from fastmcp import FastMCP
26
-
from typing importdict, list
27
48
import asyncio
28
49
29
50
# --- Define Subservers ---
@@ -114,7 +135,7 @@ await main_mcp.import_server(
114
135
Be cautious when choosing separators. Some MCP clients (like Claude Desktop) might have restrictions on characters allowed in tool names (e.g., `/` might not be supported). The defaults (`_` for names, `+` for URIs) are generally safe.
115
136
</Warning>
116
137
117
-
## Mounting Subservers (Live Linking)
138
+
## Mounting (Live Linking)
118
139
119
140
The `mount()` method creates a **live link** between the `main_mcp` server and the `subserver`. Instead of copying components, requests for components matching the `prefix` are **delegated** to the `subserver` at runtime.
120
141
@@ -186,61 +207,19 @@ main_mcp.mount(
186
207
)
187
208
```
188
209
189
-
## Comparing Import and Mount
190
-
191
-
| Feature |`import_server`|`mount`|
192
-
|---------|----------------|---------|
193
-
|**Synchronicity**| Async (must be awaited) | Sync |
194
-
|**Composition Type**| One-time copy (static) | Live link (dynamic) |
195
-
|**Updates**| Changes to subserver NOT reflected | Changes to subserver immediately reflected |
196
-
|**Lifespan**| Not managed | Automatically managed |
FastMCP can automatically generate an MCP server from an OpenAPI specification. Users only need to provide an OpenAPI specification (3.0 or 3.1) and an API client.
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.from_client()` class method.
When defining FastMCP [tools](/servers/tools), your functions might need to interact with the underlying MCP session or access server capabilities. FastMCP provides the `Context` object for this purpose.
9
10
@@ -174,6 +175,8 @@ The returned content is typically accessed via `content_list[0].content` and can
174
175
175
176
### LLM Sampling
176
177
178
+
<VersionBadgeversion="2.0.0" />
179
+
177
180
Request the client's LLM to generate text based on provided messages. This is useful when your tool needs to leverage the LLM's capabilities to process data or generate responses.
0 commit comments