Skip to main content

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

1//! `development plugins mcp create` — point a plugin's coordinates at
2//! a local directory, so the laboratory host builds its image from
3//! that tree instead of fetching the version's git tag.
4//!
5//! The registration lives IN THE RESIDENT DAEMON's memory and nowhere
6//! else — no database, no file. It is a developer's session state, and
7//! surviving a daemon restart would mean a stale registration silently
8//! outliving the work it was for.
9//!
10//! Registering also pins the plugin to the LOCAL laboratory host: the
11//! directory is a path on this machine, so no other host could build
12//! from it.
13
14use crate::cli::command::CommandRequest;
15
16#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
17#[schemars(rename = "cli.command.development.plugins.mcp.create.Request")]
18pub struct Request {
19    pub path_type: Path,
20    /// GitHub `<owner>` segment, lowercased on arrival — the
21    /// declaration layer lowercases it too, so the registration and an
22    /// agent's `plugin` entry agree.
23    pub owner: String,
24    /// Repository segment, likewise lowercased.
25    pub name: String,
26    /// Plugin version — matched byte-for-byte against what an agent
27    /// declares. It is the git tag everywhere else, and stays
28    /// case-sensitive here even though nothing is fetched.
29    pub version: String,
30    /// ABSOLUTE path to the plugin's source directory: the one holding
31    /// `objectiveai.json`. Absolute because the laboratory host
32    /// resolves it, and its working directory is not yours.
33    pub path: String,
34    #[serde(flatten)]
35    pub base: crate::cli::command::RequestBase,
36}
37
38#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
39#[schemars(rename = "cli.command.development.plugins.mcp.create.Path")]
40pub enum Path {
41    #[serde(rename = "development/plugins/mcp/create")]
42    DevelopmentPluginsMcpCreate,
43}
44
45impl CommandRequest for Request {
46    fn request_base(&self) -> &crate::cli::command::RequestBase {
47        &self.base
48    }
49
50    fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
51        Some(&mut self.base)
52    }
53}
54
55/// The registration, echoed with the coordinates as the daemon
56/// canonicalized them — which is what an agent's declaration will be
57/// matched against, so it is worth seeing.
58#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
59#[schemars(rename = "cli.command.development.plugins.mcp.create.Response")]
60pub struct Response {
61    pub owner: String,
62    pub name: String,
63    pub version: String,
64    pub path: String,
65    /// Whether this REPLACED an existing registration for the same
66    /// coordinates. Worth reporting: re-registering a different
67    /// directory is silent otherwise, and the image built from the old
68    /// one is still tagged until the next create rebuilds it.
69    pub replaced: bool,
70}
71
72#[derive(clap::Args)]
73#[command(group(clap::ArgGroup::new("owner_required").required(true).args(["owner"])))]
74#[command(group(clap::ArgGroup::new("name_required").required(true).args(["name"])))]
75#[command(group(clap::ArgGroup::new("version_required").required(true).args(["version"])))]
76#[command(group(clap::ArgGroup::new("path_required").required(true).args(["path"])))]
77pub struct Args {
78    /// GitHub <owner> segment.
79    #[arg(long)]
80    pub owner: Option<String>,
81    /// Repository segment.
82    #[arg(long)]
83    pub name: Option<String>,
84    /// Plugin version, exactly as an agent declares it (v-prefixed).
85    #[arg(long)]
86    pub version: Option<String>,
87    /// Absolute path to the directory holding objectiveai.json.
88    #[arg(long)]
89    pub path: Option<String>,
90    #[command(flatten)]
91    pub base: crate::cli::command::RequestBaseArgs,
92}
93
94#[derive(clap::Args)]
95#[command(args_conflicts_with_subcommands = true)]
96pub struct Command {
97    #[command(flatten)]
98    pub args: Args,
99    #[command(subcommand)]
100    pub schema: Option<Schema>,
101}
102
103#[derive(clap::Subcommand)]
104pub enum Schema {
105    /// Emit the JSON Schema for this leaf's `Request` type and exit.
106    RequestSchema(request_schema::Args),
107    /// Emit the JSON Schema for this leaf's `Response` type and exit.
108    ResponseSchema(response_schema::Args),
109}
110
111impl TryFrom<Args> for Request {
112    type Error = crate::cli::command::FromArgsError;
113    fn try_from(args: Args) -> Result<Self, Self::Error> {
114        let owner = args.owner.ok_or_else(|| {
115            crate::cli::command::FromArgsError::path_parse(
116                "owner",
117                "--owner is required".to_string(),
118            )
119        })?;
120        let name = args.name.ok_or_else(|| {
121            crate::cli::command::FromArgsError::path_parse(
122                "name",
123                "--name is required".to_string(),
124            )
125        })?;
126        let version = args.version.ok_or_else(|| {
127            crate::cli::command::FromArgsError::path_parse(
128                "version",
129                "--version is required".to_string(),
130            )
131        })?;
132        let path = args.path.ok_or_else(|| {
133            crate::cli::command::FromArgsError::path_parse(
134                "path",
135                "--path is required".to_string(),
136            )
137        })?;
138        Ok(Self {
139            path_type: Path::DevelopmentPluginsMcpCreate,
140            owner,
141            name,
142            version,
143            path,
144            base: args.base.into(),
145        })
146    }
147}
148
149#[cfg(feature = "mcp")]
150impl crate::cli::command::CommandResponse for Response {
151    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
152        crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
153    }
154}
155
156#[cfg(feature = "cli-executor")]
157pub async fn execute<E: crate::cli::command::CommandExecutor>(
158    executor: &E,
159    mut request: Request,
160    identity: Option<&crate::identity::Identity>,
161) -> Result<Response, E::Error> {
162    request.base.clear_transform();
163    executor.execute_one(request, identity).await
164}
165
166#[cfg(feature = "cli-executor")]
167pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
168    executor: &E,
169    mut request: Request,
170    transform: crate::cli::command::Transform,
171    identity: Option<&crate::identity::Identity>,
172) -> Result<serde_json::Value, E::Error> {
173    request.base.set_transform(transform);
174    executor.execute_one(request, identity).await
175}
176
177pub mod request_schema;
178
179pub mod response_schema;
180
181/// One `/listen` broadcast run of `development plugins mcp create`.
182/// See [`crate::daemon::command_listener`].
183#[cfg(all(feature = "cli", feature = "daemon"))]
184pub struct ListenerExecution {
185    pub request: Request,
186    pub identity: crate::identity::Identity,
187    pub response: crate::daemon::command_listener::UnaryResponse<Response>,
188}