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 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(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
32#[schemars(rename = "cli.command.mcp.config.port.get.Response")]
33pub struct Response {
34    pub port: u16,
35}
36
37#[derive(clap::Args)]
38pub struct Args {
39    /// Read the global config layer.
40    #[arg(long)]
41    pub global: bool,
42    /// Read the state config layer.
43    #[arg(long)]
44    pub state: bool,
45    /// Read the final merged config view.
46    #[arg(long)]
47    pub r#final: bool,
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    /// Emit the JSON Schema for this leaf's `Request` type and exit.
64    RequestSchema(request_schema::Args),
65    /// Emit the JSON Schema for this leaf's `Response` type and exit.
66    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 scope = match (args.global, args.state, args.r#final) {
73            (true, false, false) => crate::cli::command::GetScope::Global,
74            (false, true, false) => crate::cli::command::GetScope::State,
75            (false, false, true) => crate::cli::command::GetScope::Final,
76            _ => {
77                return Err(crate::cli::command::FromArgsError {
78                    field: "scope",
79                    source: crate::cli::command::FromArgsErrorSource::Plain(
80                        "exactly one of --global, --state, --final is required".to_string(),
81                    ),
82                });
83            }
84        };
85        Ok(Self { path_type: Path::McpConfigPortGet,
86            scope,
87            base: args.base.into(),
88        })
89    }
90}
91
92#[cfg(feature = "cli-executor")]
93pub async fn execute<E: crate::cli::command::CommandExecutor>(
94    executor: &E,
95    mut request: Request,
96
97        agent_arguments: Option<&crate::cli::command::AgentArguments>,
98    ) -> Result<Response, E::Error> {
99    request.base.clear_transform();
100    executor.execute_one(request, agent_arguments).await
101}
102
103#[cfg(feature = "cli-executor")]
104pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
105    executor: &E,
106    mut request: Request,
107    transform: crate::cli::command::Transform,
108
109        agent_arguments: Option<&crate::cli::command::AgentArguments>,
110    ) -> Result<serde_json::Value, E::Error> {
111    request.base.set_transform(transform);
112    executor.execute_one(request, agent_arguments).await
113}
114
115#[cfg(feature = "mcp")]
116impl crate::cli::command::CommandResponse for Response {
117    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
118        crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
119    }
120}
121
122pub mod request_schema;
123
124
125pub mod response_schema;