windmill_api/apis/
mcp_oauth_api.rs1use reqwest;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum DiscoverMcpOAuthError {
22 UnknownValue(serde_json::Value),
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GetMcpOAuthServerClientError {
29 UnknownValue(serde_json::Value),
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum McpOAuthCallbackError {
36 UnknownValue(serde_json::Value),
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum StartMcpOAuthPopupError {
43 UnknownValue(serde_json::Value),
44}
45
46
47pub async fn discover_mcp_o_auth(configuration: &configuration::Configuration, discover_mcp_o_auth_request: models::DiscoverMcpOAuthRequest) -> Result<models::DiscoverMcpOAuth200Response, Error<DiscoverMcpOAuthError>> {
48 let local_var_configuration = configuration;
49
50 let local_var_client = &local_var_configuration.client;
51
52 let local_var_uri_str = format!("{}/mcp/oauth/discover", local_var_configuration.base_path);
53 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
54
55 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
56 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
57 }
58 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
59 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
60 };
61 local_var_req_builder = local_var_req_builder.json(&discover_mcp_o_auth_request);
62
63 let local_var_req = local_var_req_builder.build()?;
64 let local_var_resp = local_var_client.execute(local_var_req).await?;
65
66 let local_var_status = local_var_resp.status();
67 let local_var_content = local_var_resp.text().await?;
68
69 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
70 crate::from_str_patched(&local_var_content).map_err(Error::from)
71 } else {
72 let local_var_entity: Option<DiscoverMcpOAuthError> = crate::from_str_patched(&local_var_content).ok();
73 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
74 Err(Error::ResponseError(local_var_error))
75 }
76}
77
78pub async fn get_mcp_o_auth_server_client(configuration: &configuration::Configuration, client_id: &str) -> Result<models::GetMcpOAuthServerClient200Response, Error<GetMcpOAuthServerClientError>> {
80 let local_var_configuration = configuration;
81
82 let local_var_client = &local_var_configuration.client;
83
84 let local_var_uri_str = format!("{}/mcp/gateway/oauth/server/client/{client_id}", local_var_configuration.base_path, client_id=crate::apis::urlencode(client_id));
85 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
86
87 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
88 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
89 }
90 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
91 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
92 };
93
94 let local_var_req = local_var_req_builder.build()?;
95 let local_var_resp = local_var_client.execute(local_var_req).await?;
96
97 let local_var_status = local_var_resp.status();
98 let local_var_content = local_var_resp.text().await?;
99
100 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
101 crate::from_str_patched(&local_var_content).map_err(Error::from)
102 } else {
103 let local_var_entity: Option<GetMcpOAuthServerClientError> = crate::from_str_patched(&local_var_content).ok();
104 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
105 Err(Error::ResponseError(local_var_error))
106 }
107}
108
109pub async fn mcp_o_auth_callback(configuration: &configuration::Configuration, code: &str, state: &str) -> Result<String, Error<McpOAuthCallbackError>> {
111 let local_var_configuration = configuration;
112
113 let local_var_client = &local_var_configuration.client;
114
115 let local_var_uri_str = format!("{}/mcp/oauth/callback", local_var_configuration.base_path);
116 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
117
118 local_var_req_builder = local_var_req_builder.query(&[("code", &code.to_string())]);
119 local_var_req_builder = local_var_req_builder.query(&[("state", &state.to_string())]);
120 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
121 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
122 }
123
124 let local_var_req = local_var_req_builder.build()?;
125 let local_var_resp = local_var_client.execute(local_var_req).await?;
126
127 let local_var_status = local_var_resp.status();
128 let local_var_content = local_var_resp.text().await?;
129
130 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
131 crate::from_str_patched(&local_var_content).map_err(Error::from)
132 } else {
133 let local_var_entity: Option<McpOAuthCallbackError> = crate::from_str_patched(&local_var_content).ok();
134 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
135 Err(Error::ResponseError(local_var_error))
136 }
137}
138
139pub async fn start_mcp_o_auth_popup(configuration: &configuration::Configuration, mcp_server_url: &str, scopes: Option<&str>) -> Result<(), Error<StartMcpOAuthPopupError>> {
141 let local_var_configuration = configuration;
142
143 let local_var_client = &local_var_configuration.client;
144
145 let local_var_uri_str = format!("{}/mcp/oauth/start", local_var_configuration.base_path);
146 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
147
148 local_var_req_builder = local_var_req_builder.query(&[("mcp_server_url", &mcp_server_url.to_string())]);
149 if let Some(ref local_var_str) = scopes {
150 local_var_req_builder = local_var_req_builder.query(&[("scopes", &local_var_str.to_string())]);
151 }
152 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
153 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
154 }
155 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
156 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
157 };
158
159 let local_var_req = local_var_req_builder.build()?;
160 let local_var_resp = local_var_client.execute(local_var_req).await?;
161
162 let local_var_status = local_var_resp.status();
163 let local_var_content = local_var_resp.text().await?;
164
165 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
166 Ok(())
167 } else {
168 let local_var_entity: Option<StartMcpOAuthPopupError> = crate::from_str_patched(&local_var_content).ok();
169 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
170 Err(Error::ResponseError(local_var_error))
171 }
172}
173