objectiveai_sdk/cli/command/mcp/config/get/
mod.rs1use crate::cli::command::CommandRequest;
4
5#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
6#[schemars(rename = "cli.command.mcp.config.get.Request")]
7pub struct Request {
8 pub path_type: Path,
9 pub scope: crate::cli::command::GetScope,
10 #[serde(flatten)]
11 pub base: crate::cli::command::RequestBase,
12}
13
14#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
15#[schemars(rename = "cli.command.mcp.config.get.Path")]
16pub enum Path {
17 #[serde(rename = "mcp/config/get")]
18 McpConfigGet,
19}
20
21impl CommandRequest for Request {
22 fn request_base(&self) -> &crate::cli::command::RequestBase {
23 &self.base
24 }
25
26 fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
27 Some(&mut self.base)
28 }
29}
30
31#[derive(PartialEq, Debug, Clone, Default, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
32#[schemars(rename = "cli.command.mcp.config.get.Response")]
33pub struct Response {
34 #[serde(skip_serializing_if = "Option::is_none")]
35 #[schemars(extend("omitempty" = true))]
36 pub address: Option<String>,
37 #[serde(skip_serializing_if = "Option::is_none")]
38 #[schemars(extend("omitempty" = true))]
39 pub port: Option<u16>,
40}
41
42#[derive(clap::Args)]
43pub struct Args {
44 #[arg(long)]
46 pub global: bool,
47 #[arg(long)]
49 pub state: bool,
50 #[arg(long)]
52 pub r#final: bool,
53 #[command(flatten)]
54 pub base: crate::cli::command::RequestBaseArgs,
55}
56
57#[derive(clap::Args)]
58#[command(args_conflicts_with_subcommands = true)]
59pub struct Command {
60 #[command(flatten)]
61 pub args: Args,
62 #[command(subcommand)]
63 pub schema: Option<Schema>,
64}
65
66#[derive(clap::Subcommand)]
67pub enum Schema {
68 RequestSchema(request_schema::Args),
70 ResponseSchema(response_schema::Args),
72}
73
74impl TryFrom<Args> for Request {
75 type Error = crate::cli::command::FromArgsError;
76 fn try_from(args: Args) -> Result<Self, Self::Error> {
77 let scope = match (args.global, args.state, args.r#final) {
78 (true, false, false) => crate::cli::command::GetScope::Global,
79 (false, true, false) => crate::cli::command::GetScope::State,
80 (false, false, true) => crate::cli::command::GetScope::Final,
81 _ => {
82 return Err(crate::cli::command::FromArgsError {
83 field: "scope",
84 source: crate::cli::command::FromArgsErrorSource::Plain(
85 "exactly one of --global, --state, --final is required".to_string(),
86 ),
87 });
88 }
89 };
90 Ok(Self { path_type: Path::McpConfigGet,
91 scope,
92 base: args.base.into(),
93 })
94 }
95}
96
97#[cfg(feature = "cli-executor")]
98pub async fn execute<E: crate::cli::command::CommandExecutor>(
99 executor: &E,
100 mut request: Request,
101
102 agent_arguments: Option<&crate::cli::command::AgentArguments>,
103 ) -> Result<Response, E::Error> {
104 request.base.clear_transform();
105 executor.execute_one(request, agent_arguments).await
106}
107
108#[cfg(feature = "cli-executor")]
109pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
110 executor: &E,
111 mut request: Request,
112 transform: crate::cli::command::Transform,
113
114 agent_arguments: Option<&crate::cli::command::AgentArguments>,
115 ) -> Result<serde_json::Value, E::Error> {
116 request.base.set_transform(transform);
117 executor.execute_one(request, agent_arguments).await
118}
119
120#[cfg(feature = "mcp")]
121impl crate::cli::command::CommandResponse for Response {
122 fn into_mcp(self) -> crate::cli::command::McpResponseItem {
123 crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
124 }
125}
126
127pub mod request_schema;
128
129
130pub mod response_schema;