Channels Overview
This page covers TypeScript-specific channel details. For the general concept of what a channel is, see Channels.
Built-in channels
Section titled “Built-in channels” MessagePortChannel Web Workers, Node.js worker_threads, and MessageChannel communication.
HTTPChannel HTTP-based communication with NDJSON streaming for REST APIs and edge functions.
MCPChannel Model Context Protocol integration — expose commands as AI agent tools or consume remote MCP servers.
The ICommandChannel interface
Section titled “The ICommandChannel interface”All channels implement ICommandChannel. Create custom transports (WebSocket, gRPC, etc.) by implementing this interface:
interface ICommandChannel { readonly id: string start(): Promise<void> close(): Promise<void> sendMessage(message: unknown): void on(event: 'message', listener: (message: unknown) => void): void on(event: 'close', listener: () => void): void}| Method | Description |
|---|---|
id | Unique identifier for this channel |
start() | Initialize the channel (called automatically by the registry) |
close() | Close the channel and clean up resources |
sendMessage() | Send a message through the channel |
on('message') | Subscribe to incoming messages |
on('close') | Subscribe to channel close events |
Registering channels
Section titled “Registering channels”const channel = new MessagePortChannel('worker', workerPort)await registry.registerChannel(channel)