Channels Overview
This page covers Rust-specific channel details. For the general concept of what a channel is, see Channels.
Built-in channels
Section titled “Built-in channels” InMemoryChannel Same-process registry-to-registry transport via Arc-shared message queues.
MCPChannel Expose a registry's public commands as MCP tools for AI agents.
The CommandChannel trait
Section titled “The CommandChannel trait”All channels implement the CommandChannel trait:
pub trait CommandChannel: Send + Sync { fn id(&self) -> &str; fn start(&self) -> BoxFuture<'_, Result<(), ChannelError>>; fn close(&self) -> BoxFuture<'_, ()>; fn send(&self, msg: Message) -> Result<(), ChannelError>; fn recv(&self) -> BoxFuture<'_, Option<Message>>;}| Method | Description |
|---|---|
id() | Unique identifier for this channel |
start() | Handshake/setup, called once before first recv |
close() | Tear down; subsequent send returns Err(Closed), recv returns None |
send(msg) | Fire-and-forget send to the peer |
recv() | Await the next inbound message, or None on close |
The async methods return BoxFuture so dyn CommandChannel stays object-safe (same shape #[async_trait] would produce).
Registering channels
Section titled “Registering channels”use std::sync::Arc;use coralstack_cmd_ipc::prelude::*;
let channel: Arc<dyn CommandChannel> = /* ... */;let driver = registry.register_channel(channel).await?;tokio::spawn(driver); // or any executorregister_channel returns a Future<Output = ()> — spawn it yourself on tokio, async-std, smol, or futures::executor::ThreadPool. The future resolves when the channel closes, and commands owned by the channel are cleaned up automatically at that point.