@@ -200,36 +200,43 @@ pub mod connecting_as_client {
200200 //!
201201 //! # Example
202202 //!
203- //! ```ignore
204- //! use sacp::ClientToAgent;
205- //! use sacp::schema::{InitializeRequest, NewSessionRequest};
206- //!
207- //! ClientToAgent::builder()
208- //! .name("my-client")
209- //! .on_receive_notification(async |notif: SessionUpdate, cx| {
210- //! // Handle notifications from the agent
211- //! println!("Session updated: {:?}", notif);
212- //! Ok(())
213- //! }, sacp::on_receive_notification!())
214- //! .with_client(transport, async |cx| {
215- //! // Initialize the connection
216- //! let init_response = cx.send_request(InitializeRequest::make())
217- //! .block_task()
218- //! .await?;
219- //!
220- //! // Create a session
221- //! let session = cx.send_request(NewSessionRequest {
222- //! cwd: std::env::current_dir()?,
223- //! mcp_servers: vec![],
224- //! meta: None,
225- //! })
226- //! .block_task()
227- //! .await?;
203+ //! ```
204+ //! use sacp::{ClientToAgent, Component};
205+ //! use sacp::schema::{InitializeRequest, NewSessionRequest, SessionNotification};
206+ //!
207+ //! async fn connect_to_agent(transport: impl Component) -> Result<(), sacp::Error> {
208+ //! ClientToAgent::builder()
209+ //! .name("my-client")
210+ //! .on_receive_notification(async |notif: SessionNotification, _cx| {
211+ //! // Handle notifications from the agent
212+ //! println!("Session updated: {:?}", notif);
213+ //! Ok(())
214+ //! }, sacp::on_receive_notification!())
215+ //! .with_client(transport, async |cx| {
216+ //! // Initialize the connection
217+ //! let _init_response = cx.send_request(InitializeRequest {
218+ //! protocol_version: Default::default(),
219+ //! client_capabilities: Default::default(),
220+ //! client_info: None,
221+ //! meta: None,
222+ //! })
223+ //! .block_task()
224+ //! .await?;
225+ //!
226+ //! // Create a session
227+ //! let session = cx.send_request(NewSessionRequest {
228+ //! cwd: ".".into(),
229+ //! mcp_servers: vec![],
230+ //! meta: None,
231+ //! })
232+ //! .block_task()
233+ //! .await?;
228234 //!
229- //! println!("Session created: {:?}", session.session_id);
230- //! Ok(())
231- //! })
232- //! .await?;
235+ //! println!("Session created: {:?}", session.session_id);
236+ //! Ok(())
237+ //! })
238+ //! .await
239+ //! }
233240 //! ```
234241 //!
235242 //! # Note on `block_task`
@@ -322,32 +329,32 @@ pub mod per_session_mcp_server {
322329 //!
323330 //! # Example
324331 //!
325- //! ```ignore
332+ //! ```
326333 //! use sacp::mcp_server::McpServer;
327334 //! use sacp::schema::NewSessionRequest;
328- //! use sacp::{Agent, Client, ProxyToConductor};
329- //!
330- //! ProxyToConductor::builder()
331- //! .on_receive_request_from(Client, async |request: NewSessionRequest, request_cx, cx| {
332- //! // Create an MCP server for this session
333- //! let cwd = request.cwd.clone();
334- //! let mcp_server = McpServer::builder("session-tools")
335- //! .tool_fn("get_cwd", "Returns session working directory",
336- //! async move |_params: (), _cx| {
337- //! Ok(cwd.display().to_string())
338- //! }, sacp::tool_fn! ())
339- //! .build();
340- //!
341- //! // Build the session with the MCP server attached
342- //! cx.build_session(request)
343- //! .with_mcp_server(mcp_server)?
344- //! .run_session(async |session| {
345- //! request_cx.respond(session.response().clone() )
346- //! })
347- //! .await
348- //! }, sacp::on_receive_request!() )
349- //! .serve(transport)
350- //! .await?;
335+ //! use sacp::{Agent, Client, Component, JrResponder, ProxyToConductor};
336+ //!
337+ //! async fn run_proxy(transport: impl Component) -> Result<(), sacp::Error> {
338+ //! ProxyToConductor::builder()
339+ //! .on_receive_request_from(Client, async |request: NewSessionRequest, request_cx, cx| {
340+ //! // Create an MCP server for this session
341+ //! let cwd = request.cwd.clone();
342+ //! let mcp_server = McpServer::builder("session-tools")
343+ //! .tool_fn("get_cwd", "Returns session working directory",
344+ //! async move |_params: (), _cx| {
345+ //! Ok(cwd.display().to_string ())
346+ //! }, sacp::tool_fn!())
347+ //! .build();
348+ //!
349+ //! // Build the session with the MCP server attached and proxy it
350+ //! cx.build_session_from(request)
351+ //! .with_mcp_server(mcp_server)?
352+ //! .proxy_session(request_cx, JrResponder::run )
353+ //! .await
354+ //! }, sacp::on_receive_request!())
355+ //! .serve(transport )
356+ //! .await
357+ //! }
351358 //! ```
352359 //!
353360 //! # How it works
0 commit comments