a2a_send_task_subscribe
Send a task to an A2A agent and subscribe to receive real-time streaming updates on its progress and responses.
Instructions
Send a task and subscribe to updates (streaming)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| message | Yes | Message to send to the agent | |
| taskId | No | Optional task ID. If not provided, a new UUID will be generated | |
| agentId | No | Optional agent ID. If not provided, the first available agent will be used | |
| maxUpdates | No | Maximum number of updates to receive (default: 10) |
Implementation Reference
- index.ts:202-244 (handler)Handler for the 'a2a_send_task_subscribe' MCP tool. Selects an A2A client, sends a task with subscription for streaming updates, collects up to maxUpdates events, and returns the task ID and updates as JSON.case "a2a_send_task_subscribe": { const { message, taskId, agentId, maxUpdates = 10 } = args as { message: string; taskId?: string; agentId?: string; maxUpdates?: number; }; const client = agentId ? agentManager.getClientById(agentId) : agentManager.getAllClients().values().next().value; if (!client) { throw new Error(`No available agent${agentId ? ` with ID ${agentId}` : ''}`); } const id = taskId || crypto.randomUUID(); const stream = client.sendTaskSubscribe({ id, message: { role: "user", parts: [{ text: message }], }, }); const updates = []; let count = 0; for await (const event of stream) { updates.push(event); count++; if (count >= maxUpdates) break; if (event.final) break; } return { content: [ { type: "text", text: JSON.stringify({ taskId: id, updates }, null, 2), }, ], }; }
- index.ts:94-114 (schema)Input schema for the a2a_send_task_subscribe tool, validating message (required string), optional taskId, agentId, and maxUpdates (number).inputSchema: { type: "object", properties: { message: { type: "string", description: "Message to send to the agent", }, taskId: { type: "string", description: "Optional task ID. If not provided, a new UUID will be generated", }, agentId: { type: "string", description: "Optional agent ID. If not provided, the first available agent will be used", }, maxUpdates: { type: "number", description: "Maximum number of updates to receive (default: 10)", }, }, required: ["message"],
- index.ts:91-116 (registration)Registration of the a2a_send_task_subscribe tool in the ListToolsRequestSchema response, including name, description, and input schema.{ name: "a2a_send_task_subscribe", description: "Send a task and subscribe to updates (streaming)", inputSchema: { type: "object", properties: { message: { type: "string", description: "Message to send to the agent", }, taskId: { type: "string", description: "Optional task ID. If not provided, a new UUID will be generated", }, agentId: { type: "string", description: "Optional agent ID. If not provided, the first available agent will be used", }, maxUpdates: { type: "number", description: "Maximum number of updates to receive (default: 10)", }, }, required: ["message"], }, },
- a2a-client.ts:391-409 (helper)Supporting utility method A2AClient.sendTaskSubscribe that initiates the streaming JSON-RPC request to 'tasks/sendSubscribe' for real-time task updates.sendTaskSubscribe( params: TaskSendParams ): AsyncIterable<TaskStatusUpdateEvent | TaskArtifactUpdateEvent> { const streamGenerator = async function* ( this: A2AClient ): AsyncIterable<TaskStatusUpdateEvent | TaskArtifactUpdateEvent> { const httpResponse = await this._makeHttpRequest( "tasks/sendSubscribe", params, "text/event-stream" ); yield* this._handleStreamingResponse<TaskStatusUpdateEvent | TaskArtifactUpdateEvent>( httpResponse, "tasks/sendSubscribe" ); }.bind(this)(); return streamGenerator; }