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