Skip to main content

objectiveai_sdk/cli/command/agents/mcp/tools/list/
mod.rs

1//! `agents mcp tools list` — run `tools/list` against the per-`response_id`
2//! MCP listener socket and return the MCP `ListToolsResult`. `--params`
3//! is the MCP `ListToolsRequest`, supplied as a JSON string (e.g.
4//! `{}` or `{"cursor":"..."}`).
5
6use crate::cli::command::CommandRequest;
7
8#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
9#[schemars(rename = "cli.command.agents.mcp.tools.list.Request")]
10pub struct Request {
11    pub path_type: Path,
12    pub response_id: String,
13    pub params: crate::mcp::tool::ListToolsRequest,
14    /// Restrict the listing to the single server with this name (the
15    /// routing prefix `agents mcp servers list` reports). `None` lists
16    /// every server.
17    #[serde(default, skip_serializing_if = "Option::is_none")]
18    #[schemars(extend("omitempty" = true))]
19    pub name: Option<String>,
20    #[serde(flatten)]
21    pub base: crate::cli::command::RequestBase,
22}
23
24#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
25#[schemars(rename = "cli.command.agents.mcp.tools.list.Path")]
26pub enum Path {
27    #[serde(rename = "agents/mcp/tools/list")]
28    AgentsMcpToolsList,
29}
30
31impl CommandRequest for Request {
32    fn request_base(&self) -> &crate::cli::command::RequestBase {
33        &self.base
34    }
35
36    fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
37        Some(&mut self.base)
38    }
39}
40
41pub type Response = crate::mcp::tool::ListToolsResult;
42
43#[derive(clap::Args)]
44#[command(group(clap::ArgGroup::new("response_id_required").required(true).args(["response_id"])))]
45#[command(group(clap::ArgGroup::new("params_required").required(true).args(["params"])))]
46pub struct Args {
47    /// Objectiveai response id of the live agent whose MCP aggregation
48    /// to query (the socket at `<state>/socks/<response_id>.sock`).
49    #[arg(long)]
50    pub response_id: Option<String>,
51    /// MCP `ListToolsRequest` as a JSON string, e.g. `{}` or
52    /// `{"cursor":"..."}`.
53    #[arg(long)]
54    pub params: Option<String>,
55    /// Restrict the listing to the single server with this name (the
56    /// routing prefix from `agents mcp servers list`). Omit to list all.
57    #[arg(long)]
58    pub name: Option<String>,
59    #[command(flatten)]
60    pub base: crate::cli::command::RequestBaseArgs,
61}
62
63#[derive(clap::Args)]
64#[command(args_conflicts_with_subcommands = true)]
65pub struct Command {
66    #[command(flatten)]
67    pub args: Args,
68    #[command(subcommand)]
69    pub schema: Option<Schema>,
70}
71
72#[derive(clap::Subcommand)]
73pub enum Schema {
74    /// Emit the JSON Schema for this leaf's `Request` type and exit.
75    RequestSchema(request_schema::Args),
76    /// Emit the JSON Schema for this leaf's `Response` type and exit.
77    ResponseSchema(response_schema::Args),
78}
79
80impl TryFrom<Args> for Request {
81    type Error = crate::cli::command::FromArgsError;
82    fn try_from(args: Args) -> Result<Self, Self::Error> {
83        let response_id = args.response_id.ok_or_else(|| {
84            crate::cli::command::FromArgsError::path_parse(
85                "response_id",
86                "--response-id is required".to_string(),
87            )
88        })?;
89        let params = {
90            let s = args.params.ok_or_else(|| {
91                crate::cli::command::FromArgsError::path_parse(
92                    "params",
93                    "--params is required".to_string(),
94                )
95            })?;
96            let mut de = serde_json::Deserializer::from_str(&s);
97            serde_path_to_error::deserialize(&mut de)
98                .map_err(|source| crate::cli::command::FromArgsError {
99                    field: "params",
100                    source: source.into(),
101                })?
102        };
103        Ok(Self {
104            path_type: Path::AgentsMcpToolsList,
105            response_id,
106            params,
107            name: args.name,
108            base: args.base.into(),
109        })
110    }
111}
112
113#[cfg(feature = "cli-executor")]
114pub async fn execute<E: crate::cli::command::CommandExecutor>(
115    executor: &E,
116    mut request: Request,
117    agent_arguments: Option<&crate::cli::command::AgentArguments>,
118) -> Result<Response, E::Error> {
119    request.base.clear_transform();
120    executor.execute_one(request, agent_arguments).await
121}
122
123#[cfg(feature = "cli-executor")]
124pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
125    executor: &E,
126    mut request: Request,
127    transform: crate::cli::command::Transform,
128    agent_arguments: Option<&crate::cli::command::AgentArguments>,
129) -> Result<serde_json::Value, E::Error> {
130    request.base.set_transform(transform);
131    executor.execute_one(request, agent_arguments).await
132}
133
134#[cfg(feature = "mcp")]
135impl crate::cli::command::CommandResponse for Response {
136    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
137        crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
138    }
139}
140
141pub mod request_schema;
142
143pub mod response_schema;