Step 6 of 7
Handle an error and try your own image
Read a tool error, recover and apply what you learned.
In this step you will handle an image operation that fails, and then change the input without changing anything about the task workflow.
1. Try an invalid image
With the MCP server still running, use the supplied CLI wrapper:
pnpm run client run --images broken.pngAfter the task ID, the last lines of the output include:
completed: Batch returned a tool error.
Cannot process broken.png: Input buffer contains unsupported image formatThe command exits with a nonzero status even though the task says completed.
The task itself finished normally. What failed was the tool, which returned a
result with isError: true. A task only shows failed when the request itself
errors, so your MCP client has to check the tool result as well as the task
status.
Run it again with valid input:
pnpm run client run --images landscape.png
pnpm run verify --outputYou should get three thumbnails and the line
Verified 3 WebP files against manifest.json. This is a new task, because
correcting the input does not rewrite the earlier attempt.
2. Validate the workflow with different input
Copy a JPEG or PNG of your own into fixtures/, for example my-photo.jpg. Then
use the CLI's --images option to process only that file, and its --widths
option to ask for widths of 320 and 640. Run the batch and look at its
manifest.
src/client.ts accepts comma-separated lists of filenames and widths. You should
get two WebP outputs. If your image is smaller than a requested width, the output
stays at the smaller size, because the resize function avoids enlarging images.
Give your file a new name, since pnpm run fixtures overwrites the supplied
sample names.
The README in the finished project has this command under “Try your own image.”
3. Verify the implementation
Stop terminal A with Ctrl+C, then run:
pnpm run typecheck
pnpm run testThe tests start their own local MCP server, and they should report no failures.
Your implementation now covers the core Tasks lifecycle:
- The MCP server saves a task before returning its handle, and keeps the task's state up to date.
- The MCP client declares support for the extension and handles both response shapes.
- Polling retrieves the final result, and reconnecting follows the same operation.
- The worker checks for cancellation, and the actual outcome is read from the task.
- Tool errors are handled separately from task execution errors.
To use the same approach for report generation or another long-running tool, replace the batch operation and its input and result schemas. The capability declarations, the task persistence and the lifecycle handling do the same jobs as before.
Beyond this local example
This MCP server uses a local file store and a single worker process. It has no authentication, no distributed queue, no automatic retries and no way to restart a job. Expired records and partial outputs also stay on disk. You would need to deal with all of these before adapting the server for remote use.
The supplied HTTP adapter only handles this example's JSON responses. It does not implement approval prompts or subscription notifications. When a task does need user input, the official input handling guide is the place to start, and the Tasks overview covers other use cases.
The finished project has all source files and tests.
Step 6
Ready to continue?
Mark this step complete when you have finished the checks above.
Checking saved progress…

