Skip to main content
Back to timeline
mastra.aiSource publication:

Mastra adds background tasks to MCP tool calls: slow computations no longer block the agent, and clients poll a task ID for results

Synopsis

Mastra has added tasks to its MCP server and client so that long-running tool calls run in the background. Previously MCP tool calls were synchronous: a single HTTP request stayed open until the call finished, blocking the agent loop, and although Mastra's existing background tasks primitive could free the loop, a call that outlasted a proxy timeout or a load balancer's idle limit would still fail. Now the server returns a task ID that ends the request, the client polls that ID for working, input_required, completed, failed or cancelled status, and a notification signal reaches the agent when the task completes.

Source-provided article image: Introducing MCP Tasks in Mastra
mastra.ai

Interpretation

Mastra's MCP server and client can now run tool calls as tasks in the background, so the agent keeps responding to user requests while slow or expensive computations run. Before tasks, MCP tool calls were synchronous, each handled by a single HTTP request that remained open until complete and blocked the agent loop. Mastra's existing background tasks primitive could free the agent loop, but a tool call that outlasted a proxy timeout or a load balancer's idle limit would eventually fail, which is the case tasks address.

The mechanism has the server respond immediately with a task ID, which completes the HTTP request and unblocks the agent. The client then uses that ID to poll the server, receiving a response that includes one of the task statuses working, input_required, completed, failed or cancelled. When the task completes, Mastra sends the agent a notification signal that reaches an active run on its next model request instead of waiting for the agent loop to finish.

Perspective

The mechanism targets developers using Mastra MCPServer and MCPClient; tools can be configured as tasks with always, auto or off, where auto switches a call to a task when it exceeds syncWindowMs (2 seconds by default), and a running task can still call suspend() to request human input and pause in the input_required state until the client responds.

MCP tasks are still experimental, and the API may change between releases.