Skip to main content

uarp_sdk/generated/api/
mcp.rs

1// Code generated by @uarp/codegen from spec/openapi.json. DO NOT EDIT.
2//!
3//! Model Context Protocol server endpoints
4
5#![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/// Query and header parameters for `mcpJsonRpc`.
18#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
19pub struct MCPJSONRpcParams {
20    /// Agent ID whose tools/resources/prompts the MCP server should expose for this RPC call.
21    #[serde(skip)]
22    pub x_uarp_agent_id: String,
23}
24
25/// Model Context Protocol server endpoints
26#[derive(Debug, Clone)]
27pub struct MCPApi {
28    pub(crate) client: Client,
29}
30
31impl Client {
32    /// Model Context Protocol server endpoints
33    pub fn mcp(&self) -> MCPApi {
34        MCPApi { client: self.clone() }
35    }
36}
37
38impl MCPApi {
39    /// Create MCP server
40    ///
41    /// `POST /api/v1/mcp/servers`
42    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    /// Delete MCP server
56    ///
57    /// `DELETE /api/v1/mcp/servers/{serverId}`
58    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    /// Get MCP server
72    ///
73    /// `GET /api/v1/mcp/servers/{serverId}`
74    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    /// List MCP servers
88    ///
89    /// `GET /api/v1/mcp/servers`
90    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    /// MCP JSON-RPC endpoint
104    ///
105    /// JSON-RPC 2.0 dispatch into the MCP server runtime. The `X-UARP-Agent-Id` header is required
106    /// so the MCP server can scope tool/resource visibility to a single agent; missing or malformed
107    /// headers return 400.
108    ///
109    /// `POST /api/v1/mcp`
110    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    /// MCP SSE transport (Server-Sent Events)
126    ///
127    /// `GET /api/v1/mcp`
128    ///
129    /// Returns a server-sent event stream.
130    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    /// Probe an MCP server's live connection
139    ///
140    /// Opens a real connection and lists the server's tools. **A failed probe is still 200** — `ok`
141    /// is the verdict, not the status code, because a server that refuses to connect is an answer
142    /// about the server rather than about the request. Read `ok` first: on false, `error` carries
143    /// the reason (including an SSRF refusal when the URL resolves to a private address) and
144    /// `tool_count`/`tools` are absent.
145    ///
146    /// `POST /api/v1/mcp/servers/{serverId}/test`
147    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    /// Update MCP server
161    ///
162    /// `PATCH /api/v1/mcp/servers/{serverId}`
163    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}