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    /// Objectiveai response id of the live agent to address. `None` ⇒
14    /// resolved from the caller's contextual agent arguments
15    /// (`OBJECTIVEAI_RESPONSE_ID`); an error if absent there too.
16    #[serde(default, skip_serializing_if = "Option::is_none")]
17    #[schemars(extend("omitempty" = true))]
18    pub response_id: Option<String>,
19    #[serde(flatten)]
20    pub base: crate::cli::command::RequestBase,
21}
22
23#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
24#[schemars(rename = "cli.command.agents.mcp.servers.list.Path")]
25pub enum Path {
26    #[serde(rename = "agents/mcp/servers/list")]
27    AgentsMcpServersList,
28}
29
30impl CommandRequest for Request {
31    fn request_base(&self) -> &crate::cli::command::RequestBase {
32        &self.base
33    }
34
35    fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
36        Some(&mut self.base)
37    }
38}
39
40pub type Response = crate::mcp::server::ListServersResult;
41
42#[derive(clap::Args)]
43pub struct Args {
44    /// Objectiveai response id of the live agent whose connected MCP
45    /// servers to list (the socket at `<state>/socks/<response_id>.sock`).
46    /// Omit to use the invoking agent's own response id (from the
47    /// contextual agent arguments).
48    #[arg(long)]
49    pub response_id: Option<String>,
50    #[command(flatten)]
51    pub base: crate::cli::command::RequestBaseArgs,
52}
53
54#[derive(clap::Args)]
55#[command(args_conflicts_with_subcommands = true)]
56pub struct Command {
57    #[command(flatten)]
58    pub args: Args,
59    #[command(subcommand)]
60    pub schema: Option<Schema>,
61}
62
63#[derive(clap::Subcommand)]
64pub enum Schema {
65    /// Emit the JSON Schema for this leaf's `Request` type and exit.
66    RequestSchema(request_schema::Args),
67    /// Emit the JSON Schema for this leaf's `Response` type and exit.
68    ResponseSchema(response_schema::Args),
69}
70
71impl TryFrom<Args> for Request {
72    type Error = crate::cli::command::FromArgsError;
73    fn try_from(args: Args) -> Result<Self, Self::Error> {
74        Ok(Self {
75            path_type: Path::AgentsMcpServersList,
76            response_id: args.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::broadcast_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::broadcast_listener::UnaryResponse<Response>,
123}