Skip to main content

objectiveai_cli/command/agents/tools/
call.rs

1//! `agents tools call` — connect to the agent's per-`response_id` MCP
2//! listener socket, run `tools/call`, and return the MCP
3//! `CallToolResult`. A socket-level `err` reply (e.g. unknown response
4//! id) or a connect/IO failure surfaces as an `Error`.
5
6use objectiveai_sdk::cli::command::agents::tools::call::{Request, Response};
7
8use crate::context::Context;
9use crate::error::Error;
10use crate::websockets::mcp_listener::{SocketRequest, SocketResponse, call_socket};
11
12pub async fn execute(ctx: &Context, request: Request) -> Result<Response, Error> {
13    let state_dir = ctx.filesystem.state_dir();
14    let socket_request = SocketRequest::CallTool(request.params);
15    let response: SocketResponse<Response> =
16        call_socket(&state_dir, &request.response_id, &socket_request)
17            .await
18            .map_err(|e| Error::Instance(format!("mcp socket: {e}")))?;
19    match response {
20        SocketResponse::Ok(result) => Ok(result),
21        SocketResponse::Err(e) => {
22            Err(Error::Instance(format!("mcp error {}: {}", e.code, e.message)))
23        }
24    }
25}
26
27pub mod request_schema {
28    use objectiveai_sdk::cli::command::agents::tools::call as sdk;
29    use objectiveai_sdk::cli::command::agents::tools::call::request_schema::{
30        Request, Response,
31    };
32
33    use crate::context::Context;
34    use crate::error::Error;
35
36    pub async fn execute(_ctx: &Context, _request: Request) -> Result<Response, Error> {
37        Ok(objectiveai_sdk::cli::command::ResponseSchema(
38            schemars::schema_for!(sdk::Request),
39        ))
40    }
41}
42
43pub mod response_schema {
44    use objectiveai_sdk::cli::command::agents::tools::call as sdk;
45    use objectiveai_sdk::cli::command::agents::tools::call::response_schema::{
46        Request, Response,
47    };
48
49    use crate::context::Context;
50    use crate::error::Error;
51
52    pub async fn execute(_ctx: &Context, _request: Request) -> Result<Response, Error> {
53        Ok(objectiveai_sdk::cli::command::ResponseSchema(
54            schemars::schema_for!(sdk::Response),
55        ))
56    }
57}