langgraph_api/generated/apis/
mcp_api.rs

1/*
2 * LangSmith Deployment
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: 0.1.0
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use super::{ContentType, Error, UploadFile, configuration};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{Deserialize, Serialize, de::Error as _};
15
16/// struct for typed errors of method [`delete_mcp`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum DeleteMcpError {
20    Status404(),
21    UnknownValue(serde_json::Value),
22}
23
24/// struct for typed errors of method [`get_mcp`]
25#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(untagged)]
27pub enum GetMcpError {
28    Status405(),
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`post_mcp`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum PostMcpError {
36    Status400(),
37    Status405(),
38    Status500(),
39    UnknownValue(serde_json::Value),
40}
41
42/// Implemented according to the Streamable HTTP Transport specification. Terminate an MCP session. The server implementation is stateless, so this is a no-op.  
43pub fn delete_mcp_request_builder(
44    configuration: &configuration::Configuration,
45) -> Result<reqwest::RequestBuilder, Error<serde_json::Error>> {
46    let uri_str = format!("{}/mcp/", configuration.base_path);
47    let mut req_builder = configuration
48        .client
49        .request(reqwest::Method::DELETE, &uri_str);
50
51    if let Some(ref user_agent) = configuration.user_agent {
52        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
53    }
54
55    Ok(req_builder)
56}
57
58pub async fn delete_mcp(
59    configuration: &configuration::Configuration,
60) -> Result<(), Error<DeleteMcpError>> {
61    let req_builder =
62        delete_mcp_request_builder(configuration).map_err(super::map_request_builder_error)?;
63    let req = req_builder.build()?;
64    let resp = configuration.client.execute(req).await?;
65
66    let status = resp.status();
67
68    if !status.is_client_error() && !status.is_server_error() {
69        Ok(())
70    } else {
71        let content = resp.text().await?;
72        let entity: Option<DeleteMcpError> = serde_json::from_str(&content).ok();
73        Err(Error::ResponseError(ResponseContent {
74            status,
75            content,
76            entity,
77        }))
78    }
79}
80
81/// Implemented according to the Streamable HTTP Transport specification.
82pub fn get_mcp_request_builder(
83    configuration: &configuration::Configuration,
84) -> Result<reqwest::RequestBuilder, Error<serde_json::Error>> {
85    let uri_str = format!("{}/mcp/", configuration.base_path);
86    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
87
88    if let Some(ref user_agent) = configuration.user_agent {
89        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
90    }
91
92    Ok(req_builder)
93}
94
95pub async fn get_mcp(
96    configuration: &configuration::Configuration,
97) -> Result<(), Error<GetMcpError>> {
98    let req_builder =
99        get_mcp_request_builder(configuration).map_err(super::map_request_builder_error)?;
100    let req = req_builder.build()?;
101    let resp = configuration.client.execute(req).await?;
102
103    let status = resp.status();
104
105    if !status.is_client_error() && !status.is_server_error() {
106        Ok(())
107    } else {
108        let content = resp.text().await?;
109        let entity: Option<GetMcpError> = serde_json::from_str(&content).ok();
110        Err(Error::ResponseError(ResponseContent {
111            status,
112            content,
113            entity,
114        }))
115    }
116}
117
118/// Implemented according to the Streamable HTTP Transport specification. Sends a JSON-RPC 2.0 message to the server.  - **Request**: Provide an object with `jsonrpc`, `id`, `method`, and optional `params`. - **Response**: Returns a JSON-RPC response or acknowledgment.  **Notes:** - Stateless: Sessions are not persisted across requests.
119pub fn post_mcp_request_builder(
120    configuration: &configuration::Configuration,
121    accept: &str,
122    body: serde_json::Value,
123) -> Result<reqwest::RequestBuilder, Error<serde_json::Error>> {
124    // add a prefix to parameters to efficiently prevent name collisions
125    let p_header_accept = accept;
126    let p_body_body = body;
127
128    let uri_str = format!("{}/mcp/", configuration.base_path);
129    let mut req_builder = configuration
130        .client
131        .request(reqwest::Method::POST, &uri_str);
132
133    if let Some(ref user_agent) = configuration.user_agent {
134        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
135    }
136    req_builder = req_builder.header("Accept", p_header_accept.to_string());
137    req_builder = req_builder.json(&p_body_body);
138
139    Ok(req_builder)
140}
141
142pub async fn post_mcp(
143    configuration: &configuration::Configuration,
144    accept: &str,
145    body: serde_json::Value,
146) -> Result<serde_json::Value, Error<PostMcpError>> {
147    let req_builder = post_mcp_request_builder(configuration, accept, body)
148        .map_err(super::map_request_builder_error)?;
149    let req = req_builder.build()?;
150    let resp = configuration.client.execute(req).await?;
151
152    let status = resp.status();
153    let content_type = resp
154        .headers()
155        .get("content-type")
156        .and_then(|v| v.to_str().ok())
157        .unwrap_or("application/octet-stream");
158    let content_type = super::ContentType::from(content_type);
159
160    if !status.is_client_error() && !status.is_server_error() {
161        let content = resp.text().await?;
162        match content_type {
163            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
164            ContentType::Text => Err(Error::from(serde_json::Error::custom(
165                "Received `text/plain` content type response that cannot be converted to `serde_json::Value`",
166            ))),
167            ContentType::Unsupported(unknown_type) => {
168                Err(Error::from(serde_json::Error::custom(format!(
169                    "Received `{unknown_type}` content type response that cannot be converted to `serde_json::Value`"
170                ))))
171            }
172        }
173    } else {
174        let content = resp.text().await?;
175        let entity: Option<PostMcpError> = serde_json::from_str(&content).ok();
176        Err(Error::ResponseError(ResponseContent {
177            status,
178            content,
179            entity,
180        }))
181    }
182}