objectiveai_sdk/cli/command/mcp/config/
mod.rs1pub mod address;
2pub mod get;
3pub mod port;
4
5#[derive(clap::Subcommand)]
6pub enum Command {
7 Get(get::Command),
8 Address {
9 #[command(subcommand)]
10 command: address::Command,
11 },
12 Port {
13 #[command(subcommand)]
14 command: port::Command,
15 },
16}
17
18#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
19#[serde(untagged)]
20#[schemars(rename = "cli.command.mcp.config.Request")]
21pub enum Request {
22 #[schemars(title = "Get")]
23 Get(get::Request),
24 #[schemars(title = "GetRequestSchema")]
25 GetRequestSchema(get::request_schema::Request),
26 #[schemars(title = "GetResponseSchema")]
27 GetResponseSchema(get::response_schema::Request),
28 #[schemars(title = "Address")]
29 Address(address::Request),
30 #[schemars(title = "Port")]
31 Port(port::Request),
32}
33
34#[objectiveai_sdk_macros::json_schema_ignore]
37#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
38#[schemars(rename = "cli.command.mcp.config.Response")]
39#[serde(untagged)]
40pub enum Response {
41 #[schemars(title = "Get")]
42 Get(get::Response),
43 #[schemars(title = "GetRequestSchema")]
44 GetRequestSchema(get::request_schema::Response),
45 #[schemars(title = "GetResponseSchema")]
46 GetResponseSchema(get::response_schema::Response),
47 #[schemars(title = "Address")]
48 Address(address::Response),
49 #[schemars(title = "Port")]
50 Port(port::Response),
51}
52
53#[cfg(feature = "mcp")]
54impl crate::cli::command::CommandResponse for Response {
55 fn into_mcp(self) -> crate::cli::command::McpResponseItem {
56 match self {
57 Response::Get(v) => v.into_mcp(),
58 Response::GetRequestSchema(v) => v.into_mcp(),
59 Response::GetResponseSchema(v) => v.into_mcp(),
60 Response::Address(v) => v.into_mcp(),
61 Response::Port(v) => v.into_mcp(),
62 }
63 }
64}
65
66impl TryFrom<Command> for Request {
67 type Error = crate::cli::command::FromArgsError;
68 fn try_from(command: Command) -> Result<Self, Self::Error> {
69 match command {
70 Command::Get(cmd) => match cmd.schema {
71 None => Ok(Request::Get(get::Request::try_from(cmd.args)?)),
72 Some(get::Schema::RequestSchema(args)) =>
73 Ok(Request::GetRequestSchema(get::request_schema::Request::try_from(args)?)),
74 Some(get::Schema::ResponseSchema(args)) =>
75 Ok(Request::GetResponseSchema(get::response_schema::Request::try_from(args)?)),
76 },
77 Command::Address { command } =>
78 Ok(Request::Address(address::Request::try_from(command)?)),
79 Command::Port { command } =>
80 Ok(Request::Port(port::Request::try_from(command)?)),
81 }
82 }
83}
84
85impl crate::cli::command::CommandRequest for Request {
86 fn into_command(&self) -> Vec<String> {
87 match self {
88 Request::Get(inner) => inner.into_command(),
89 Request::GetRequestSchema(inner) => inner.into_command(),
90 Request::GetResponseSchema(inner) => inner.into_command(),
91 Request::Address(inner) => inner.into_command(),
92 Request::Port(inner) => inner.into_command(),
93 }
94 }
95
96 fn request_base(&self) -> &crate::cli::command::RequestBase {
97 match self {
98 Request::Get(inner) => inner.request_base(),
99 Request::GetRequestSchema(inner) => inner.request_base(),
100 Request::GetResponseSchema(inner) => inner.request_base(),
101 Request::Address(inner) => inner.request_base(),
102 Request::Port(inner) => inner.request_base(),
103 }
104 }
105
106 fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
107 match self {
108 Request::Get(inner) => inner.request_base_mut(),
109 Request::GetRequestSchema(inner) => inner.request_base_mut(),
110 Request::GetResponseSchema(inner) => inner.request_base_mut(),
111 Request::Address(inner) => inner.request_base_mut(),
112 Request::Port(inner) => inner.request_base_mut(),
113 }
114 }
115}
116
117#[cfg(feature = "cli-executor")]
118pub async fn execute<E: crate::cli::command::CommandExecutor>(
119 executor: &E,
120 request: Request,
121
122 agent_arguments: Option<&crate::cli::command::AgentArguments>,
123 ) -> Result<
124 std::pin::Pin<Box<dyn futures::Stream<Item = Result<Response, E::Error>> + Send>>,
125 E::Error,
126> {
127 use futures::StreamExt;
128 let stream: std::pin::Pin<Box<dyn futures::Stream<Item = Result<Response, E::Error>> + Send>> =
129 match request {
130 Request::Get(req) => {
131 let value = get::execute(executor, req, agent_arguments).await?;
132 Box::pin(crate::cli::command::StreamOnce::new(Ok(
133 Response::Get(value),
134 )))
135 }
136 Request::GetRequestSchema(req) => {
137 let value = get::request_schema::execute(executor, req, agent_arguments).await?;
138 Box::pin(crate::cli::command::StreamOnce::new(Ok(
139 Response::GetRequestSchema(value),
140 )))
141 }
142 Request::GetResponseSchema(req) => {
143 let value = get::response_schema::execute(executor, req, agent_arguments).await?;
144 Box::pin(crate::cli::command::StreamOnce::new(Ok(
145 Response::GetResponseSchema(value),
146 )))
147 }
148 Request::Address(req) => {
149 let inner = address::execute(executor, req, agent_arguments).await?;
150 Box::pin(inner.map(|r| r.map(Response::Address)))
151 }
152 Request::Port(req) => {
153 let inner = port::execute(executor, req, agent_arguments).await?;
154 Box::pin(inner.map(|r| r.map(Response::Port)))
155 }
156 };
157 Ok(stream)
158}
159
160#[cfg(feature = "cli-executor")]
161pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
162 executor: &E,
163 request: Request,
164 transform: crate::cli::command::Transform,
165
166 agent_arguments: Option<&crate::cli::command::AgentArguments>,
167 ) -> Result<
168 std::pin::Pin<Box<dyn futures::Stream<Item = Result<serde_json::Value, E::Error>> + Send>>,
169 E::Error,
170> {
171 let stream: std::pin::Pin<Box<dyn futures::Stream<Item = Result<serde_json::Value, E::Error>> + Send>> =
172 match request {
173 Request::Get(req) => {
174 let value = get::execute_transform(executor, req, transform, agent_arguments).await?;
175 Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
176 }
177 Request::GetRequestSchema(req) => {
178 let value = get::request_schema::execute_transform(executor, req, transform, agent_arguments).await?;
179 Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
180 }
181 Request::GetResponseSchema(req) => {
182 let value = get::response_schema::execute_transform(executor, req, transform, agent_arguments).await?;
183 Box::pin(crate::cli::command::StreamOnce::new(Ok(value)))
184 }
185 Request::Address(req) => {
186 let inner = address::execute_transform(executor, req, transform, agent_arguments).await?;
187 Box::pin(inner)
188 }
189 Request::Port(req) => {
190 let inner = port::execute_transform(executor, req, transform, agent_arguments).await?;
191 Box::pin(inner)
192 }
193 };
194 Ok(stream)
195}