Spaces:
Running
Running
Jeremiah Lowin commited on
Commit ·
a266504
1
Parent(s): f7b7ab6
Update docs
Browse files- docs/clients/client.mdx +103 -14
- docs/clients/logging.mdx +1 -1
- docs/clients/progress.mdx +1 -1
- docs/clients/prompts.mdx +1 -1
- docs/clients/resources.mdx +1 -1
- docs/clients/roots.mdx +1 -1
- docs/clients/sampling.mdx +1 -1
- docs/clients/tools.mdx +1 -1
- docs/docs.json +1 -1
- docs/servers/{fastmcp.mdx → server.mdx} +2 -2
docs/clients/client.mdx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
sidebarTitle: Overview
|
| 4 |
-
description:
|
| 5 |
icon: user-robot
|
| 6 |
---
|
| 7 |
|
|
@@ -9,20 +9,24 @@ import { VersionBadge } from '/snippets/version-badge.mdx'
|
|
| 9 |
|
| 10 |
<VersionBadge version="2.0.0" />
|
| 11 |
|
| 12 |
-
The `fastmcp.Client`
|
|
|
|
|
|
|
| 13 |
|
| 14 |
- **Testing MCP servers** during development
|
| 15 |
-
- **Building deterministic applications** that need reliable MCP interactions
|
| 16 |
- **Creating the foundation for agentic or LLM-based clients** with structured, type-safe operations
|
| 17 |
|
|
|
|
|
|
|
| 18 |
|
| 19 |
<Note>
|
| 20 |
This is not an agentic client - it requires explicit function calls and provides direct control over all MCP operations. Use it as a building block for higher-level systems.
|
| 21 |
</Note>
|
| 22 |
|
| 23 |
-
##
|
| 24 |
|
| 25 |
-
|
| 26 |
|
| 27 |
```python
|
| 28 |
import asyncio
|
|
@@ -157,16 +161,57 @@ async def example():
|
|
| 157 |
print(f"Connected: {client.is_connected()}")
|
| 158 |
```
|
| 159 |
|
| 160 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
|
| 162 |
-
|
| 163 |
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
|
| 171 |
### Server Connectivity
|
| 172 |
|
|
@@ -178,6 +223,50 @@ async with client:
|
|
| 178 |
print("Server is reachable")
|
| 179 |
```
|
| 180 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
## Next Steps
|
| 182 |
|
| 183 |
Explore the detailed documentation for each operation type:
|
|
|
|
| 1 |
---
|
| 2 |
+
title: The FastMCP Client
|
| 3 |
sidebarTitle: Overview
|
| 4 |
+
description: Programmatic client for interacting with MCP servers through a well-typed, Pythonic interface.
|
| 5 |
icon: user-robot
|
| 6 |
---
|
| 7 |
|
|
|
|
| 9 |
|
| 10 |
<VersionBadge version="2.0.0" />
|
| 11 |
|
| 12 |
+
The central piece of MCP client applications is the `fastmcp.Client` class. This class provides a **programmatic interface** for interacting with any Model Context Protocol (MCP) server, handling protocol details and connection management automatically.
|
| 13 |
+
|
| 14 |
+
The FastMCP Client is designed for deterministic, controlled interactions rather than autonomous behavior, making it ideal for:
|
| 15 |
|
| 16 |
- **Testing MCP servers** during development
|
| 17 |
+
- **Building deterministic applications** that need reliable MCP interactions
|
| 18 |
- **Creating the foundation for agentic or LLM-based clients** with structured, type-safe operations
|
| 19 |
|
| 20 |
+
All client operations require using the `async with` context manager for proper connection lifecycle management.
|
| 21 |
+
|
| 22 |
|
| 23 |
<Note>
|
| 24 |
This is not an agentic client - it requires explicit function calls and provides direct control over all MCP operations. Use it as a building block for higher-level systems.
|
| 25 |
</Note>
|
| 26 |
|
| 27 |
+
## Creating a Client
|
| 28 |
|
| 29 |
+
Creating a client is straightforward. You provide a server source and the client automatically infers the appropriate transport mechanism.
|
| 30 |
|
| 31 |
```python
|
| 32 |
import asyncio
|
|
|
|
| 161 |
print(f"Connected: {client.is_connected()}")
|
| 162 |
```
|
| 163 |
|
| 164 |
+
## Operations
|
| 165 |
+
|
| 166 |
+
FastMCP clients can interact with several types of server components:
|
| 167 |
+
|
| 168 |
+
### Tools
|
| 169 |
+
|
| 170 |
+
Tools are server-side functions that the client can execute with arguments.
|
| 171 |
+
|
| 172 |
+
```python
|
| 173 |
+
async with client:
|
| 174 |
+
# List available tools
|
| 175 |
+
tools = await client.list_tools()
|
| 176 |
+
|
| 177 |
+
# Execute a tool
|
| 178 |
+
result = await client.call_tool("multiply", {"a": 5, "b": 3})
|
| 179 |
+
print(result[0].text) # "15"
|
| 180 |
+
```
|
| 181 |
+
|
| 182 |
+
See [Tools](/clients/tools) for detailed documentation.
|
| 183 |
+
|
| 184 |
+
### Resources
|
| 185 |
+
|
| 186 |
+
Resources are data sources that the client can read, either static or templated.
|
| 187 |
+
|
| 188 |
+
```python
|
| 189 |
+
async with client:
|
| 190 |
+
# List available resources
|
| 191 |
+
resources = await client.list_resources()
|
| 192 |
+
|
| 193 |
+
# Read a resource
|
| 194 |
+
content = await client.read_resource("file:///config/settings.json")
|
| 195 |
+
print(content[0].text)
|
| 196 |
+
```
|
| 197 |
+
|
| 198 |
+
See [Resources](/clients/resources) for detailed documentation.
|
| 199 |
|
| 200 |
+
### Prompts
|
| 201 |
|
| 202 |
+
Prompts are reusable message templates that can accept arguments.
|
| 203 |
+
|
| 204 |
+
```python
|
| 205 |
+
async with client:
|
| 206 |
+
# List available prompts
|
| 207 |
+
prompts = await client.list_prompts()
|
| 208 |
+
|
| 209 |
+
# Get a rendered prompt
|
| 210 |
+
messages = await client.get_prompt("analyze_data", {"data": [1, 2, 3]})
|
| 211 |
+
print(messages.messages)
|
| 212 |
+
```
|
| 213 |
+
|
| 214 |
+
See [Prompts](/clients/prompts) for detailed documentation.
|
| 215 |
|
| 216 |
### Server Connectivity
|
| 217 |
|
|
|
|
| 223 |
print("Server is reachable")
|
| 224 |
```
|
| 225 |
|
| 226 |
+
## Client Configuration
|
| 227 |
+
|
| 228 |
+
Clients can be configured with additional handlers and settings for specialized use cases.
|
| 229 |
+
|
| 230 |
+
### Callback Handlers
|
| 231 |
+
|
| 232 |
+
The client supports several callback handlers for advanced server interactions:
|
| 233 |
+
|
| 234 |
+
```python
|
| 235 |
+
from fastmcp import Client
|
| 236 |
+
from fastmcp.client.logging import LogMessage
|
| 237 |
+
|
| 238 |
+
async def log_handler(message: LogMessage):
|
| 239 |
+
print(f"Server log: {message.data}")
|
| 240 |
+
|
| 241 |
+
async def progress_handler(progress: float, total: float | None, message: str | None):
|
| 242 |
+
print(f"Progress: {progress}/{total} - {message}")
|
| 243 |
+
|
| 244 |
+
async def sampling_handler(messages, params, context):
|
| 245 |
+
# Integrate with your LLM service here
|
| 246 |
+
return "Generated response"
|
| 247 |
+
|
| 248 |
+
client = Client(
|
| 249 |
+
"my_mcp_server.py",
|
| 250 |
+
log_handler=log_handler,
|
| 251 |
+
progress_handler=progress_handler,
|
| 252 |
+
sampling_handler=sampling_handler,
|
| 253 |
+
timeout=30.0
|
| 254 |
+
)
|
| 255 |
+
```
|
| 256 |
+
|
| 257 |
+
The `Client` constructor accepts several configuration options:
|
| 258 |
+
|
| 259 |
+
- `transport`: Transport instance or source for automatic inference
|
| 260 |
+
- `log_handler`: Handle server log messages
|
| 261 |
+
- `progress_handler`: Monitor long-running operations
|
| 262 |
+
- `sampling_handler`: Respond to server LLM requests
|
| 263 |
+
- `roots`: Provide local context to servers
|
| 264 |
+
- `timeout`: Default timeout for requests (in seconds)
|
| 265 |
+
|
| 266 |
+
### Transport Configuration
|
| 267 |
+
|
| 268 |
+
For detailed transport configuration (headers, authentication, environment variables), see the [Transports](/clients/transports) documentation.
|
| 269 |
+
|
| 270 |
## Next Steps
|
| 271 |
|
| 272 |
Explore the detailed documentation for each operation type:
|
docs/clients/logging.mdx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
---
|
| 2 |
title: Server Logging
|
| 3 |
sidebarTitle: Logging
|
| 4 |
-
description:
|
| 5 |
icon: receipt
|
| 6 |
---
|
| 7 |
|
|
|
|
| 1 |
---
|
| 2 |
title: Server Logging
|
| 3 |
sidebarTitle: Logging
|
| 4 |
+
description: Receive and handle log messages from MCP servers.
|
| 5 |
icon: receipt
|
| 6 |
---
|
| 7 |
|
docs/clients/progress.mdx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
---
|
| 2 |
title: Progress Monitoring
|
| 3 |
sidebarTitle: Progress
|
| 4 |
-
description:
|
| 5 |
icon: bars-progress
|
| 6 |
---
|
| 7 |
|
|
|
|
| 1 |
---
|
| 2 |
title: Progress Monitoring
|
| 3 |
sidebarTitle: Progress
|
| 4 |
+
description: Handle progress notifications from long-running server operations.
|
| 5 |
icon: bars-progress
|
| 6 |
---
|
| 7 |
|
docs/clients/prompts.mdx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
---
|
| 2 |
title: Prompts
|
| 3 |
sidebarTitle: Prompts
|
| 4 |
-
description:
|
| 5 |
icon: message-lines
|
| 6 |
---
|
| 7 |
|
|
|
|
| 1 |
---
|
| 2 |
title: Prompts
|
| 3 |
sidebarTitle: Prompts
|
| 4 |
+
description: Use server-side prompt templates with automatic argument serialization.
|
| 5 |
icon: message-lines
|
| 6 |
---
|
| 7 |
|
docs/clients/resources.mdx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
---
|
| 2 |
title: Resource Operations
|
| 3 |
sidebarTitle: Resources
|
| 4 |
-
description:
|
| 5 |
icon: folder-open
|
| 6 |
---
|
| 7 |
|
|
|
|
| 1 |
---
|
| 2 |
title: Resource Operations
|
| 3 |
sidebarTitle: Resources
|
| 4 |
+
description: Access static and templated resources from MCP servers.
|
| 5 |
icon: folder-open
|
| 6 |
---
|
| 7 |
|
docs/clients/roots.mdx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
---
|
| 2 |
title: Client Roots
|
| 3 |
sidebarTitle: Roots
|
| 4 |
-
description:
|
| 5 |
icon: folder-tree
|
| 6 |
---
|
| 7 |
|
|
|
|
| 1 |
---
|
| 2 |
title: Client Roots
|
| 3 |
sidebarTitle: Roots
|
| 4 |
+
description: Provide local context and resource boundaries to MCP servers.
|
| 5 |
icon: folder-tree
|
| 6 |
---
|
| 7 |
|
docs/clients/sampling.mdx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
---
|
| 2 |
title: LLM Sampling
|
| 3 |
sidebarTitle: Sampling
|
| 4 |
-
description:
|
| 5 |
icon: robot
|
| 6 |
---
|
| 7 |
|
|
|
|
| 1 |
---
|
| 2 |
title: LLM Sampling
|
| 3 |
sidebarTitle: Sampling
|
| 4 |
+
description: Handle server-initiated LLM sampling requests.
|
| 5 |
icon: robot
|
| 6 |
---
|
| 7 |
|
docs/clients/tools.mdx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
---
|
| 2 |
title: Tool Operations
|
| 3 |
sidebarTitle: Tools
|
| 4 |
-
description:
|
| 5 |
icon: wrench
|
| 6 |
---
|
| 7 |
|
|
|
|
| 1 |
---
|
| 2 |
title: Tool Operations
|
| 3 |
sidebarTitle: Tools
|
| 4 |
+
description: Discover and execute server-side tools with the FastMCP client.
|
| 5 |
icon: wrench
|
| 6 |
---
|
| 7 |
|
docs/docs.json
CHANGED
|
@@ -63,7 +63,7 @@
|
|
| 63 |
{
|
| 64 |
"group": "Servers",
|
| 65 |
"pages": [
|
| 66 |
-
"servers/
|
| 67 |
{
|
| 68 |
"group": "Core Components",
|
| 69 |
"icon": "toolbox",
|
|
|
|
| 63 |
{
|
| 64 |
"group": "Servers",
|
| 65 |
"pages": [
|
| 66 |
+
"servers/server",
|
| 67 |
{
|
| 68 |
"group": "Core Components",
|
| 69 |
"icon": "toolbox",
|
docs/servers/{fastmcp.mdx → server.mdx}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
---
|
| 2 |
title: The FastMCP Server
|
| 3 |
-
sidebarTitle:
|
| 4 |
-
description:
|
| 5 |
icon: server
|
| 6 |
---
|
| 7 |
|
|
|
|
| 1 |
---
|
| 2 |
title: The FastMCP Server
|
| 3 |
+
sidebarTitle: Overview
|
| 4 |
+
description: The core FastMCP server class for building MCP applications with tools, resources, and prompts.
|
| 5 |
icon: server
|
| 6 |
---
|
| 7 |
|