MCPcopy Create free account
hub / github.com/AI45Lab/Code / request

Method request

core/src/mcp/transport/streamable_http.rs:285–310  ·  view source on GitHub ↗
(&self, request: JsonRpcRequest)

Source from the content-addressed store, hash-verified

283#[async_trait]
284impl McpTransport for StreamableHttpTransport {
285 async fn request(&self, request: JsonRpcRequest) -> Result<JsonRpcResponse> {
286 if !self.connected.load(Ordering::SeqCst) {
287 return Err(anyhow!("Transport not connected"));
288 }
289
290 let extra_headers = self.request_headers().await;
291 let body = serde_json::to_string(&request)?;
292
293 let response = self
294 .client
295 .post(&self.url)
296 .headers(extra_headers)
297 .body(body)
298 .send()
299 .await
300 .with_context(|| format!("Streamable HTTP POST to {} failed", self.url))?;
301
302 if !response.status().is_success() {
303 let status = response.status();
304 let body = response.text().await.unwrap_or_default();
305 return Err(anyhow!("MCP server returned HTTP {}: {}", status, body));
306 }
307
308 self.capture_session_id(response.headers()).await;
309 Self::parse_response(response).await
310 }
311
312 async fn notify(&self, notification: JsonRpcNotification) -> Result<()> {
313 if !self.connected.load(Ordering::SeqCst) {

Calls 8

with_contextMethod · 0.80
capture_session_idMethod · 0.80
loadMethod · 0.45
request_headersMethod · 0.45
sendMethod · 0.45
postMethod · 0.45
statusMethod · 0.45
textMethod · 0.45

Tested by 1