> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Demo Messages and Schemas Part 2

> Shows how MCP servers send asynchronous progress notifications to clients during long-running tool executions, with examples, token registration, and server side code.

Welcome back — this lesson extends the previous demonstration by showing how MCP servers can send asynchronous progress and notification messages back to clients during long-running or multi-step tool executions.

Recap: MCP Inspector acts as a client. In the MCP model every AI application has a host, and a host can contain one or many clients. Each client connects to exactly one server — that is how an MCP server is modeled.

Running the demo server

* Start the shipment-tracker server used in this lesson:

```bash theme={null}
../.venv/bin/python server.py
```

If the server is running, you can call its exposed tools (for example, the "Get Shipment Status" tool visible in the browser tools UI). Example tool response when requesting shipment `PL-4417`:

```json theme={null}
{
  "ref": "PL-4417",
  "status": "in_transit",
  "location": "Rotterdam distribution center",
  "estimatedDelivery": "2026-09-14",
  "lastScan": "2026-09-10T06:12:00Z"
}
```

Example server console output:

```text theme={null}
14:19:19 shipment-tracker ready on stdio
14:19:52 [shipment-tracker] lookup PL-4417
```

Why server progress/notifications matter

* Simple requests may complete instantly, but many useful server tasks involve multiple steps or take significant time. In these cases it’s helpful for the server to notify the client about progress (e.g., "started lookup", "processing records", "finished").
* MCP servers can send server-to-client notifications using the server context object (`ctx`) and its `report_progress` method.

Server-side example: reporting progress
Below is a compact server tool implementation that calls `ctx.report_progress` twice to indicate two steps: lookup started and lookup completed.

```python theme={null}
# server.py
from typing import Annotated, Optional
import sys

from pydantic import Field
from mcp.server import MCPServer
from mcp.server.mcpserver import Context
from mcp.server.mcpserver.exceptions import ToolError

from mcpa_demo import Shipment, find_shipment  # demo helper module

server = MCPServer(name="shipment-tracker", version="1.0.0")

@server.tool()
async def get_shipment_status(
    ref: Annotated[str, Field(description="Shipment reference")],
    ctx: Context,
) -> Shipment:
    # Step 1 of 2: notify client that lookup has started
    await ctx.report_progress(1, total=2, message=f"Looking up {ref}")
    print(f"[shipment-tracker] lookup {ref}", file=sys.stderr)

    # Do the lookup (may be blocking or awaitable depending on your implementation)
    shipment: Optional[Shipment] = find_shipment(ref)

    # Step 2 of 2: notify client whether it was found
    await ctx.report_progress(2, total=2, message="Found" if shipment else "Not found")

    if shipment is None:
        raise ToolError(
            f"No shipment found with reference {ref}. "
            "This demo knows about PL-4417, PL-4418 and PL-9002."
        )

    return shipment

if __name__ == "__main__":
    print("shipment-tracker ready on stdio", file=sys.stderr)
    server.run("stdio")
```

How progress reporting works

* Call: `await ctx.report_progress(progress, total=..., message="...")`.
* Each call sends a server-to-client notification containing:
  * `progress` — current progress value (you determine semantics: step index, percent, etc.).
  * `total` — total number of steps or maximum progress value.
  * `message` — a human-readable description of what’s happening.
* In the example above, we used `1` and `2` to express “first of two steps” and “second of two steps”.

Progress notification fields (summary)

| Field | Type | Description |
| - | - | - |
| `progressToken` | `string` | Token that associates notifications with a specific server instance (from `mcp.json` metadata) |
| `progress` | `number` | Current progress value (semantic meaning chosen by server) |
| `total` | `number` | Total value or number of steps |
| `message` | `string` | Human-readable status message |

Registering a progress token in mcp.json

* To allow clients to correlate progress notifications with the right server, include a `progressToken` in your server entry within `mcp.json`. This metadata token is attached to the server configuration and the client will see it in notifications.

Example `mcp.json` entry:

```json theme={null}
{
  "mcpServers": {
    "shipment-tracker": {
      "type": "stdio",
      "command": "../.venv/bin/python",
      "args": [
        "server.py"
      ],
      "metadata": {
        "progressToken": "demo-1"
      },
      "protocolEra": "modern"
    }
  }
}
```

Representative notification sequence the client receives

* When the client spawns or connects to the configured server, progress notifications will include the token so the client can match notifications to the correct server/tool invocation.

Progress start notification:

```json theme={null}
{
  "progressToken": "demo-1",
  "progress": 1,
  "total": 2,
  "message": "Looking up PL-4417"
}
```

Progress completion notification:

```json theme={null}
{
  "progressToken": "demo-1",
  "progress": 2,
  "total": 2,
  "message": "Found"
}
```

Final tool response (the shipment record):

```json theme={null}
{
  "ref": "PL-4417",
  "status": "in_transit",
  "location": "Rotterdam distribution center",
  "estimatedDelivery": "2026-09-14",
  "lastScan": "2026-09-10T06:12:00Z"
}
```

Key points

* The server sends asynchronous `server-to-client` progress notifications while the client initiates the `tool/call`.
* Progress notifications and the final tool response are independent messages; use `progressToken` to associate them with the correct server invocation.
* You control the meaning of `progress` and `total` (step indexes, percentage, or custom semantics).

The server can only send notifications to the client (e.g., progress updates). The client is the only entity that can initiate tool calls. Use `metadata.progressToken` in `mcp.json` so the client can correlate server notifications with the corresponding server instance.

Links and references

* [MCP Protocol Overview](https://example.com/mcp-protocol) (replace with your MCP docs)
* [MCP Server API — report\_progress](https://example.com/mcp-server-report-progress)
* [Python async patterns](https://docs.python.org/3/library/asyncio.html)

> [card] [Watch Video](https://learn.kodekloud.com/user/courses/model-context-protocol-associate-mcpa-certification/module/282d97e2-04f7-4beb-8301-695ecb3f3f99/lesson/f6d27c11-0f4e-4a68-aeec-b25dd1d3a8ec)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.