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:

ProblemWhat happens with one long request
TimeoutsClients and intermediaries close requests that stay open too long.
Lost resultsIf the MCP client exits or the connection drops, the result is lost.
No visibilityThe 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.

Two sequence diagrams. Without Tasks, the MCP client sends tools/call and waits on one open request while the MCP server resizes 18 images; a timeout or disconnect leaves the result with nowhere to go. With Tasks, the MCP server returns a task handle immediately, the MCP client sends short tasks/get requests and sees "working, Created 6 of 18", and the last tasks/get returns completed with the final result.

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:

jsonc
{
  "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.

Sequence diagram with three participants: MCP client, MCP server and task store. 1: the MCP client sends tools/call and its _meta declares Tasks support. 2: the MCP server saves a task with status working. 3: the server returns a task handle with resultType task and a taskId. 4: a worker resizes images in the background and updates the store. 5: in a loop every pollIntervalMs, the client sends tasks/get with the taskId and receives status working with a message such as "Created 6 of 18 thumbnails." 6: the client can exit or lose its connection; the task keeps running and a new connection polls the saved taskId without a second tools/call. 7: tasks/get returns status completed with a result in the same shape tools/call returns.

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/get always finds the task.
  • The work runs outside the request (step 4). By then the tools/call response 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/get with the saved ID follows the original one instead.
  • The final tasks/get carries the result (step 7). Its result field holds exactly what an ordinary tools/call would have returned, so there is no separate "fetch result" request.

The extension adds three methods to the tools/call you already know:

MethodThe MCP client sends it toIn this guide
tools/callStart the work. The response is a task handle or an ordinary result.Steps 3–4
tasks/getRead the current status and, once finished, the result.Steps 3–6
tasks/cancelAsk the MCP server to stop. The reply is an empty acknowledgement.Step 5
tasks/updateAnswer 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:

State diagram. A task starts in working after tools/call returns a task handle. It can move to input_required when it needs input and back to working after tasks/update; this guide's example never needs input. From working, a task ends in one of three terminal statuses that never change: completed when the result is ready, including when the tool result has isError true; failed for JSON-RPC errors only, not tool errors; and cancelled when tasks/cancel is honoured, although cancellation is cooperative and the task may still end as completed.

StatusWhat your MCP client does
workingWait pollIntervalMs, then call tasks/get again.
input_requiredShow the requests in inputRequests, then reply with tasks/update.
completedRead result. Check its isError too, because tool errors land here.
failedRead error, a JSON-RPC error that prevented a normal result.
cancelledStop 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.

Flowchart. The MCP client sends tools/call. If the request's _meta does not declare the Tasks extension, the server never returns a task: it returns an ordinary result, or error -32021 if it cannot do the work without one. If the request declares the extension, the MCP server decides per request: an ordinary CallToolResult for quick work, or a task handle with resultType task for long work. Your client must handle both shapes on every call. In this guide, a declaring client always receives a task handle.

Each side declares support with the same extension identifier, io.modelcontextprotocol/tasks:

jsonc
// 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 fitUsually unnecessary
Batch work: imports, exports, migrations, media processingLookups and simple API calls
Pipelines and deployments that take minutesWork 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

  1. 2. Prepare the projectCopy the project and install it. The image resizing, HTTP wiring and file-based task store are supplied.
  2. 3. Build the MCP serverAdvertise the extension, return a task handle from tools/call, and serve tasks/get and tasks/cancel.
  3. 4. Build the MCP clientDeclare support, branch on resultType and poll tasks/get until a terminal status.
  4. 5. Reconnect and cancelResume a task from a saved ID, then see how cooperative cancellation ends.
  5. 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.

  1. What does the MCP server return in place of the tool result? A task handle with a taskId.
  2. How does an MCP client get the result after reconnecting? It calls tasks/get with the saved ID, not tools/call.
  3. Which status does a tool error produce? completed, with isError: true in 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…

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.