Skip to content

@agenticforge/protocols

npm

TypeScript implementations of MCP, A2A, and ANP — the three core agent communication protocols.

Installation

bash
npm install @agenticforge/protocols

Protocols

ProtocolPurposeKey Classes
MCPTool calls, resource access, prompt templatesMCPServer, MCPClient, MCPServerBuilder
A2AInter-agent skill sharing and communicationA2AServer, A2AClient, AgentNetwork
ANPNetwork management and service discoveryANPNetwork, ANPDiscovery, ServiceInfo

MCP

ts
import {MCPServer, MCPClient} from "@agenticforge/protocols";

const server = new MCPServer("my-server");
server.addTool(
  "greet",
  "Say hello",
  {type: "object", properties: {name: {type: "string"}}, required: ["name"]},
  ({name}) => `Hello, ${name}!`,
);

// In-memory client
const client = new MCPClient(server);
await client.connect();
console.log(await client.callTool("greet", {name: "World"}));

// HTTP mode
await server.serve(8000);
const remote = new MCPClient("http://127.0.0.1:8000");
await remote.connect();

MCPServer HTTP endpoints:

MethodPathDescription
GET/healthHealth check
GET/infoServer info
GET/toolsList tools
POST/tools/:nameCall tool ({ arguments: {...} })
GET/resourcesList resources
GET/resources/*Read resource
GET/promptsList prompts
POST/prompts/:nameGet prompt ({ arguments: {...} })

A2A

ts
import {A2AServer, A2AClient, AgentNetwork} from "@agenticforge/protocols";

const agent = new A2AServer({name: "my-agent", description: "Example"});
agent.addSkill("echo", "Echo input", (text) => text);
await agent.serve(5000);

const client = new A2AClient("http://localhost:5000");
const res = await client.executeSkill("echo", "hello");
console.log(res.result); // "hello"

// Auto-discover agents
const network = new AgentNetwork();
await network.discoverAgents(["http://localhost:5000"]);

A2AServer HTTP endpoints:

MethodPathDescription
GET/healthHealth check
GET/infoAgent info
GET/skillsList skills
POST/execute/:skillRun skill ({ text, data? })
POST/askAuto-select skill ({ question })

ANP

ts
import {ANPNetwork, ANPDiscovery, ServiceInfo} from "@agenticforge/protocols";

const discovery = new ANPDiscovery();
discovery.registerService(new ServiceInfo({
  serviceId: "svc-1",
  serviceType: "calculator",
  endpoint: "http://localhost:8001",
  capabilities: ["add", "multiply"],
}));
const svcs = discovery.findServicesByType("calculator");

const network = new ANPNetwork("prod");
network.addNode("n1", "http://localhost:8001");
network.addNode("n2", "http://localhost:8002");
network.connectNodes("n1", "n2");
const route = network.routeMessage("n1", "n2");
const status = network.getNetworkStatus(); // { healthStatus: "healthy", ... }

API Reference

Base

ExportDescription
ProtocolTypeEnum: MCP | A2A | ANP
ProtocolAbstract base class

MCP Exports

ExportDescription
MCPServerServer with tool/resource/prompt registration + HTTP
MCPServerBuilderFluent builder for MCPServer
MCPClientIn-memory or HTTP client
createExampleMCPServer()Example server factory
createContext()Create MCP context object
parseContext()Parse MCP context from JSON
createSuccessResponse()Build success response
createErrorResponse()Build error response

A2A Exports

ExportDescription
A2AServerAgent server with skill registration + HTTP
A2AClientClient for in-memory or HTTP mode
AgentNetworkManage multiple agents with auto-discovery
AgentRegistryCentral registry for A2A agents
createExampleA2AServer()Example agent factory

ANP Exports

ExportDescription
ServiceInfoService descriptor class
ANPDiscoveryService registry with filtering
ANPNetworkNetwork topology management
createExampleANPNetwork()3-node example network factory

See the Protocols Guide for architecture details and examples.

Released under the CC BY-NC-SA 4.0 License.