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    /// Objectiveai response id of the live agent to address. `None` ⇒
13    /// resolved from the caller's contextual agent arguments
14    /// (`OBJECTIVEAI_RESPONSE_ID`); an error if absent there too.
15    #[serde(default, skip_serializing_if = "Option::is_none")]
16    #[schemars(extend("omitempty" = true))]
17    pub response_id: Option<String>,
18    pub params: crate::mcp::tool::ListToolsRequest,
19    /// Restrict the listing to the single server with this name (the
20    /// routing prefix `agents mcp servers list` reports). `None` lists
21    /// every server.
22    #[serde(default, skip_serializing_if = "Option::is_none")]
23    #[schemars(extend("omitempty" = true))]
24    pub name: Option<String>,
25    #[serde(flatten)]
26    pub base: crate::cli::command::RequestBase,
27}
28
29#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
30#[schemars(rename = "cli.command.agents.mcp.tools.list.Path")]
31pub enum Path {
32    #[serde(rename = "agents/mcp/tools/list")]
33    AgentsMcpToolsList,
34}
35
36impl CommandRequest for Request {
37    fn request_base(&self) -> &crate::cli::command::RequestBase {
38        &self.base
39    }
40
41    fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
42        Some(&mut self.base)
43    }
44}
45
46pub type Response = crate::mcp::tool::ListToolsResult;
47
48#[derive(clap::Args)]
49#[command(group(clap::ArgGroup::new("params_required").required(true).args(["params"])))]
50pub struct Args {
51    /// Objectiveai response id of the live agent whose MCP aggregation
52    /// to query (the socket at `<state>/socks/<response_id>.sock`).
53    /// Omit to use the invoking agent's own response id (from the
54    /// contextual agent arguments).
55    #[arg(long)]
56    pub response_id: Option<String>,
57    /// MCP `ListToolsRequest` as a JSON string, e.g. `{}` or
58    /// `{"cursor":"..."}`.
59    #[arg(long)]
60    pub params: Option<String>,
61    /// Restrict the listing to the single server with this name (the
62    /// routing prefix from `agents mcp servers list`). Omit to list all.
63    #[arg(long)]
64    pub name: Option<String>,
65    #[command(flatten)]
66    pub base: crate::cli::command::RequestBaseArgs,
67}
68
69#[derive(clap::Args)]
70#[command(args_conflicts_with_subcommands = true)]
71pub struct Command {
72    #[command(flatten)]
73    pub args: Args,
74    #[command(subcommand)]
75    pub schema: Option<Schema>,
76}
77
78#[derive(clap::Subcommand)]
79pub enum Schema {
80    /// Emit the JSON Schema for this leaf's `Request` type and exit.
81    RequestSchema(request_schema::Args),
82    /// Emit the JSON Schema for this leaf's `Response` type and exit.
83    ResponseSchema(response_schema::Args),
84}
85
86impl TryFrom<Args> for Request {
87    type Error = crate::cli::command::FromArgsError;
88    fn try_from(args: Args) -> Result<Self, Self::Error> {
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: args.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;
144
145/// One `/listen` broadcast run of `agents mcp tools list`: the actual
146/// [`Request`], the producer's
147/// [`AgentArguments`](crate::cli::command::AgentArguments), and the
148/// unary response future. See [`crate::cli::broadcast_listener`].
149#[cfg(feature = "cli-listener")]
150pub struct ListenerExecution {
151    pub request: Request,
152    pub agent_arguments: crate::cli::command::AgentArguments,
153    pub response: crate::cli::broadcast_listener::UnaryResponse<Response>,
154}