Skip to main content

objectiveai_sdk/cli/command/config/mcp/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.config.mcp.get.Request")]
7pub struct Request {
8    pub path_type: Path,
9    pub filter: Option<String>,
10    pub jq: Option<String>,
11}
12
13#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
14#[schemars(rename = "cli.command.config.mcp.get.Path")]
15pub enum Path {
16    #[serde(rename = "config/mcp/get")]
17    ConfigMcpGet,
18}
19
20impl CommandRequest for Request {
21    fn into_command(&self) -> Vec<String> {
22        let mut argv = vec!["config".to_string(), "mcp".to_string(), "get".to_string()];
23        if let Some(filter) = &self.filter {
24            argv.push(filter.clone());
25        }
26        if let Some(jq) = &self.jq {
27            argv.push("--jq".to_string());
28            argv.push(jq.clone());
29        }
30        argv
31    }
32}
33
34#[derive(PartialEq, Debug, Clone, Default, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
35#[schemars(rename = "cli.command.config.mcp.get.Response")]
36pub struct Response {
37    #[serde(skip_serializing_if = "Option::is_none")]
38    #[schemars(extend("omitempty" = true))]
39    pub address: Option<String>,
40    #[serde(skip_serializing_if = "Option::is_none")]
41    #[schemars(extend("omitempty" = true))]
42    pub port: Option<u16>,
43}
44
45#[derive(clap::Args)]
46pub struct Args {
47    /// Optional path filter into the config tree.
48    pub filter: Option<String>,
49    /// jq filter applied to the JSON output.
50    #[arg(long)]
51    pub jq: Option<String>,
52}
53
54#[derive(clap::Args)]
55#[command(args_conflicts_with_subcommands = true)]
56pub struct Command {
57    #[command(flatten)]
58    pub args: Args,
59    #[command(subcommand)]
60    pub schema: Option<Schema>,
61}
62
63#[derive(clap::Subcommand)]
64pub enum Schema {
65    /// Emit the JSON Schema for this leaf's `Request` type and exit.
66    RequestSchema(request_schema::Args),
67    /// Emit the JSON Schema for this leaf's `Response` type and exit.
68    ResponseSchema(response_schema::Args),
69}
70
71impl TryFrom<Args> for Request {
72    type Error = crate::cli::command::FromArgsError;
73    fn try_from(args: Args) -> Result<Self, Self::Error> {
74        Ok(Self { path_type: Path::ConfigMcpGet,
75            filter: args.filter,
76            jq: args.jq,
77        })
78    }
79}
80
81#[cfg(feature = "cli-executor")]
82pub async fn execute<E: crate::cli::command::CommandExecutor>(
83    executor: &E,
84    mut request: Request,
85
86        agent_arguments: Option<&crate::cli::command::AgentArguments>,
87    ) -> Result<Response, E::Error> {
88    request.jq = None;
89    executor.execute_one(request, agent_arguments).await
90}
91
92#[cfg(feature = "cli-executor")]
93pub async fn execute_jq<E: crate::cli::command::CommandExecutor>(
94    executor: &E,
95    mut request: Request,
96    jq: String,
97
98        agent_arguments: Option<&crate::cli::command::AgentArguments>,
99    ) -> Result<serde_json::Value, E::Error> {
100    request.jq = Some(jq);
101    executor.execute_one(request, agent_arguments).await
102}
103
104#[cfg(feature = "mcp")]
105impl crate::cli::command::CommandResponse for Response {
106    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
107        crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
108    }
109}
110
111pub mod request_schema;
112
113
114pub mod response_schema;