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