Skip to main content
mountAgents hands the upgrade to the runtime’s default webSocket(), and the GET, like an RPC’s POST, to the class’s fetch:
fetch(req) overrides the runtime SDK’s fetch() with an AgentHttpServer over connectionEngine.
  • The server answers a GET with Server-Sent Events, and a POST to …/rpc/<method> with one RPC call.
  • connectionEngine is the engine the default webSocket() runs every socket through, so both transports serve the same streams under the same authorize.
  • The server is built on the first request and kept for the activation.
authorize decides who may read the streams and who may call the @rpc methods:
authorize(token, req) overrides the runtime SDK’s authorize().
  • token is the credential the caller presented, or undefined without one.
  • req is the request, with any identity headers a front door stamped on it.
  • The returned claims are the caller’s grants, and a throw rejects the caller. The runtime acts on "rpc" alone, which admits the @rpc methods.
  • The runtime’s own default returns ["read"], which admits the streams and no RPC.
The voice class overrides webSocket() to answer calls: an upgrade whose address carries ?media=call is a call’s media, as The Call Webhook shows, and any other upgrade is the agent socket protocol, as here.
Without a host authorize, every caller is granted read and RPC — including the approvals methods: pendingApproval and inspectApproval expose the pending approval (tool name, required action, arguments), and approve/deny decide it.