← Back to Dashboard
1. Sampling & Roots2. Async Tasks (2025)3. Elicitation & HITL4. Structured Content & Tool Annotations5. Completions & Metadata
Async Tasks (2025)
Long-Running Operations & Non-Blocking Asynchronous Tasks
Standard MCP tools are strictly synchronous: the host issues a tools/call request and blocks waiting for the response. When an agent triggers operations requiring minutes or hours (such as building container images, fine-tuning a model, or executing extensive database migrations), synchronous execution risks socket disconnections, proxy timeouts, and frozen user interfaces.
The MCP Task Lifecycle
- Immediate Handle Return: The tool initializes background work and immediately returns a unique
taskIdwith status"running". - Progress Stream: The server emits out-of-band progress notifications (
notifications/progress) containing aprogressToken, percentage complete, and status messages. - Asynchronous Polling & Completion: The host polls
tasks/getor listens to server-sent events (SSE). When finished, the task resolves into standardCallToolResultcontent. - Cooperative Cancellation: The client can issue
tasks/cancelif the user aborts the workflow, cleanly reclaiming compute resources.
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { z } from "zod";
const server = new McpServer({ name: "cloud-builder", version: "1.0.0" });
server.tool(
"run_container_build",
{ repoUrl: z.string().url(), tag: z.string() },
async ({ repoUrl, tag }, extra) => {
const taskId = "build_" + Date.now();
// Spawn background worker process
spawnBuildWorker(taskId, repoUrl, tag, async (current, total, msg) => {
// Stream real-time progress back to the host client
if (extra._meta?.progressToken) {
await extra.sendProgressNotification({
progressToken: extra._meta.progressToken,
progress: current,
total: total
});
}
});
return {
content: [{ type: "text", text: "Build started asynchronously. Task ID: " + taskId }]
};
}
);⌨ HANDS-ON LABQuery Async Background Task Status
⭐ +150 XPQuery the execution status of an asynchronous background task on the MCP server.
1Send tasks/get method for a long-running task.
OBJECTIVE 1 / 1 — type "hint" if stuck
🧪 Knowledge Check
Press 1-4 to select1 of 3
Why were Tasks introduced into the MCP spec in 2025?
To replace JSON with XML.
To handle long-running tool executions asynchronously without blocking the client connection.
To improve text rendering.
To manage memory garbage collection.