mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-20 04:24:17 +02:00
* Archive v3 docs under /v3 and publish v4 as the primary version * Label primary docs version v4.0.0 (alpha 1) * Add What's New in v4 page; fix upgrade-guide phrasing; point banner at What's New * Rewrite What's New around v4's new capabilities, not the sampling deprecation * Lead What's New with the SDK v2 engine swap and the SEPs it brings * State ships now (link Session State); tasks arrive next alpha * Exclude docs/v3 frozen snapshots from doc-example import validation
67 lines
1.5 KiB
Text
67 lines
1.5 KiB
Text
---
|
|
title: Progress Monitoring
|
|
sidebarTitle: Progress
|
|
description: Handle progress notifications from long-running server operations.
|
|
icon: bars-progress
|
|
---
|
|
|
|
import { VersionBadge } from '/snippets/version-badge.mdx'
|
|
|
|
<VersionBadge version="2.3.5" />
|
|
|
|
Use this when you need to track progress of long-running operations.
|
|
|
|
MCP servers can report progress during operations. The client receives these updates through a progress handler.
|
|
|
|
## Progress Handler
|
|
|
|
Set a handler when creating the client:
|
|
|
|
```python
|
|
from fastmcp import Client
|
|
|
|
async def progress_handler(
|
|
progress: float,
|
|
total: float | None,
|
|
message: str | None
|
|
) -> None:
|
|
if total is not None:
|
|
percentage = (progress / total) * 100
|
|
print(f"Progress: {percentage:.1f}% - {message or ''}")
|
|
else:
|
|
print(f"Progress: {progress} - {message or ''}")
|
|
|
|
client = Client(
|
|
"my_mcp_server.py",
|
|
progress_handler=progress_handler
|
|
)
|
|
```
|
|
|
|
The handler receives three parameters:
|
|
|
|
<Card icon="code" title="Handler Parameters">
|
|
<ResponseField name="progress" type="float">
|
|
Current progress value
|
|
</ResponseField>
|
|
|
|
<ResponseField name="total" type="float | None">
|
|
Expected total value (may be None if unknown)
|
|
</ResponseField>
|
|
|
|
<ResponseField name="message" type="str | None">
|
|
Optional status message
|
|
</ResponseField>
|
|
</Card>
|
|
|
|
## Per-Call Handler
|
|
|
|
Override the client-level handler for specific tool calls:
|
|
|
|
```python
|
|
async with client:
|
|
result = await client.call_tool(
|
|
"long_running_task",
|
|
{"param": "value"},
|
|
progress_handler=my_progress_handler
|
|
)
|
|
```
|