(
&self,
name: &str,
arguments: Option<serde_json::Value>,
)
| 562 | } |
| 563 | |
| 564 | pub async fn call_tool( |
| 565 | &self, |
| 566 | name: &str, |
| 567 | arguments: Option<serde_json::Value>, |
| 568 | ) -> Result<CallToolResult, McpClientError> { |
| 569 | let params = CallToolParams { |
| 570 | name: name.to_string(), |
| 571 | arguments, |
| 572 | }; |
| 573 | |
| 574 | let params_value = serde_json::to_value(params) |
| 575 | .map_err(|e| McpClientError::ProtocolError(e.to_string()))?; |
| 576 | |
| 577 | let response = self |
| 578 | .send_request_with_progress_timeout("tools/call", Some(params_value), self.timeout_ms) |
| 579 | .await?; |
| 580 | |
| 581 | // After tool call, check if tools changed notification was received |
| 582 | self.refresh_tools_if_needed().await.ok(); |
| 583 | |
| 584 | let result: CallToolResult = response |
| 585 | .result |
| 586 | .ok_or_else(|| McpClientError::ProtocolError("No result in tools/call response".into())) |
| 587 | .and_then(|r| { |
| 588 | serde_json::from_value(r).map_err(|e| { |
| 589 | McpClientError::ProtocolError(format!("Failed to parse tools/call result: {e}")) |
| 590 | }) |
| 591 | })?; |
| 592 | |
| 593 | Ok(result) |
| 594 | } |
| 595 | |
| 596 | pub async fn read_resource(&self, uri: &str) -> Result<ReadResourceResult, McpClientError> { |
| 597 | let params = ReadResourceParams { |
no test coverage detected