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    #[serde(flatten)]
10    pub base: crate::cli::command::RequestBase,
11}
12
13#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
14#[schemars(rename = "cli.command.mcp.config.port.get.Path")]
15pub enum Path {
16    #[serde(rename = "mcp/config/port/get")]
17    McpConfigPortGet,
18}
19
20impl CommandRequest for Request {
21    fn request_base(&self) -> &crate::cli::command::RequestBase {
22        &self.base
23    }
24
25    fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
26        Some(&mut self.base)
27    }
28}
29
30#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
31#[schemars(rename = "cli.command.mcp.config.port.get.Response")]
32pub struct Response {
33    pub port: u16,
34}
35
36#[derive(clap::Args)]
37pub struct Args {
38    #[command(flatten)]
39    pub base: crate::cli::command::RequestBaseArgs,
40}
41
42#[derive(clap::Args)]
43#[command(args_conflicts_with_subcommands = true)]
44pub struct Command {
45    #[command(flatten)]
46    pub args: Args,
47    #[command(subcommand)]
48    pub schema: Option<Schema>,
49}
50
51#[derive(clap::Subcommand)]
52pub enum Schema {
53    /// Emit the JSON Schema for this leaf's `Request` type and exit.
54    RequestSchema(request_schema::Args),
55    /// Emit the JSON Schema for this leaf's `Response` type and exit.
56    ResponseSchema(response_schema::Args),
57}
58
59impl TryFrom<Args> for Request {
60    type Error = crate::cli::command::FromArgsError;
61    fn try_from(args: Args) -> Result<Self, Self::Error> {
62        Ok(Self { path_type: Path::McpConfigPortGet,
63            base: args.base.into(),
64        })
65    }
66}
67
68#[cfg(feature = "cli-executor")]
69pub async fn execute<E: crate::cli::command::CommandExecutor>(
70    executor: &E,
71    mut request: Request,
72
73        agent_arguments: Option<&crate::cli::command::AgentArguments>,
74    ) -> Result<Response, E::Error> {
75    request.base.clear_transform();
76    executor.execute_one(request, agent_arguments).await
77}
78
79#[cfg(feature = "cli-executor")]
80pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
81    executor: &E,
82    mut request: Request,
83    transform: crate::cli::command::Transform,
84
85        agent_arguments: Option<&crate::cli::command::AgentArguments>,
86    ) -> Result<serde_json::Value, E::Error> {
87    request.base.set_transform(transform);
88    executor.execute_one(request, agent_arguments).await
89}
90
91#[cfg(feature = "mcp")]
92impl crate::cli::command::CommandResponse for Response {
93    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
94        crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
95    }
96}
97
98pub mod request_schema;
99
100pub mod response_schema;
101
102/// One `/listen` broadcast run of `mcp config port get`: the actual
103/// [`Request`], the producer's
104/// [`AgentArguments`](crate::cli::command::AgentArguments), and the
105/// unary response future. See [`crate::cli::broadcast_listener`].
106#[cfg(feature = "cli-listener")]
107pub struct ListenerExecution {
108    pub request: Request,
109    pub agent_arguments: crate::cli::command::AgentArguments,
110    pub response: crate::cli::broadcast_listener::UnaryResponse<Response>,
111}