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.
Join us at the inaugural PyAI Conf in San Francisco on March 10th! Learn More
Handle progress notifications from long-running server operations.
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.
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
)
async with client:
result = await client.call_tool(
"long_running_task",
{"param": "value"},
progress_handler=my_progress_handler
)