use super::{ContentType, Error, UploadFile, configuration};
use crate::{apis::ResponseContent, models};
use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteMcpError {
Status404(),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetMcpError {
Status405(),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PostMcpError {
Status400(),
Status405(),
Status500(),
UnknownValue(serde_json::Value),
}
pub fn delete_mcp_request_builder(
configuration: &configuration::Configuration,
) -> Result<reqwest::RequestBuilder, Error<serde_json::Error>> {
let uri_str = format!("{}/mcp/", configuration.base_path);
let mut req_builder = configuration
.client
.request(reqwest::Method::DELETE, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
Ok(req_builder)
}
pub async fn delete_mcp(
configuration: &configuration::Configuration,
) -> Result<(), Error<DeleteMcpError>> {
let req_builder =
delete_mcp_request_builder(configuration).map_err(super::map_request_builder_error)?;
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
let entity: Option<DeleteMcpError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub fn get_mcp_request_builder(
configuration: &configuration::Configuration,
) -> Result<reqwest::RequestBuilder, Error<serde_json::Error>> {
let uri_str = format!("{}/mcp/", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
Ok(req_builder)
}
pub async fn get_mcp(
configuration: &configuration::Configuration,
) -> Result<(), Error<GetMcpError>> {
let req_builder =
get_mcp_request_builder(configuration).map_err(super::map_request_builder_error)?;
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
let entity: Option<GetMcpError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub fn post_mcp_request_builder(
configuration: &configuration::Configuration,
accept: &str,
body: serde_json::Value,
) -> Result<reqwest::RequestBuilder, Error<serde_json::Error>> {
let p_header_accept = accept;
let p_body_body = body;
let uri_str = format!("{}/mcp/", configuration.base_path);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = req_builder.header("Accept", p_header_accept.to_string());
req_builder = req_builder.json(&p_body_body);
Ok(req_builder)
}
pub async fn post_mcp(
configuration: &configuration::Configuration,
accept: &str,
body: serde_json::Value,
) -> Result<serde_json::Value, Error<PostMcpError>> {
let req_builder = post_mcp_request_builder(configuration, accept, body)
.map_err(super::map_request_builder_error)?;
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `serde_json::Value`",
))),
ContentType::Unsupported(unknown_type) => {
Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `serde_json::Value`"
))))
}
}
} else {
let content = resp.text().await?;
let entity: Option<PostMcpError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}