title: Server. Request Handler
A2A Node SDK - v0.1.0 / Modules / Server / RequestHandler
Interface: RequestHandler
Server.RequestHandler
Interface for request handlers in the A2A server
This interface defines the contract for all request handlers in the A2A server, including methods for handling messages, managing tasks, configuring push notifications, and discovering agents.
Implemented by
Table of contents
Properties
Methods
- handleCancelTask
- handleDiscoverAgents
- handleGetPushConfig
- handleGetTaskStatus
- handleSendMessage
- handleSetPushConfig
- handleStreamMessage
- handleTaskResubscription
- normalizeError
Properties
router
• Readonly
router: Router
Express router for handling HTTP requests
Methods
handleCancelTask
▸ handleCancelTask(taskId
): Promise
<void
>
Cancels a running task
Parameters
Name | Type | Description |
---|---|---|
taskId | string | ID of the task to cancel |
Returns
Promise
<void
>
Promise resolving when the task is canceled
handleDiscoverAgents
▸ handleDiscoverAgents(capability?
): Promise
<AgentCard
[]>
Discovers available agents, optionally filtered by capability
Parameters
Name | Type | Description |
---|---|---|
capability? | string | Optional capability to filter agents by |
Returns
Promise
<AgentCard
[]>
Promise resolving to an array of agent cards
handleGetPushConfig
▸ handleGetPushConfig(taskId
): Promise
<PushNotificationConfig
>
Gets push notification configuration for a task
Parameters
Name | Type | Description |
---|---|---|
taskId | string | ID of the task |
Returns
Promise
<PushNotificationConfig
>
Promise resolving to the push notification configuration
handleGetTaskStatus
▸ handleGetTaskStatus(taskId
): Promise
<Task
>
Gets the status of a task
Parameters
Name | Type | Description |
---|---|---|
taskId | string | ID of the task |
Returns
Promise
<Task
>
Promise resolving to the task object
handleSendMessage
▸ handleSendMessage(parts
, agentId
): Promise
<string
>
Handles sending a message to an agent
Parameters
Name | Type | Description |
---|---|---|
parts | ({ content : string ; format : "plain" | "markdown" ; type : "text" } | { content : string | Uint8Array <ArrayBuffer > ; mimeType : string ; name : string ; size? : number ; type : "file" } | { content : Record <string , any > ; schema? : string ; type : "data" } | { content : string ; format : "plain" ; type : "heartbeat" })[] | Message parts to send |
agentId | string | ID of the target agent |
Returns
Promise
<string
>
Promise resolving to the created task ID
handleSetPushConfig
▸ handleSetPushConfig(taskId
, config
): Promise
<void
>
Sets push notification configuration for a task
Parameters
Name | Type | Description |
---|---|---|
taskId | string | ID of the task |
config | PushNotificationConfig | Push notification configuration |
Returns
Promise
<void
>
Promise resolving when the configuration is set
handleStreamMessage
▸ handleStreamMessage(parts
, agentId
): AsyncGenerator
<{ content
: string
; format
: "plain"
| "markdown"
; type
: "text"
} | { content
: string
| Uint8Array
<ArrayBuffer
> ; mimeType
: string
; name
: string
; size?
: number
; type
: "file"
} | { content
: Record
<string
, any
> ; schema?
: string
; type
: "data"
} | { content
: string
; format
: "plain"
; type
: "heartbeat"
}, void
, unknown
>
Handles streaming a message to an agent
Parameters
Name | Type | Description |
---|---|---|
parts | ({ content : string ; format : "plain" | "markdown" ; type : "text" } | { content : string | Uint8Array <ArrayBuffer > ; mimeType : string ; name : string ; size? : number ; type : "file" } | { content : Record <string , any > ; schema? : string ; type : "data" } | { content : string ; format : "plain" ; type : "heartbeat" })[] | Message parts to send |
agentId | string | ID of the target agent |
Returns
AsyncGenerator
<{ content
: string
; format
: "plain"
| "markdown"
; type
: "text"
} | { content
: string
| Uint8Array
<ArrayBuffer
> ; mimeType
: string
; name
: string
; size?
: number
; type
: "file"
} | { content
: Record
<string
, any
> ; schema?
: string
; type
: "data"
} | { content
: string
; format
: "plain"
; type
: "heartbeat"
}, void
, unknown
>
AsyncGenerator yielding message parts as they are processed
handleTaskResubscription
▸ handleTaskResubscription(taskId
): AsyncGenerator
<{ content
: string
; format
: "plain"
| "markdown"
; type
: "text"
} | { content
: string
| Uint8Array
<ArrayBuffer
> ; mimeType
: string
; name
: string
; size?
: number
; type
: "file"
} | { content
: Record
<string
, any
> ; schema?
: string
; type
: "data"
} | { content
: string
; format
: "plain"
; type
: "heartbeat"
}, void
, unknown
>
Resubscribes to a task’s message stream
Parameters
Name | Type | Description |
---|---|---|
taskId | string | ID of the task |
Returns
AsyncGenerator
<{ content
: string
; format
: "plain"
| "markdown"
; type
: "text"
} | { content
: string
| Uint8Array
<ArrayBuffer
> ; mimeType
: string
; name
: string
; size?
: number
; type
: "file"
} | { content
: Record
<string
, any
> ; schema?
: string
; type
: "data"
} | { content
: string
; format
: "plain"
; type
: "heartbeat"
}, void
, unknown
>
AsyncGenerator yielding message parts for the task
normalizeError
▸ normalizeError(err
): A2AError
Normalizes errors to A2AError format
Parameters
Name | Type | Description |
---|---|---|
err | unknown | Error to normalize |
Returns
Normalized A2AError