AI Hints
Home›MCP Tutorial›Elicitation and Progress
MCP · Lesson 27 of 120

Progress

Long-running tools.

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

Some tools take a while, like rebuilding a search index. Progress notifications tell the client how far along the tool is, so the host can show a progress bar.

Progress
From the video: Progress
  • Slow tools
  • Progress updates
  • A progress bar

Reporting progress

The tool takes a context, and calls report progress after each step, with the step, the total, and a message. The client passes a progress callback, which prints each update. Run it. Three updates arrive, then the result.

progress.pypython
import asyncio
from mcp import Client
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, 4):
        await asyncio.sleep(0.2)
        await ctx.report_progress(step, 3, f"indexed part {step}")
    return "index rebuilt"

async def show(progress, total, message): print(f"{progress:.0f}/{total:.0f} {message}")
async def main():
    async with Client(mcp) as client:
        print((await client.call_tool("reindex", {}, progress_callback=show)).content[0].text)
asyncio.run(main())
Output
1/3 indexed part 1
2/3 indexed part 2
3/3 indexed part 3
index rebuilt

Progress tips

Report progress for anything that takes more than a second or two. Include a total when you know it. Keep messages short. The client decides how to show them.

keyvalue
Whenover a second or two
Totalif you know it
Messageshort
Clientshows it

Summary

Long tools report progress with the context, and clients show it. Next, tool design tips.

Key takeaways
  • ctx.report_progress
  • progress_callback
  • Show a bar
Next up: Tool Design Tips — names, inputs, outputs