pub struct V2SessionBuilder<Counterpart, Run = NullRun>{ /* private fields */ }unstable_protocol_v2 only.Expand description
Builder for a draft protocol v2 session/new request.
Protocol v2 acknowledges session/prompt independently from inbound
session updates. Register typed v2::UpdateSessionNotification and
session request handlers on crate::Builder before connecting, then use
Self::start_session to create the command-only V2Session handle or
on_proxy_session_start to forward setup through a proxy.
With both the unstable_protocol_v2 and unstable_mcp_over_acp features,
with_mcp_server attaches an MCP server to the new session.
Implementations§
Source§impl<Counterpart, Run> V2SessionBuilder<Counterpart, Run>
impl<Counterpart, Run> V2SessionBuilder<Counterpart, Run>
Sourcepub fn with_mcp_server<McpRun>(
self,
mcp_server: McpServer<Counterpart, McpRun>,
) -> Result<V2SessionBuilder<Counterpart, ChainRun<Run, McpRun>>, Error>where
McpRun: RunWithConnectionTo<Counterpart>,
Available on crate feature unstable_mcp_over_acp only.
pub fn with_mcp_server<McpRun>(
self,
mcp_server: McpServer<Counterpart, McpRun>,
) -> Result<V2SessionBuilder<Counterpart, ChainRun<Run, McpRun>>, Error>where
McpRun: RunWithConnectionTo<Counterpart>,
unstable_mcp_over_acp only.Attach an MCP server to this new protocol v2 session.
This method is available when both unstable_protocol_v2 and
unstable_mcp_over_acp are enabled. MCP routes are installed and their
runner tasks receive an initial poll before session/new is published,
allowing the agent to connect while handling session setup. A
successful attachment remains active for the lifetime of the connection.
Sourcepub fn start_session(
self,
) -> SentRequest<OpenedV2Session<Counterpart, NewSessionResponse>>where
Run: 'static,
pub fn start_session(
self,
) -> SentRequest<OpenedV2Session<Counterpart, NewSessionResponse>>where
Run: 'static,
Send session/new and return its independently consumable request.
The successful result contains both a cloneable command handle and the
complete v2::NewSessionResponse. Consume the returned request with
SentRequest::block_task, SentRequest::on_receiving_result, or
another explicit SentRequest completion mode.
Attached MCP routes are installed and their runner tasks begin executing before the request is published. A valid success response promotes them to the connection lifetime, independently from how this request handle is consumed. Setup errors clean up the pending attachment.
Sourcepub fn on_proxy_session_start<F, Fut>(
self,
responder: Responder<NewSessionResponse>,
op: F,
) -> Result<(), Error>
pub fn on_proxy_session_start<F, Fut>( self, responder: Responder<NewSessionResponse>, op: F, ) -> Result<(), Error>
Start a protocol v2 session through a proxy and forward its response.
The downstream request is ordered and inherits cancellation from the
upstream request. On success, this helper installs session routing before
later inbound traffic is processed, forwards the complete response, and
spawns op with an OpenedV2Session containing the command-only
session handle plus the complete setup response. Inbound updates and
interactive requests remain independent connection traffic.
The callback runs outside the ordered response barrier, so it may wait for later connection traffic without deadlocking the dispatch loop.