title: Server. A2 A Server

A2A Node SDK - v0.1.0 / Modules / Server / A2AServer

Class: A2AServer

Server.A2AServer

Server implementation for hosting A2A protocol agents

The A2AServer class provides a complete HTTP and WebSocket server implementation for hosting agents that implement the A2A protocol. It handles request routing, error handling, and WebSocket connections for streaming.

Example

import { A2AServer, DefaultRequestHandler } from '@dexwox-labs/a2a-node';
 
// Define an agent
const agent = {
  id: 'weather-agent',
  name: 'Weather Agent',
  description: 'Provides weather information',
  capabilities: ['weather-forecasting'],
  endpoint: 'http://localhost:3000'
};
 
// Create a request handler
const requestHandler = new DefaultRequestHandler([agent]);
 
// Create and start the server
const server = new A2AServer(agent, requestHandler);
server.start(3000);

Table of contents

Constructors

Methods

Constructors

constructor

new A2AServer(agentCard, requestHandler, contextMiddleware?): A2AServer

Creates a new A2AServer instance

Parameters

NameTypeDescription
agentCardAgentCardThe agent card describing this server’s capabilities
requestHandlerRequestHandlerHandler for processing incoming requests
contextMiddleware?(req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: NextFunction) => voidOptional custom middleware for request context

Returns

A2AServer

Methods

start

start(port?): void

Starts the A2A server on the specified port

This method starts both the HTTP server and WebSocket server for handling A2A protocol requests. The WebSocket server is used for streaming messages.

Parameters

NameTypeDefault valueDescription
portnumber3000The port to listen on (default: 3000)

Returns

void

Example

// Start on the default port (3000)
server.start();
 
// Start on a specific port
server.start(8080);