Skip to main content

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

1//! `agents mcp servers list` — list the upstream MCP servers the proxy has
2//! connected for the live agent's `response_id`, with each server's metadata
3//! (capabilities, name, version, description, instructions). Answered locally
4//! by the proxy from its in-memory connection set — no MCP params, no upstream
5//! round-trip.
6
7use crate::cli::command::CommandRequest;
8
9#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
10#[schemars(rename = "cli.command.agents.mcp.servers.list.Request")]
11pub struct Request {
12    pub path_type: Path,
13    pub response_id: String,
14    #[serde(flatten)]
15    pub base: crate::cli::command::RequestBase,
16}
17
18#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
19#[schemars(rename = "cli.command.agents.mcp.servers.list.Path")]
20pub enum Path {
21    #[serde(rename = "agents/mcp/servers/list")]
22    AgentsMcpServersList,
23}
24
25impl CommandRequest for Request {
26    fn request_base(&self) -> &crate::cli::command::RequestBase {
27        &self.base
28    }
29
30    fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
31        Some(&mut self.base)
32    }
33}
34
35pub type Response = crate::mcp::server::ListServersResult;
36
37#[derive(clap::Args)]
38#[command(group(clap::ArgGroup::new("response_id_required").required(true).args(["response_id"])))]
39pub struct Args {
40    /// Objectiveai response id of the live agent whose connected MCP
41    /// servers to list (the socket at `<state>/socks/<response_id>.sock`).
42    #[arg(long)]
43    pub response_id: Option<String>,
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 response_id = args.response_id.ok_or_else(|| {
69            crate::cli::command::FromArgsError::path_parse(
70                "response_id",
71                "--response-id is required".to_string(),
72            )
73        })?;
74        Ok(Self {
75            path_type: Path::AgentsMcpServersList,
76            response_id,
77            base: args.base.into(),
78        })
79    }
80}
81
82#[cfg(feature = "cli-executor")]
83pub async fn execute<E: crate::cli::command::CommandExecutor>(
84    executor: &E,
85    mut request: Request,
86    agent_arguments: Option<&crate::cli::command::AgentArguments>,
87) -> Result<Response, E::Error> {
88    request.base.clear_transform();
89    executor.execute_one(request, agent_arguments).await
90}
91
92#[cfg(feature = "cli-executor")]
93pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
94    executor: &E,
95    mut request: Request,
96    transform: crate::cli::command::Transform,
97    agent_arguments: Option<&crate::cli::command::AgentArguments>,
98) -> Result<serde_json::Value, E::Error> {
99    request.base.set_transform(transform);
100    executor.execute_one(request, agent_arguments).await
101}
102
103#[cfg(feature = "mcp")]
104impl crate::cli::command::CommandResponse for Response {
105    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
106        crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
107    }
108}
109
110pub mod request_schema;
111
112pub mod response_schema;
113
114/// One `/listen` broadcast run of `agents mcp servers list`: the actual
115/// [`Request`], the producer's
116/// [`AgentArguments`](crate::cli::command::AgentArguments), and the
117/// unary response future. See [`crate::cli::websocket_listener`].
118#[cfg(feature = "cli-listener")]
119pub struct ListenerExecution {
120    pub request: Request,
121    pub agent_arguments: crate::cli::command::AgentArguments,
122    pub response: crate::cli::websocket_listener::UnaryResponse<Response>,
123}