Skip to main content

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

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