Mastra adds experimental MCP tasks for background tool calls
Mastra introduced MCP tasks for MCPServer and MCPClient, allowing long-running tool calls to execute in the background while an agent continues responding. The server returns a task ID that the client polls for working, input_required, completed, failed, or cancelled status, with completed results returned to the agent. The feature requires @mastra/mcp 2.7.0 and @mastra/core 1.81.0 or later.
According to Mastra Blog, task IDs can end long-lived HTTP requests and free the agent loop from slow or expensive MCP tool calls.
You can now use tasks with Mastra MCPServer and MCPClient to run long-running tool calls in the background. The client can poll the server until the task is completed, then hand the result back to the agent.
While tool calls are in progress, agents are blocked and can't respond to user requests. Moving tool calls to tasks lets the agent keep responding while slow or expensive computations run in the background.
Your browser does not support the video tag.An agent keeps answering questions while a 30-day repo report runs as an MCP task, then shows the finished report as a dashboard.
Before tasks, MCP tool calls were synchronous. Each call was handled by a single HTTP request that remained open until complete, and blocked the agent loop. Mastra's existing background tasks primitive could be used to free up the agent loop, but if a tool call outlasted a proxy timeout or a load balancer's idle limit, it would eventually fail.
With tasks, MCP servers can quickly respond with a task ID (which completes the HTTP request and unblocks the agent). MCP clients then use the ID to poll the server, receiving a response that includes a task status of working, input_required, completed, failed, or cancelled. When the task completes, Mastra sends the agent a notification signal, which reaches an active run on its next model request, instead of waiting for the agent loop to finish.
#Mastra#Mastra MCPServer#Mastra MCPClient#Model Context Protocol