objectiveai_sdk/cli/command/agents/mcp/tools/call/
mod.rs1use crate::cli::command::CommandRequest;
6
7#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
8#[schemars(rename = "cli.command.agents.mcp.tools.call.Request")]
9pub struct Request {
10 pub path_type: Path,
11 pub response_id: String,
12 pub params: crate::mcp::tool::CallToolRequestParams,
13 #[serde(flatten)]
14 pub base: crate::cli::command::RequestBase,
15}
16
17#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
18#[schemars(rename = "cli.command.agents.mcp.tools.call.Path")]
19pub enum Path {
20 #[serde(rename = "agents/mcp/tools/call")]
21 AgentsMcpToolsCall,
22}
23
24impl CommandRequest for Request {
25 fn request_base(&self) -> &crate::cli::command::RequestBase {
26 &self.base
27 }
28
29 fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
30 Some(&mut self.base)
31 }
32}
33
34pub type Response = crate::mcp::tool::CallToolResult;
35
36#[derive(clap::Args)]
37#[command(group(clap::ArgGroup::new("response_id_required").required(true).args(["response_id"])))]
38#[command(group(clap::ArgGroup::new("params_required").required(true).args(["params"])))]
39pub struct Args {
40 #[arg(long)]
43 pub response_id: Option<String>,
44 #[arg(long)]
47 pub params: Option<String>,
48 #[command(flatten)]
49 pub base: crate::cli::command::RequestBaseArgs,
50}
51
52#[derive(clap::Args)]
53#[command(args_conflicts_with_subcommands = true)]
54pub struct Command {
55 #[command(flatten)]
56 pub args: Args,
57 #[command(subcommand)]
58 pub schema: Option<Schema>,
59}
60
61#[derive(clap::Subcommand)]
62pub enum Schema {
63 RequestSchema(request_schema::Args),
65 ResponseSchema(response_schema::Args),
67}
68
69impl TryFrom<Args> for Request {
70 type Error = crate::cli::command::FromArgsError;
71 fn try_from(args: Args) -> Result<Self, Self::Error> {
72 let response_id = args.response_id.ok_or_else(|| {
73 crate::cli::command::FromArgsError::path_parse(
74 "response_id",
75 "--response-id is required".to_string(),
76 )
77 })?;
78 let params = {
79 let s = args.params.ok_or_else(|| {
80 crate::cli::command::FromArgsError::path_parse(
81 "params",
82 "--params is required".to_string(),
83 )
84 })?;
85 let mut de = serde_json::Deserializer::from_str(&s);
86 serde_path_to_error::deserialize(&mut de)
87 .map_err(|source| crate::cli::command::FromArgsError {
88 field: "params",
89 source: source.into(),
90 })?
91 };
92 Ok(Self {
93 path_type: Path::AgentsMcpToolsCall,
94 response_id,
95 params,
96 base: args.base.into(),
97 })
98 }
99}
100
101#[cfg(feature = "cli-executor")]
102pub async fn execute<E: crate::cli::command::CommandExecutor>(
103 executor: &E,
104 mut request: Request,
105 agent_arguments: Option<&crate::cli::command::AgentArguments>,
106) -> Result<Response, E::Error> {
107 request.base.clear_transform();
108 executor.execute_one(request, agent_arguments).await
109}
110
111#[cfg(feature = "cli-executor")]
112pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
113 executor: &E,
114 mut request: Request,
115 transform: crate::cli::command::Transform,
116 agent_arguments: Option<&crate::cli::command::AgentArguments>,
117) -> Result<serde_json::Value, E::Error> {
118 request.base.set_transform(transform);
119 executor.execute_one(request, agent_arguments).await
120}
121
122#[cfg(feature = "mcp")]
123impl crate::cli::command::CommandResponse for Response {
124 fn into_mcp(self) -> crate::cli::command::McpResponseItem {
125 crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
126 }
127}
128
129pub mod request_schema;
130
131pub mod response_schema;