Skip to main content

objectiveai_sdk/cli/command/mcp/kill/
mod.rs

1//! `mcp kill` — 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.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 request_base(&self) -> &crate::cli::command::RequestBase {
22        &self.base
23    }
24
25    fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
26        Some(&mut self.base)
27    }
28}
29
30#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
31#[schemars(rename = "cli.command.mcp.kill.Response")]
32pub struct Response {
33    pub killed: usize,
34}
35
36#[derive(clap::Args)]
37pub struct Args {
38    /// Kill across all states.
39    #[arg(long)]
40    pub global: bool,
41    /// Kill only the current state.
42    #[arg(long)]
43    pub state: bool,
44    #[command(flatten)]
45    pub base: crate::cli::command::RequestBaseArgs,
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        let scope = match (args.global, args.state) {
69            (true, false) => crate::cli::command::SetScope::Global,
70            (false, true) => crate::cli::command::SetScope::State,
71            _ => {
72                return Err(crate::cli::command::FromArgsError {
73                    field: "scope",
74                    source: crate::cli::command::FromArgsErrorSource::Plain(
75                        "exactly one of --global, --state is required".to_string(),
76                    ),
77                });
78            }
79        };
80        Ok(Self { path_type: Path::McpKill, scope, base: args.base.into() })
81    }
82}
83
84#[cfg(feature = "cli-executor")]
85pub async fn execute<E: crate::cli::command::CommandExecutor>(
86    executor: &E,
87    mut request: Request,
88
89        agent_arguments: Option<&crate::cli::command::AgentArguments>,
90    ) -> Result<Response, E::Error> {
91    request.base.clear_transform();
92    executor.execute_one(request, agent_arguments).await
93}
94
95#[cfg(feature = "cli-executor")]
96pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
97    executor: &E,
98    mut request: Request,
99    transform: crate::cli::command::Transform,
100
101        agent_arguments: Option<&crate::cli::command::AgentArguments>,
102    ) -> Result<serde_json::Value, E::Error> {
103    request.base.set_transform(transform);
104    executor.execute_one(request, agent_arguments).await
105}
106
107#[cfg(feature = "mcp")]
108impl crate::cli::command::CommandResponse for Response {
109    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
110        crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
111    }
112}
113
114pub mod request_schema;
115
116pub mod response_schema;