Update clients on the progress of long-running operations through the MCP context.
Progress reporting allows MCP tools to notify clients about the progress of long-running operations. This enables clients to display progress indicators and provide better user experience during time-consuming tasks.
Use ctx.report_progress() to send progress updates to the client:
Copy
from fastmcp import FastMCP, Contextimport asynciomcp = FastMCP("ProgressDemo")@mcp.toolasync def process_items(items: list[str], ctx: Context) -> dict: """Process a list of items with progress updates.""" total = len(items) results = [] for i, item in enumerate(items): # Report progress as we process each item await ctx.report_progress(progress=i, total=total) # Simulate processing time await asyncio.sleep(0.1) results.append(item.upper()) # Report 100% completion await ctx.report_progress(progress=total, total=total) return {"processed": len(results), "results": results}