Skip to main content

objectiveai_cli/command/agents/mcp/tools/
mod.rs

1//! `agents mcp tools` — CLI-side dispatch for the tool ops. `call`,
2//! `list`. Each leaf does one socket round-trip to the agent's
3//! per-`response_id` MCP listener and returns the MCP result.
4
5use std::pin::Pin;
6
7use futures::Stream;
8use objectiveai_sdk::cli::command::agents::mcp::tools::{Request, ResponseItem};
9
10use crate::context::Context;
11use crate::error::Error;
12
13pub mod call;
14pub mod list;
15
16type ItemStream = Pin<Box<dyn Stream<Item = Result<ResponseItem, Error>> + Send>>;
17
18fn once<T: Send + 'static>(
19    item: Result<T, Error>,
20) -> Pin<Box<dyn Stream<Item = Result<T, Error>> + Send>> {
21    Box::pin(futures::stream::once(async move { item }))
22}
23
24pub async fn execute(ctx: &Context, request: Request) -> Result<ItemStream, Error> {
25    let stream: ItemStream = match request {
26        Request::Call(req) => {
27            let value = call::execute(ctx, req).await?;
28            once(Ok(ResponseItem::Call(value)))
29        }
30        Request::CallRequestSchema(req) => {
31            let value = call::request_schema::execute(ctx, req).await?;
32            once(Ok(ResponseItem::CallRequestSchema(value)))
33        }
34        Request::CallResponseSchema(req) => {
35            let value = call::response_schema::execute(ctx, req).await?;
36            once(Ok(ResponseItem::CallResponseSchema(value)))
37        }
38        Request::List(req) => {
39            let value = list::execute(ctx, req).await?;
40            once(Ok(ResponseItem::List(value)))
41        }
42        Request::ListRequestSchema(req) => {
43            let value = list::request_schema::execute(ctx, req).await?;
44            once(Ok(ResponseItem::ListRequestSchema(value)))
45        }
46        Request::ListResponseSchema(req) => {
47            let value = list::response_schema::execute(ctx, req).await?;
48            once(Ok(ResponseItem::ListResponseSchema(value)))
49        }
50    };
51    Ok(stream)
52}