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