Skip to main content

objectiveai_sdk/cli/command/api/config/mcp_authorization/add/
mod.rs

1//! `config api mcp-authorization add` — 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.api.config.mcp_authorization.add.Request")]
7pub struct Request {
8    pub path_type: Path,
9    #[serde(flatten)]
10    pub base: crate::cli::command::RequestBase,
11    pub scope: crate::cli::command::SetScope,
12    pub key: String,
13    pub value: String,
14}
15
16#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
17#[schemars(rename = "cli.command.api.config.mcp_authorization.add.Path")]
18pub enum Path {
19    #[serde(rename = "api/config/mcp_authorization/add")]
20    ApiConfigMcpAuthorizationAdd,
21}
22
23impl CommandRequest for Request {
24    fn into_command(&self) -> Vec<String> {
25        let mut argv = vec!["api".to_string(), "config".to_string(), "mcp-authorization".to_string(), "add".to_string(), self.key.clone(), self.value.clone()];
26        argv.push(match self.scope {
27            crate::cli::command::SetScope::Global => "--global".to_string(),
28            crate::cli::command::SetScope::State => "--state".to_string(),
29        });
30        self.base.push_flags(&mut argv);
31        argv
32    }
33
34    fn request_base(&self) -> &crate::cli::command::RequestBase {
35        &self.base
36    }
37
38    fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
39        Some(&mut self.base)
40    }
41}
42
43pub type Response = crate::cli::command::Ok;
44
45#[derive(clap::Args)]
46pub struct Args {
47    /// Mutate the global config layer.
48    #[arg(long)]
49    pub global: bool,
50    /// Mutate the state config layer.
51    #[arg(long)]
52    pub state: bool,
53    #[command(flatten)]
54    pub base: crate::cli::command::RequestBaseArgs,
55    /// Entry key (MCP server name).
56    pub key: String,
57    /// Entry value (authorization token).
58    pub value: String,
59}
60
61#[derive(clap::Args)]
62#[command(args_conflicts_with_subcommands = true)]
63pub struct Command {
64    #[command(flatten)]
65    pub args: Args,
66    #[command(subcommand)]
67    pub schema: Option<Schema>,
68}
69
70#[derive(clap::Subcommand)]
71pub enum Schema {
72    /// Emit the JSON Schema for this leaf's `Request` type and exit.
73    RequestSchema(request_schema::Args),
74    /// Emit the JSON Schema for this leaf's `Response` type and exit.
75    ResponseSchema(response_schema::Args),
76}
77
78impl TryFrom<Args> for Request {
79    type Error = crate::cli::command::FromArgsError;
80    fn try_from(args: Args) -> Result<Self, Self::Error> {
81        let scope = match (args.global, args.state) {
82            (true, false) => crate::cli::command::SetScope::Global,
83            (false, true) => crate::cli::command::SetScope::State,
84            _ => {
85                return Err(crate::cli::command::FromArgsError {
86                    field: "scope",
87                    source: crate::cli::command::FromArgsErrorSource::Plain(
88                        "exactly one of --global, --state is required".to_string(),
89                    ),
90                });
91            }
92        };
93        Ok(Self {
94            base: args.base.into(), path_type: Path::ApiConfigMcpAuthorizationAdd,
95            scope,
96            key: args.key,
97            value: args.value,
98        })
99    }
100}
101
102#[cfg(feature = "cli-executor")]
103pub async fn execute<E: crate::cli::command::CommandExecutor>(
104    executor: &E,
105    request: Request,
106
107        agent_arguments: Option<&crate::cli::command::AgentArguments>,
108    ) -> Result<Response, E::Error> {
109    executor.execute_one(request, agent_arguments).await
110}
111
112pub mod request_schema;
113
114
115pub mod response_schema;
116
117#[cfg(feature = "cli-executor")]
118pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
119    executor: &E,
120    request: Request,
121    _transform: crate::cli::command::Transform,
122
123        agent_arguments: Option<&crate::cli::command::AgentArguments>,
124    ) -> Result<serde_json::Value, E::Error> {
125    let resp: Response = executor.execute_one(request, agent_arguments).await?;
126    Ok(serde_json::to_value(resp).expect("Response serializes"))
127}