| 310 | } |
| 311 | |
| 312 | async fn notify(&self, notification: JsonRpcNotification) -> Result<()> { |
| 313 | if !self.connected.load(Ordering::SeqCst) { |
| 314 | return Err(anyhow!("Transport not connected")); |
| 315 | } |
| 316 | |
| 317 | let extra_headers = self.request_headers().await; |
| 318 | let body = serde_json::to_string(¬ification)?; |
| 319 | |
| 320 | let response = self |
| 321 | .client |
| 322 | .post(&self.url) |
| 323 | .headers(extra_headers) |
| 324 | .body(body) |
| 325 | .send() |
| 326 | .await |
| 327 | .with_context(|| format!("Streamable HTTP notification to {} failed", self.url))?; |
| 328 | |
| 329 | if !response.status().is_success() { |
| 330 | tracing::warn!( |
| 331 | status = %response.status(), |
| 332 | "Streamable HTTP notification returned non-success status" |
| 333 | ); |
| 334 | } |
| 335 | |
| 336 | Ok(()) |
| 337 | } |
| 338 | |
| 339 | fn notifications(&self) -> mpsc::Receiver<McpNotification> { |
| 340 | let mut rx = self.notification_rx.blocking_write(); |