Step 1 of 7
Understand how MCP Tasks work
This guide step explains why a long tool call needs a task, what a task is, and how an MCP client follows one to its result.
A normal tool call is quick: the client asks, the server answers, and that is
the end of it. Some tool calls are not quick. This step looks at what goes wrong
when a call takes a long time, and how the MCP Tasks extension fixes it. You
won't write any code yet. The goal is to understand what a task is and which
messages carry one from tools/call to its result, because every later step
builds one part of that picture.
Why a long tool call needs a task
An ordinary tools/call is a single request with a single response. The MCP
client sends the request and waits until the MCP server sends back the tool
result. When the tool is something like a database lookup that takes a few
milliseconds, that works fine.
Now imagine a tool that takes much longer. The one you will build in this guide resizes images: you give it six images, and it produces three sizes of each, so eighteen thumbnails in total, made one after another. A CI run, or a step that waits for a person to approve something, would behave the same way. If the client has to hold one request open for that whole time, three things go wrong:
| Problem | What happens with one long request |
|---|---|
| Timeouts | Clients and intermediaries close requests that stay open too long. |
| Lost results | If the MCP client exits or the connection drops, the result is lost. |
| No visibility | The MCP client can't see progress or ask the work to stop. |
A task separates starting the work from collecting its result. Instead of making the client wait, the MCP server answers the call straight away with a task handle. The MCP client can then check on the task with short requests whenever it likes.
2. What a task is
A task is a record that the MCP server keeps for one tools/call. The record
has an unguessable ID, a status and a status message, and once the work is
finished it also holds the result. The MCP client never sees the work itself,
only this record.
When the MCP server decides to run a call as a task, it returns a task handle instead of the tool result. The server you will build returns handles like the one below, which is annotated to explain each field:
{
"resultType": "task", // "this is a task handle, not the tool result"
"taskId": "a1288bf1-305f-46ac-a49c-5c02a2828bc7", // keep this to check back
"status": "working",
"statusMessage": "Starting the image batch.", // human-readable progress
"createdAt": "2026-10-27T10:41:57.590Z",
"lastUpdatedAt": "2026-10-27T10:41:57.590Z",
"ttlMs": 3600000, // the server may discard the task after one hour
"pollIntervalMs": 500, // "please check no more than every 500 ms"
}ttlMs and pollIntervalMs are values that this example's server picked. They
are not protocol defaults, and a server may change either one while a task is
running.
3. Follow one task from call to result
The diagram below traces the exchange you will implement. It also shows the worker and task store that this example's MCP server uses behind the scenes.
Four details in this flow matter when you write the code:
- The server saves the task before it returns the handle (steps 2–3). The
specification requires this, so the MCP client's first
tasks/getalways finds the task. - The work runs outside the request (step 4). By then the
tools/callresponse has already been sent, so a worker or job queue has to run the batch. - The task ID is how you resume (step 6). If you called the tool again, you
would start a second batch. Calling
tasks/getwith the saved ID follows the original one instead. - The final
tasks/getcarries the result (step 7). Itsresultfield holds exactly what an ordinarytools/callwould have returned, so there is no separate "fetch result" request.
The extension adds three methods to the tools/call you already know:
| Method | The MCP client sends it to | In this guide |
|---|---|---|
tools/call | Start the work. The response is a task handle or an ordinary result. | Steps 3–4 |
tasks/get | Read the current status and, once finished, the result. | Steps 3–6 |
tasks/cancel | Ask the MCP server to stop. The reply is an empty acknowledgement. | Step 5 |
tasks/update | Answer a request the task is waiting on, such as an approval. | Explained, not built |
Over Streamable HTTP, the MCP client also sets the Mcp-Name header to the
taskId on every tasks/* request. A load balancer can use that header to
route each poll to the server instance that holds the task. The supplied
connection helper sets it for you.
4. Read a task's status
Every task is a small state machine. Your MCP client decides what to do next by
reading status:
| Status | What your MCP client does |
|---|---|
working | Wait pollIntervalMs, then call tasks/get again. |
input_required | Show the requests in inputRequests, then reply with tasks/update. |
completed | Read result. Check its isError too, because tool errors land here. |
failed | Read error, a JSON-RPC error that prevented a normal result. |
cancelled | Stop waiting. In this example, files already created stay in output/. |
When a task needs approval or other input, it moves to input_required. The
server puts standard requests, such as an elicitation, in the tasks/get
response, and the MCP client answers them with tasks/update and then goes back
to polling. The image batch never needs input, so this guide does not implement
that path.
5. Who decides to create a task
Both sides opt in to the extension, but the MCP server decides, request by request, whether to create a task. The MCP client never asks for one. It only says that it can handle one.
Each side declares support with the same extension identifier,
io.modelcontextprotocol/tasks:
// MCP client: in every request's params._meta
"io.modelcontextprotocol/clientCapabilities": {
"extensions": { "io.modelcontextprotocol/tasks": {} }
}
// MCP server: in its server/discover capabilities
"capabilities": {
"tools": {},
"extensions": { "io.modelcontextprotocol/tasks": {} }
}Because the client's declaration travels with every request, the server checks it every time. A server must never return a task to a request that did not declare the extension, and this guide's server falls back to an ordinary result in that case.
6. When to reach for Tasks
| Good fit | Usually unnecessary |
|---|---|
| Batch work: imports, exports, migrations, media processing | Lookups and simple API calls |
| Pipelines and deployments that take minutes | Work that reliably finishes in a few seconds |
Approval steps that wait for a person (input_required) | Streaming output back as it is generated |
| Wrapping an API that already returns a job ID |
The official Tasks overview lists more use cases. The statuses, methods and rules in this step come from the Tasks specification.
7. How the next steps map to this picture
- 2. Prepare the projectCopy the project and install it. The image resizing, HTTP wiring and file-based task store are supplied.
- 3. Build the MCP serverAdvertise the extension, return a task handle from tools/call, and serve tasks/get and tasks/cancel.
- 4. Build the MCP clientDeclare support, branch on resultType and poll tasks/get until a terminal status.
- 5. Reconnect and cancelResume a task from a saved ID, then see how cooperative cancellation ends.
- 6. Handle a tool errorConfirm that a tool error completes the task with isError: true, then try your own image.
Checkpoint: before moving on, you should be able to answer these three questions.
- What does the MCP server return in place of the tool result? A task
handle with a
taskId. - How does an MCP client get the result after reconnecting? It calls
tasks/getwith the saved ID, nottools/call. - Which status does a tool error produce?
completed, withisError: truein the result.
No local files change in this step.
Step 1
Ready to continue?
Mark this step complete when you have finished the checks above.
Checking saved progress…

