Step 5 of 7

Reconnect to a task and cancel work

Save a task ID, return to the same batch and request cancellation.

In this step you will check that a task keeps running after the MCP client that started it has gone, and then you will cancel a task while its batch is still running. These are two different actions, and they end differently:

Two flows side by side. Detach: the MCP client saves the taskId and exits without sending a message; the server keeps working and finishes all 18 images; a later tasks/get from a new connection returns completed with the same batch and result. Cancel: the MCP client sends tasks/cancel and the server replies with an empty acknowledgement; the worker checks for cancellation between images, so the current image may finish; tasks/get then reads the actual outcome, cancelled, or completed if the batch had already finished.

The project you copied includes a command-line wrapper, src/client.ts, with run, watch and cancel commands. It uses the same connection helper and polling loop that you just wrote, and it saves task IDs in output/last-task.json.

1. Leave a task running

Keep terminal A running with pnpm run server --demo-delay-ms 1000. In terminal B:

Shell
pnpm run client run --detach

Expect:

text
Task ID: <task-id>
Detached. Run: pnpm run client watch last

The command saves the task ID and exits without cancelling anything. You can close terminal B if you like, because the MCP server in terminal A keeps processing the images.

2. Reconnect using the saved ID

Reopen a terminal in the same project folder and run:

Shell
pnpm run client watch last
pnpm run verify --output

Eventually you should see completed: All thumbnails are ready., followed by Created 18 thumbnails. and a successful verification. The batch may already be finished by the time you reconnect. You can also run pnpm run client watch <task-id>, replacing the placeholder with the ID that was printed.

The watch command sends tasks/get, and it does not call create_thumbnails again. Check that its output folder is the one from the same batch. The stored MCP server URL and the task ID together identify which work you are picking up again, and the official recovery guide uses the same idea when it hands tasks from one connection to another.

If the task is reported as unknown or expired, check the ID, the URL and the project folder. This example keeps tasks for one hour. Also note that restarting the MCP server marks any unfinished batches as failed, because a saved task record on its own does not restart an interrupted image job.

3. Request cancellation

Start a new batch with the delay enabled, and ask for it to be cancelled quickly:

Shell
pnpm run client run --detach
pnpm run client cancel last

The first message acknowledges your request:

text
Cancellation requested. Checking the actual outcome…

When the worker stops, you will see:

text
cancelled: Cancelled; completed files remain in output.

The wrapper calls connection.cancelTask(id) and then runs your watchTask() loop. The worker only checks for cancellation between Sharp operations, so the operation in progress may finish first. If the batch had already finished, you may see completed instead, so try again with the delay enabled. Any files created before the cancellation stay where they are.

Closing an MCP client and cancelling a task are different actions, and the official lifecycle API keeps detaching and cancelling separate as well.

Checkpoint: you retrieved the same batch after the MCP client had exited, and you saw the task's final state after asking for cancellation. The acknowledgement on its own is not proof that processing stopped.

Step 5

Ready to continue?

Mark this step complete when you have finished the checks above.

Checking saved progress…

Find it across ATM

Search All Things MCP

ESC

Search the practical layer around the protocol.

Browse Guides Read the Blog

Your ATM account

Sign in or create an account

Continue with GitHub. If you’re new, your ATM account will be created automatically.