1use crate::error::Result;
6use crate::http::HttpClient;
7use crate::types::api::McpActionResponse;
8use crate::types::mcp::{
9 McpAddRequest, McpAuthCallbackRequest, McpAuthStartRequest, McpAuthStartResponse,
10 McpAuthenticateRequest, McpStatus,
11};
12use reqwest::Method;
13
14#[derive(Clone)]
16pub struct McpApi {
17 http: HttpClient,
18}
19
20impl McpApi {
21 pub fn new(http: HttpClient) -> Self {
23 Self { http }
24 }
25
26 pub async fn status(&self) -> Result<McpStatus> {
32 self.http.request_json(Method::GET, "/mcp", None).await
33 }
34
35 pub async fn add(&self, req: &McpAddRequest) -> Result<McpActionResponse> {
41 let body = serde_json::to_value(req)?;
42 self.http
43 .request_json(Method::POST, "/mcp", Some(body))
44 .await
45 }
46
47 pub async fn auth_start(
53 &self,
54 name: &str,
55 req: &McpAuthStartRequest,
56 ) -> Result<McpAuthStartResponse> {
57 let body = serde_json::to_value(req)?;
58 self.http
59 .request_json(Method::POST, &format!("/mcp/{}/auth", name), Some(body))
60 .await
61 }
62
63 pub async fn auth_callback(
69 &self,
70 name: &str,
71 req: &McpAuthCallbackRequest,
72 ) -> Result<McpActionResponse> {
73 let body = serde_json::to_value(req)?;
74 self.http
75 .request_json(
76 Method::POST,
77 &format!("/mcp/{}/auth/callback", name),
78 Some(body),
79 )
80 .await
81 }
82
83 pub async fn authenticate(
89 &self,
90 name: &str,
91 req: &McpAuthenticateRequest,
92 ) -> Result<McpActionResponse> {
93 let body = serde_json::to_value(req)?;
94 self.http
95 .request_json(
96 Method::POST,
97 &format!("/mcp/{}/auth/authenticate", name),
98 Some(body),
99 )
100 .await
101 }
102
103 pub async fn auth_remove(&self, name: &str) -> Result<()> {
109 self.http
110 .request_empty(Method::DELETE, &format!("/mcp/{}/auth", name), None)
111 .await
112 }
113
114 pub async fn connect(&self, name: &str) -> Result<McpActionResponse> {
120 self.http
121 .request_json(
122 Method::POST,
123 &format!("/mcp/{}/connect", name),
124 None, )
126 .await
127 }
128
129 pub async fn disconnect(&self, name: &str) -> Result<McpActionResponse> {
135 self.http
136 .request_json(
137 Method::POST,
138 &format!("/mcp/{}/disconnect", name),
139 None, )
141 .await
142 }
143}