Send MCP progress notifications from a slow tool

Day 4, 25 minutes · advanced

Goal of this lessonAdd a slow stocktake tool that sends MCP progress notifications, and read them in a small Python client while the tool runs.

Why it matters

Some tools take a while. A stocktake of every shelf, a big export, a slow outside service. If a tool says nothing for thirty seconds, the person waiting thinks it is broken. MCP has a simple fix: while the tool works, the server sends short progress messages, and the client shows them as a bar, a counter or a line of text.

In this lesson you learn what a notification is, how progress notifications work and how they travel over Streamable HTTP. You add a slow stocktake tool to Romy's HTTP server and write a small Python client that prints each progress report as it arrives. You also learn which kind of notification is deprecated, so you do not build on it. At the end you have seen four progress reports arrive one second apart, before the final result.

The words you need today

  • Notification: a JSON-RPC message without an id. Nobody answers it. A request always gets a response, a notification never does.
  • Progress token: a value the client puts in a request to say "send me progress for this one". It goes in the request's _meta field as progressToken.
  • Context: the object the Python SDK hands to a tool that asks for it, with helpers such as report_progress.
  • Callback: a function you give to a library, which the library calls when something happens.

How progress works

The progress page of the specification is short:

  1. The client adds a progressToken to its request. It must be a string or an integer, unique among the requests that are still running.
  2. The server may then send notifications/progress messages with that token, the progress so far, an optional total and an optional message.
  3. The progress value must go up with every notification, even when the total is unknown.
  4. Notifications must only refer to a request that is still running, and they stop when it is done.

The server may also choose to send no progress at all. In the Python SDK you call await ctx.report_progress(progress, total=..., message=...). The SDK's progress page adds two useful details. The client asks for progress per call, by passing progress_callback= to call_tool. And when the client did not ask, report_progress does nothing, so a tool can always report without checking.

How it travels over HTTP

On Streamable HTTP, the server can answer a request with an SSE stream instead of one JSON object. The specification says notifications on that stream must relate to the request it answers, and the final response comes last. So progress for a tool call arrives on the very same HTTP response as its result.

Two consequences:

  • The SDK's run page warns that with the option json_response=True, progress for a running call is dropped, because a single JSON body has no room for it.
  • On Streamable HTTP, the client cancels a request by closing its stream. The server should then stop the work.

Other notifications

Notifications are not only about progress. A server can tell clients that its list of tools, resources or prompts has changed, with messages such as notifications/tools/list_changed. In version 2026-07-28 a client that wants those opens a long-lived stream with a subscriptions/listen request. The Claude Code docs say that in an interactive session it fetches the new list when such a notification arrives, so you do not need to reconnect.

One kind of notification is on its way out. Logging through the protocol (notifications/message messages sent to the client) is deprecated as of 2026-07-28 by SEP-2577. The deprecation page says to log to standard error for stdio servers, and to use OpenTelemetry for observability. Romy's server already logs with Python's logging module, which is the right choice.

Progress in Claude Code

From the Claude Code MCP page: a tool call that is still running after two minutes moves to a background task, and its entry shows the latest progress the server reported. Progress does not extend a per-server time limit. But a call that sends neither a response nor a progress notification for five minutes on an HTTP server is stopped as idle. So for a long job, progress also shows that the tool is still alive.

The steps

  1. Add two imports to quillfeather_remote.py.
  2. Add the stocktake tool, which reports after each shelf.
  3. Start the server.
  4. Write the progress client and run it.
  5. Run it again without the callback and compare.
  6. Call the tool with the Inspector and see only the result.

Follow the steps below.

Today's actions

Ticks are not saved without an account

Do it in Claude API

Claude API

  1. Open quillfeather_remote.py and replace the line from mcp.server import MCPServer with these lines. They bring in asyncio for the pause and the Context object.
    import asyncio
    
    from mcp.server import MCPServer
    from mcp.server.mcpserver import Context
  2. Paste the stocktake tool above the line if __name__ == "__main__":. It counts four made-up shelves, one second each, and reports after every shelf.
    SHELVES = {"Classics": 14, "Children": 9, "Travel": 6, "Poetry": 4}
    
    
    @mcp.tool()
    async def stocktake(ctx: Context) -> str:
        """Count the books on every shelf of the shop. Takes a few seconds."""
        total = 0
        for done, (shelf, books) in enumerate(SHELVES.items(), start=1):
            await asyncio.sleep(1)  # pretend that counting a shelf takes a while
            total += books
            await ctx.report_progress(done, total=len(SHELVES), message=f"Counted {shelf}")
        return f"Stocktake done: {total} books on {len(SHELVES)} shelves."
  3. Start the server in its own terminal and leave it open.
    uv run quillfeather_remote.py
  4. In a second terminal, create progress_client.py in the quillfeather folder with this code. It connects, calls stocktake and prints every progress report.
    import anyio
    from mcp import Client
    
    
    async def show(progress: float, total: float | None, message: str | None) -> None:
        print(f"{message} ({progress}/{total})")
    
    
    async def main() -> None:
        async with Client("http://localhost:8000/mcp") as client:
            print("Protocol version:", client.protocol_version)
            result = await client.call_tool("stocktake", {}, progress_callback=show)
        print(result.content[0].text)
    
    
    anyio.run(main)
  5. Run the client. You should see the protocol version 2026-07-28, then Counted Classics (1.0/4.0) up to Counted Poetry (4.0/4.0), one per second, and then the result: 33 books on 4 shelves.
    uv run progress_client.py
  6. Now delete , progress_callback=show from the call_tool line and run the client again. The result is the same, but no progress lines appear: the server only reports when the client asks.
  7. Call the same tool with the Inspector CLI. You get the result only. Write in mcp-notes.txt who asks for progress and who sends it.
    npx @modelcontextprotocol/inspector --cli http://localhost:8000/mcp --transport http --method tools/call --tool-name stocktake

Note: A tool that reports progress must be async def, and ctx never shows up in the tool's input schema: the SDK fills it in. Restart the server after every change to the server file.

Checked on 4 December 2026 · Source: MCP Python SDK: Progress (opens in a new tab)

Create a free account to save your progress. Sign in or sign up