Skip to main content

objectiveai_sdk/cli/command/development/plugins/mcp/delete/
mod.rs

1//! `development plugins mcp delete` — drop a development
2//! registration, so the plugin goes back to being fetched at its git
3//! tag.
4//!
5//! The image built from the local directory is NOT removed, and does
6//! not need to be: it carries the source directory as a label, so the
7//! next create sees the mismatch and rebuilds from git on its own. Run
8//! `reset` as well only to reclaim the disk.
9
10use crate::cli::command::CommandRequest;
11
12#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
13#[schemars(rename = "cli.command.development.plugins.mcp.delete.Request")]
14pub struct Request {
15    pub path_type: Path,
16    /// GitHub `<owner>` segment, lowercased on arrival.
17    pub owner: String,
18    /// Repository segment, likewise lowercased.
19    pub name: String,
20    /// Plugin version, matched byte-for-byte.
21    pub version: String,
22    #[serde(flatten)]
23    pub base: crate::cli::command::RequestBase,
24}
25
26#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
27#[schemars(rename = "cli.command.development.plugins.mcp.delete.Path")]
28pub enum Path {
29    #[serde(rename = "development/plugins/mcp/delete")]
30    DevelopmentPluginsMcpDelete,
31}
32
33impl CommandRequest for Request {
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
43/// The coordinates, echoed as canonicalized.
44#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
45#[schemars(rename = "cli.command.development.plugins.mcp.delete.Response")]
46pub struct Response {
47    pub owner: String,
48    pub name: String,
49    pub version: String,
50    /// Whether a registration was actually removed. Deleting one that
51    /// was never registered is a SUCCESS with `false` — the requested
52    /// state ("this plugin is not in development mode") already holds.
53    pub removed: bool,
54}
55
56#[derive(clap::Args)]
57#[command(group(clap::ArgGroup::new("owner_required").required(true).args(["owner"])))]
58#[command(group(clap::ArgGroup::new("name_required").required(true).args(["name"])))]
59#[command(group(clap::ArgGroup::new("version_required").required(true).args(["version"])))]
60pub struct Args {
61    /// GitHub <owner> segment.
62    #[arg(long)]
63    pub owner: Option<String>,
64    /// Repository segment.
65    #[arg(long)]
66    pub name: Option<String>,
67    /// Plugin version, exactly as it was registered.
68    #[arg(long)]
69    pub version: Option<String>,
70    #[command(flatten)]
71    pub base: crate::cli::command::RequestBaseArgs,
72}
73
74#[derive(clap::Args)]
75#[command(args_conflicts_with_subcommands = true)]
76pub struct Command {
77    #[command(flatten)]
78    pub args: Args,
79    #[command(subcommand)]
80    pub schema: Option<Schema>,
81}
82
83#[derive(clap::Subcommand)]
84pub enum Schema {
85    /// Emit the JSON Schema for this leaf's `Request` type and exit.
86    RequestSchema(request_schema::Args),
87    /// Emit the JSON Schema for this leaf's `Response` type and exit.
88    ResponseSchema(response_schema::Args),
89}
90
91impl TryFrom<Args> for Request {
92    type Error = crate::cli::command::FromArgsError;
93    fn try_from(args: Args) -> Result<Self, Self::Error> {
94        let owner = args.owner.ok_or_else(|| {
95            crate::cli::command::FromArgsError::path_parse(
96                "owner",
97                "--owner is required".to_string(),
98            )
99        })?;
100        let name = args.name.ok_or_else(|| {
101            crate::cli::command::FromArgsError::path_parse(
102                "name",
103                "--name is required".to_string(),
104            )
105        })?;
106        let version = args.version.ok_or_else(|| {
107            crate::cli::command::FromArgsError::path_parse(
108                "version",
109                "--version is required".to_string(),
110            )
111        })?;
112        Ok(Self {
113            path_type: Path::DevelopmentPluginsMcpDelete,
114            owner,
115            name,
116            version,
117            base: args.base.into(),
118        })
119    }
120}
121
122#[cfg(feature = "mcp")]
123impl crate::cli::command::CommandResponse for Response {
124    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
125        crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
126    }
127}
128
129#[cfg(feature = "cli-executor")]
130pub async fn execute<E: crate::cli::command::CommandExecutor>(
131    executor: &E,
132    mut request: Request,
133    identity: Option<&crate::identity::Identity>,
134) -> Result<Response, E::Error> {
135    request.base.clear_transform();
136    executor.execute_one(request, identity).await
137}
138
139#[cfg(feature = "cli-executor")]
140pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
141    executor: &E,
142    mut request: Request,
143    transform: crate::cli::command::Transform,
144    identity: Option<&crate::identity::Identity>,
145) -> Result<serde_json::Value, E::Error> {
146    request.base.set_transform(transform);
147    executor.execute_one(request, identity).await
148}
149
150pub mod request_schema;
151
152pub mod response_schema;
153
154/// One `/listen` broadcast run of `development plugins mcp delete`.
155/// See [`crate::daemon::command_listener`].
156#[cfg(all(feature = "cli", feature = "daemon"))]
157pub struct ListenerExecution {
158    pub request: Request,
159    pub identity: crate::identity::Identity,
160    pub response: crate::daemon::command_listener::UnaryResponse<Response>,
161}