uarp_sdk/generated/api/
mcp.rs1#![allow(unused_imports, clippy::too_many_arguments)]
6
7use reqwest::Method;
8use serde::{Deserialize, Serialize};
9
10use crate::client::{Client, Request, NO_BODY, NO_QUERY};
11use crate::error::Result;
12use crate::generated::models;
13use crate::multipart::{field_text, FilePart};
14use crate::sse::EventStream;
15use crate::util::encode_path;
16
17#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
19pub struct MCPJSONRpcParams {
20 #[serde(skip)]
22 pub x_uarp_agent_id: String,
23}
24
25#[derive(Debug, Clone)]
27pub struct MCPApi {
28 pub(crate) client: Client,
29}
30
31impl Client {
32 pub fn mcp(&self) -> MCPApi {
34 MCPApi { client: self.clone() }
35 }
36}
37
38impl MCPApi {
39 pub async fn create_mcp_server(&self, body: &models::CreateMCPServerRequest) -> Result<models::MCPServer> {
43 self.client
44 .request_json(Request {
45 method: Method::POST,
46 path: "/api/v1/mcp/servers".to_string(),
47 query: NO_QUERY,
48 body: Some(body),
49 headers: Vec::new(),
50 idempotent: true,
51 })
52 .await
53 }
54
55 pub async fn delete_mcp_server(&self, server_id: &str) -> Result<serde_json::Value> {
59 self.client
60 .request_json(Request {
61 method: Method::DELETE,
62 path: format!("/api/v1/mcp/servers/{}", encode_path(server_id)),
63 query: NO_QUERY,
64 body: NO_BODY,
65 headers: Vec::new(),
66 idempotent: true,
67 })
68 .await
69 }
70
71 pub async fn get_mcp_server(&self, server_id: &str) -> Result<models::MCPServer> {
75 self.client
76 .request_json(Request {
77 method: Method::GET,
78 path: format!("/api/v1/mcp/servers/{}", encode_path(server_id)),
79 query: NO_QUERY,
80 body: NO_BODY,
81 headers: Vec::new(),
82 idempotent: false,
83 })
84 .await
85 }
86
87 pub async fn list_mcp_servers(&self) -> Result<models::ListMCPServersResponse> {
91 self.client
92 .request_json(Request {
93 method: Method::GET,
94 path: "/api/v1/mcp/servers".to_string(),
95 query: NO_QUERY,
96 body: NO_BODY,
97 headers: Vec::new(),
98 idempotent: false,
99 })
100 .await
101 }
102
103 pub async fn mcp_json_rpc(&self, body: &models::McpjsonRpcRequest, params: &MCPJSONRpcParams) -> Result<serde_json::Value> {
111 let mut headers: Vec<(&'static str, String)> = Vec::new();
112 headers.push(("X-UARP-Agent-Id", params.x_uarp_agent_id.clone()));
113 self.client
114 .request_json(Request {
115 method: Method::POST,
116 path: "/api/v1/mcp".to_string(),
117 query: NO_QUERY,
118 body: Some(body),
119 headers,
120 idempotent: true,
121 })
122 .await
123 }
124
125 pub fn mcp_sse(&self) -> EventStream {
131 self.client.request_stream(
132 "/api/v1/mcp",
133 NO_QUERY,
134 Vec::new(),
135 )
136 }
137
138 pub async fn test_mcp_server(&self, server_id: &str) -> Result<models::MCPServerTestResult> {
148 self.client
149 .request_json(Request {
150 method: Method::POST,
151 path: format!("/api/v1/mcp/servers/{}/test", encode_path(server_id)),
152 query: NO_QUERY,
153 body: NO_BODY,
154 headers: Vec::new(),
155 idempotent: true,
156 })
157 .await
158 }
159
160 pub async fn update_mcp_server(&self, server_id: &str, body: &serde_json::Map<String, serde_json::Value>) -> Result<models::MCPServerWithConnectResult> {
164 self.client
165 .request_json(Request {
166 method: Method::PATCH,
167 path: format!("/api/v1/mcp/servers/{}", encode_path(server_id)),
168 query: NO_QUERY,
169 body: Some(body),
170 headers: Vec::new(),
171 idempotent: true,
172 })
173 .await
174 }
175}