Feedback

Chat Icon

Practical MCP with FastMCP & LangChain

Engineering the Agentic Experience

Building a Functional MCP Client
54%

Progress Handler

The progress handler is responsible for receiving progress notifications from the server and using them to update the user on the status of long-running operations. This is mainly used for tools that take a significant amount of time to complete.

To report progress from the server, you use the report_progress() method on the context object. Here's an example of how that might look inside a tool (server side code):

from fastmcp import Context

async def some_long_running_task(ctx: Context):
    # ... do some work ...
    # report progress
    await ctx.report_progress(progress=<current>, total=<total>)
    # ... do more work ...
    # report more progress
    await ctx.report_progress(progress=<current>, total=<total>)
    # ... finish up ...

The client, if you want to handle these progress updates, needs to implement a handler that will receive these notifications and do something with them. In our case, we're simply going to print them in the terminal.

Here is our code:

cat > $HOME/workspace/puppy_guide/client/handlers/progress.py << 'EOF'
async def progress_handler(
    progress: float,  # current progress value sent by the server
    total: float |

Practical MCP with FastMCP & LangChain

Engineering the Agentic Experience

Enroll now to unlock current content and receive all future updates for free. Your purchase supports the author and fuels the creation of more exciting content. Act fast, as the price will rise as the course nears completion!