Skip to main content

objectiveai_sdk/cli/command/mcp/config/get/
mod.rs

1//! `config mcp get` — async handler stub.
2
3use 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 into_command(&self) -> Vec<String> {
23        let mut argv = vec!["mcp".to_string(), "config".to_string(), "get".to_string()];
24        argv.push(match self.scope {
25            crate::cli::command::GetScope::Global => "--global".to_string(),
26            crate::cli::command::GetScope::State => "--state".to_string(),
27            crate::cli::command::GetScope::Final => "--final".to_string(),
28        });
29        self.base.push_flags(&mut argv);
30        argv
31    }
32
33    fn request_base(&self) -> &crate::cli::command::RequestBase {
34        &self.base
35    }
36
37    fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
38        Some(&mut self.base)
39    }
40}
41
42#[derive(PartialEq, Debug, Clone, Default, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
43#[schemars(rename = "cli.command.mcp.config.get.Response")]
44pub struct Response {
45    #[serde(skip_serializing_if = "Option::is_none")]
46    #[schemars(extend("omitempty" = true))]
47    pub address: Option<String>,
48    #[serde(skip_serializing_if = "Option::is_none")]
49    #[schemars(extend("omitempty" = true))]
50    pub port: Option<u16>,
51}
52
53#[derive(clap::Args)]
54pub struct Args {
55    /// Read the global config layer.
56    #[arg(long)]
57    pub global: bool,
58    /// Read the state config layer.
59    #[arg(long)]
60    pub state: bool,
61    /// Read the final merged config view.
62    #[arg(long)]
63    pub r#final: bool,
64    #[command(flatten)]
65    pub base: crate::cli::command::RequestBaseArgs,
66}
67
68#[derive(clap::Args)]
69#[command(args_conflicts_with_subcommands = true)]
70pub struct Command {
71    #[command(flatten)]
72    pub args: Args,
73    #[command(subcommand)]
74    pub schema: Option<Schema>,
75}
76
77#[derive(clap::Subcommand)]
78pub enum Schema {
79    /// Emit the JSON Schema for this leaf's `Request` type and exit.
80    RequestSchema(request_schema::Args),
81    /// Emit the JSON Schema for this leaf's `Response` type and exit.
82    ResponseSchema(response_schema::Args),
83}
84
85impl TryFrom<Args> for Request {
86    type Error = crate::cli::command::FromArgsError;
87    fn try_from(args: Args) -> Result<Self, Self::Error> {
88        let scope = match (args.global, args.state, args.r#final) {
89            (true, false, false) => crate::cli::command::GetScope::Global,
90            (false, true, false) => crate::cli::command::GetScope::State,
91            (false, false, true) => crate::cli::command::GetScope::Final,
92            _ => {
93                return Err(crate::cli::command::FromArgsError {
94                    field: "scope",
95                    source: crate::cli::command::FromArgsErrorSource::Plain(
96                        "exactly one of --global, --state, --final is required".to_string(),
97                    ),
98                });
99            }
100        };
101        Ok(Self { path_type: Path::McpConfigGet,
102            scope,
103            base: args.base.into(),
104        })
105    }
106}
107
108#[cfg(feature = "cli-executor")]
109pub async fn execute<E: crate::cli::command::CommandExecutor>(
110    executor: &E,
111    mut request: Request,
112
113        agent_arguments: Option<&crate::cli::command::AgentArguments>,
114    ) -> Result<Response, E::Error> {
115    request.base.clear_transform();
116    executor.execute_one(request, agent_arguments).await
117}
118
119#[cfg(feature = "cli-executor")]
120pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
121    executor: &E,
122    mut request: Request,
123    transform: crate::cli::command::Transform,
124
125        agent_arguments: Option<&crate::cli::command::AgentArguments>,
126    ) -> Result<serde_json::Value, E::Error> {
127    request.base.set_transform(transform);
128    executor.execute_one(request, agent_arguments).await
129}
130
131#[cfg(feature = "mcp")]
132impl crate::cli::command::CommandResponse for Response {
133    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
134        crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
135    }
136}
137
138pub mod request_schema;
139
140
141pub mod response_schema;