Skip to main content

objectiveai_sdk/cli/command/tools/get/
mod.rs

1//! `tools get` — 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.tools.get.Request")]
7pub struct Request {
8    pub path_type: Path,
9    pub owner: String,
10    pub name: String,
11    pub version: String,
12    #[serde(flatten)]
13    pub base: crate::cli::command::RequestBase,
14}
15
16#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
17#[schemars(rename = "cli.command.tools.get.Path")]
18pub enum Path {
19    #[serde(rename = "tools/get")]
20    ToolsGet,
21}
22
23impl CommandRequest for Request {
24    fn into_command(&self) -> Vec<String> {
25        let mut argv = vec![
26            "tools".to_string(),
27            "get".to_string(),
28            "--owner".to_string(),
29            self.owner.clone(),
30            "--name".to_string(),
31            self.name.clone(),
32            "--version".to_string(),
33            self.version.clone(),
34        ];
35        self.base.push_flags(&mut argv);
36        argv
37    }
38
39    fn request_base(&self) -> &crate::cli::command::RequestBase {
40        &self.base
41    }
42
43    fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
44        Some(&mut self.base)
45    }
46}
47
48/// Per-OS exec command for a tool. The current platform's vector is
49/// the program plus its leading arguments; the caller's `--args` are
50/// appended, and the result runs with CWD = the tool's version folder
51/// (where `objectiveai.json` lives).
52#[derive(Debug, Clone, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
53#[schemars(rename = "cli.command.tools.get.Exec")]
54pub struct Exec {
55    pub windows: Vec<String>,
56    pub linux: Vec<String>,
57    pub macos: Vec<String>,
58}
59
60impl Exec {
61    pub fn is_empty(&self) -> bool {
62        self.windows.is_empty() && self.linux.is_empty() && self.macos.is_empty()
63    }
64}
65
66#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
67#[schemars(rename = "cli.command.tools.get.ResponseManifest")]
68pub struct ResponseManifest {
69    pub name: String,
70    pub description: String,
71    pub version: String,
72    pub owner: String,
73    pub exec: Exec,
74    pub source: String,
75}
76
77impl ResponseManifest {
78    /// LLM-visible MCP tool name for this tool:
79    /// `tool_{owner}_{name}_{version}`, with every `.` in the version
80    /// substituted to `-` so the result stays within the Anthropic
81    /// tool-name regex (`^[a-zA-Z0-9_-]{1,128}$`). `objectiveai-mcp`
82    /// advertises each tool under this name.
83    pub fn tool_name(&self) -> String {
84        format!(
85            "tool_{}_{}_{}",
86            self.owner,
87            self.name,
88            self.version.replace('.', "-")
89        )
90    }
91}
92
93pub type Response = Option<ResponseManifest>;
94
95#[derive(clap::Args)]
96pub struct Args {
97    /// Tool owner (GitHub `<owner>` segment). Required.
98    #[arg(long)]
99    pub owner: String,
100    /// Tool name (repository segment). Required.
101    #[arg(long)]
102    pub name: String,
103    /// Tool version. Required.
104    #[arg(long)]
105    pub version: String,
106    #[command(flatten)]
107    pub base: crate::cli::command::RequestBaseArgs,
108}
109
110#[derive(clap::Args)]
111#[command(args_conflicts_with_subcommands = true)]
112pub struct Command {
113    #[command(flatten)]
114    pub args: Args,
115    #[command(subcommand)]
116    pub schema: Option<Schema>,
117}
118
119#[derive(clap::Subcommand)]
120pub enum Schema {
121    /// Emit the JSON Schema for this leaf's `Request` type and exit.
122    RequestSchema(request_schema::Args),
123    /// Emit the JSON Schema for this leaf's `Response` type and exit.
124    ResponseSchema(response_schema::Args),
125}
126
127impl TryFrom<Args> for Request {
128    type Error = crate::cli::command::FromArgsError;
129    fn try_from(args: Args) -> Result<Self, Self::Error> {
130        Ok(Self {
131            path_type: Path::ToolsGet,
132            owner: args.owner,
133            name: args.name,
134            version: args.version,
135            base: args.base.into(),
136        })
137    }
138}
139
140#[cfg(feature = "cli-executor")]
141pub async fn execute<E: crate::cli::command::CommandExecutor>(
142    executor: &E,
143    mut request: Request,
144
145        agent_arguments: Option<&crate::cli::command::AgentArguments>,
146    ) -> Result<Response, E::Error> {
147    request.base.clear_transform();
148    executor.execute_one(request, agent_arguments).await
149}
150
151#[cfg(feature = "cli-executor")]
152pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
153    executor: &E,
154    mut request: Request,
155    transform: crate::cli::command::Transform,
156
157        agent_arguments: Option<&crate::cli::command::AgentArguments>,
158    ) -> Result<serde_json::Value, E::Error> {
159    request.base.set_transform(transform);
160    executor.execute_one(request, agent_arguments).await
161}
162
163#[cfg(feature = "mcp")]
164impl crate::cli::command::CommandResponse for ResponseManifest {
165    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
166        crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
167    }
168}
169
170pub mod request_schema;
171
172
173pub mod response_schema;