pub struct ChannelTransport { /* private fields */ }Expand description
An in-process ClientTransport that connects directly to an McpRouter.
Messages are passed through tokio channels: background tasks feed
incoming JSON-RPC requests to a JsonRpcService<McpRouter> (one spawned
task per request, so calls run concurrently) and pump server
notifications into the response stream.
Implementations§
Source§impl ChannelTransport
impl ChannelTransport
Sourcepub fn new(router: McpRouter) -> Self
pub fn new(router: McpRouter) -> Self
Create a new channel transport backed by the given router.
Wires an internal notification channel into the router, so
notifications emitted during request handling (progress, log
messages, list-changed) are delivered to the client. To push
notifications from the host process’s own tasks, use
with_notifications instead.
Note: this overwrites any notification sender previously set on the
router, matching the transport-owns-the-channel behavior of
HttpTransport::new.
Sourcepub fn with_notifications(
router: McpRouter,
notification_rx: NotificationReceiver,
) -> Self
pub fn with_notifications( router: McpRouter, notification_rx: NotificationReceiver, ) -> Self
Create a channel transport with a caller-owned notification receiver.
Mirrors HttpTransport::with_notifications: the host process keeps
the sender (its own clone from notification_channel, or via
McpRouter::notification_sender) and pushes
ServerNotifications from its
own tasks; the transport serializes them into JSON-RPC notification
frames and interleaves them into recv.
The router passed here should already carry the matching sender (see the module-level example) so notifications emitted during request handling flow through the same channel.
Sourcepub fn layer<L>(router: McpRouter, layer: L) -> Selfwhere
L: Layer<McpRouter>,
L::Service: Service<RouterRequest, Response = RouterResponse> + Clone + Send + 'static,
<L::Service as Service<RouterRequest>>::Error: Display + Send,
<L::Service as Service<RouterRequest>>::Future: Send,
pub fn layer<L>(router: McpRouter, layer: L) -> Selfwhere
L: Layer<McpRouter>,
L::Service: Service<RouterRequest, Response = RouterResponse> + Clone + Send + 'static,
<L::Service as Service<RouterRequest>>::Error: Display + Send,
<L::Service as Service<RouterRequest>>::Future: Send,
Create a channel transport whose dispatch runs through a Tower layer.
The channel counterpart of StdioTransport::layer: the layer wraps
the router’s dispatch service, so standard middleware (timeout, rate
limit, tracing, audit) observes every JSON-RPC request an
McpClient makes in-process, exactly as
it would over stdio or HTTP. Layers that produce errors are wrapped
with CatchError and tool-annotation injection is preserved.
subscriptions/listen remains transport-owned on every transport and
does not pass through the layer (#1182 tracks that boundary).
Sourcepub fn layer_with_notifications<L>(
router: McpRouter,
layer: L,
notification_rx: NotificationReceiver,
) -> Selfwhere
L: Layer<McpRouter>,
L::Service: Service<RouterRequest, Response = RouterResponse> + Clone + Send + 'static,
<L::Service as Service<RouterRequest>>::Error: Display + Send,
<L::Service as Service<RouterRequest>>::Future: Send,
pub fn layer_with_notifications<L>(
router: McpRouter,
layer: L,
notification_rx: NotificationReceiver,
) -> Selfwhere
L: Layer<McpRouter>,
L::Service: Service<RouterRequest, Response = RouterResponse> + Clone + Send + 'static,
<L::Service as Service<RouterRequest>>::Error: Display + Send,
<L::Service as Service<RouterRequest>>::Future: Send,
layer with a caller-owned notification receiver, the
layered counterpart of with_notifications.