Skip to main content

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

1//! `config mcp port set` — 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.set.Request")]
7pub struct Request {
8    pub path_type: Path,
9    #[serde(flatten)]
10    pub base: crate::cli::command::RequestBase,
11    pub value: u16,
12}
13
14#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
15#[schemars(rename = "cli.command.mcp.config.port.set.Path")]
16pub enum Path {
17    #[serde(rename = "mcp/config/port/set")]
18    McpConfigPortSet,
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
31pub type Response = crate::cli::command::Ok;
32
33#[derive(clap::Args)]
34#[command(group(clap::ArgGroup::new("value_required").required(true).args(["value"])))]
35pub struct Args {
36    #[command(flatten)]
37    pub base: crate::cli::command::RequestBaseArgs,
38    /// New port value.
39    #[arg(long)]
40    pub value: Option<u16>,
41}
42
43#[derive(clap::Args)]
44#[command(args_conflicts_with_subcommands = true)]
45pub struct Command {
46    #[command(flatten)]
47    pub args: Args,
48    #[command(subcommand)]
49    pub schema: Option<Schema>,
50}
51
52#[derive(clap::Subcommand)]
53pub enum Schema {
54    /// Emit the JSON Schema for this leaf's `Request` type and exit.
55    RequestSchema(request_schema::Args),
56    /// Emit the JSON Schema for this leaf's `Response` type and exit.
57    ResponseSchema(response_schema::Args),
58}
59
60impl TryFrom<Args> for Request {
61    type Error = crate::cli::command::FromArgsError;
62    fn try_from(args: Args) -> Result<Self, Self::Error> {
63        Ok(Self {
64            base: args.base.into(), path_type: Path::McpConfigPortSet,
65            value: args.value.ok_or_else(|| {
66                crate::cli::command::FromArgsError::path_parse(
67                    "value",
68                    "--value is required".to_string(),
69                )
70            })?,
71        })
72    }
73}
74
75#[cfg(feature = "cli-executor")]
76pub async fn execute<E: crate::cli::command::CommandExecutor>(
77    executor: &E,
78    request: Request,
79
80        agent_arguments: Option<&crate::cli::command::AgentArguments>,
81    ) -> Result<Response, E::Error> {
82    executor.execute_one(request, agent_arguments).await
83}
84
85pub mod request_schema;
86
87pub mod response_schema;
88
89#[cfg(feature = "cli-executor")]
90pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
91    executor: &E,
92    request: Request,
93    _transform: crate::cli::command::Transform,
94
95        agent_arguments: Option<&crate::cli::command::AgentArguments>,
96    ) -> Result<serde_json::Value, E::Error> {
97    let resp: Response = executor.execute_one(request, agent_arguments).await?;
98    Ok(serde_json::to_value(resp).expect("Response serializes"))
99}
100
101/// One `/listen` broadcast run of `mcp config port set`: the actual
102/// [`Request`], the producer's
103/// [`AgentArguments`](crate::cli::command::AgentArguments), and the
104/// unary response future. See [`crate::cli::broadcast_listener`].
105#[cfg(feature = "cli-listener")]
106pub struct ListenerExecution {
107    pub request: Request,
108    pub agent_arguments: crate::cli::command::AgentArguments,
109    pub response: crate::cli::broadcast_listener::UnaryResponse<Response>,
110}