(&self)
| 458 | } |
| 459 | |
| 460 | async fn initialize(&self) -> Result<(), McpClientError> { |
| 461 | let params = serde_json::to_value(InitializeParams::default()) |
| 462 | .map_err(|e| McpClientError::ProtocolError(e.to_string()))?; |
| 463 | |
| 464 | let response = self.send_request("initialize", Some(params)).await?; |
| 465 | |
| 466 | let result: InitializeResult = response |
| 467 | .result |
| 468 | .ok_or_else(|| McpClientError::ProtocolError("No result in initialize response".into())) |
| 469 | .and_then(|r| { |
| 470 | serde_json::from_value(r).map_err(|e| { |
| 471 | McpClientError::ProtocolError(format!("Failed to parse initialize result: {e}")) |
| 472 | }) |
| 473 | })?; |
| 474 | |
| 475 | { |
| 476 | let mut caps = self.capabilities.write().await; |
| 477 | *caps = Some(result.capabilities); |
| 478 | } |
| 479 | |
| 480 | self.send_request("notifications/initialized", None) |
| 481 | .await |
| 482 | .ok(); |
| 483 | |
| 484 | { |
| 485 | let mut init = self.initialized.write().await; |
| 486 | *init = true; |
| 487 | } |
| 488 | |
| 489 | Ok(()) |
| 490 | } |
| 491 | |
| 492 | /// Handle a server notification received during request/response. |
| 493 | async fn handle_notification(&self, notif: JsonRpcNotification) { |
no test coverage detected