AI Hints
Home›MCP Tutorial›Client Callbacks and Practice
MCP · Lesson 62 of 120

Progress on the Client

Callbacks.

⏱ 2 min read▶ Video at 55:15🎓 Free
Watch this lesson in the MCP courseWatch on YouTube ↗Full MCP course

A host can show a progress bar while a long tool runs. The client passes a progress callback with the call, and the server's updates arrive there.

Progress on the Client
From the video: Progress on the Client
  • Long tools
  • Progress callback
  • Show a bar

A text progress bar

Bar turns progress into a row of blocks. We pass it as the progress callback when calling reindex. Run it. The bar fills up, step by step, then the result arrives.

progress_bar.pypython
import asyncio
from mcp import Client
from progress_server import mcp

async def bar(progress, total, message):
    filled = int(progress / total * 10)
    print("[" + "#" * filled + "." * (10 - filled) + "]", message)

async def main():
    async with Client(mcp) as client:
        r = await client.call_tool("reindex", {}, progress_callback=bar)
        print(r.content[0].text)

asyncio.run(main())
Output
[##........] part 1 of 4
[#####.....] part 2 of 4
[#######...] part 3 of 4
[##########] part 4 of 4
index rebuilt
Also uses progress_server.py
import asyncio
from mcp.server.mcpserver import MCPServer, Context

mcp = MCPServer("shop")

@mcp.tool()
async def reindex(ctx: Context) -> str:
    """Rebuild the product search index."""
    for step in range(1, 5):
        await asyncio.sleep(0.1)
        await ctx.report_progress(step, 4, f"part {step} of 4")
    return "index rebuilt"

Summary

Pass a progress callback with the call, and show each update as it arrives. Next, practice with a chat client.

Key takeaways
  • progress_callback
  • Fill a bar
  • Then the result
Next up: Practice: A Chat Client — ask the shop