Skip to main content

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

1//! `development plugins` — the development-mode registrations for
2//! plugins. One subgroup today, `mcp`, matching the manifest's own
3//! split: a plugin's MCP half and its viewer half are built
4//! independently and would be registered independently.
5
6use crate::cli::command::CommandRequest;
7
8pub mod mcp;
9
10#[derive(clap::Subcommand)]
11pub enum Command {
12    /// The MCP-server half.
13    Mcp {
14        #[command(subcommand)]
15        command: mcp::Command,
16    },
17}
18
19#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
20#[serde(untagged)]
21#[schemars(rename = "cli.command.development.plugins.Request")]
22pub enum Request {
23    // NOTE: no variant-level `#[schemars(title)]`. Single-variant enum
24    // — schemars collapses it to the lone variant's schema and HOISTS
25    // that title over the type's `rename`, which the json-schema
26    // builder rejects as a title changing during normalization. Same
27    // reason as `agent.script.Script` / `ClientLaboratoryType`.
28    Mcp(mcp::Request),
29}
30
31// Exempt from json-schema coverage: tier aggregate (see the root
32// `ResponseItem` in command.rs - TS7056).
33#[objectiveai_sdk_macros::json_schema_ignore]
34#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
35#[schemars(rename = "cli.command.development.plugins.ResponseItem")]
36#[serde(untagged)]
37pub enum ResponseItem {
38    #[schemars(title = "Mcp")]
39    Mcp(mcp::ResponseItem),
40}
41
42#[cfg(feature = "mcp")]
43impl crate::cli::command::CommandResponse for ResponseItem {
44    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
45        match self {
46            ResponseItem::Mcp(v) => v.into_mcp(),
47        }
48    }
49}
50
51impl TryFrom<Command> for Request {
52    type Error = crate::cli::command::FromArgsError;
53    fn try_from(command: Command) -> Result<Self, Self::Error> {
54        match command {
55            Command::Mcp { command } => Ok(Request::Mcp(mcp::Request::try_from(command)?)),
56        }
57    }
58}
59
60impl CommandRequest for Request {
61    fn request_base(&self) -> &crate::cli::command::RequestBase {
62        match self {
63            Request::Mcp(inner) => inner.request_base(),
64        }
65    }
66
67    fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
68        match self {
69            Request::Mcp(inner) => inner.request_base_mut(),
70        }
71    }
72}
73
74#[cfg(feature = "cli-executor")]
75pub async fn execute<E: crate::cli::command::CommandExecutor>(
76    executor: &E,
77    request: Request,
78    identity: Option<&crate::identity::Identity>,
79) -> Result<
80    std::pin::Pin<Box<dyn futures::Stream<Item = Result<ResponseItem, E::Error>> + Send>>,
81    E::Error,
82> {
83    use futures::StreamExt;
84    let stream: std::pin::Pin<
85        Box<dyn futures::Stream<Item = Result<ResponseItem, E::Error>> + Send>,
86    > = match request {
87        Request::Mcp(req) => {
88            let inner = mcp::execute(executor, req, identity).await?;
89            Box::pin(inner.map(|r| r.map(ResponseItem::Mcp)))
90        }
91    };
92    Ok(stream)
93}
94
95#[cfg(feature = "cli-executor")]
96pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
97    executor: &E,
98    request: Request,
99    transform: crate::cli::command::Transform,
100    identity: Option<&crate::identity::Identity>,
101) -> Result<
102    std::pin::Pin<Box<dyn futures::Stream<Item = Result<serde_json::Value, E::Error>> + Send>>,
103    E::Error,
104> {
105    let stream: std::pin::Pin<
106        Box<dyn futures::Stream<Item = Result<serde_json::Value, E::Error>> + Send>,
107    > = match request {
108        Request::Mcp(req) => {
109            let inner = mcp::execute_transform(executor, req, transform, identity).await?;
110            Box::pin(inner)
111        }
112    };
113    Ok(stream)
114}
115
116/// `/listen` mirror of [`Request`]. See [`crate::daemon::command_listener`].
117#[cfg(all(feature = "cli", feature = "daemon"))]
118pub enum ListenerExecution {
119    Mcp(mcp::ListenerExecution),
120}