objectiveai_sdk/cli/command/development/plugins/mcp/create/
mod.rs1use 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 pub owner: String,
24 pub name: String,
26 pub version: String,
30 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#[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 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 #[arg(long)]
80 pub owner: Option<String>,
81 #[arg(long)]
83 pub name: Option<String>,
84 #[arg(long)]
86 pub version: Option<String>,
87 #[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 RequestSchema(request_schema::Args),
107 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#[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}