Convert MCP tool result to string output
(result: &CallToolResult)
| 430 | |
| 431 | /// Convert MCP tool result to string output |
| 432 | pub fn tool_result_to_string(result: &CallToolResult) -> String { |
| 433 | let mut output = String::new(); |
| 434 | |
| 435 | for content in &result.content { |
| 436 | match content { |
| 437 | ToolContent::Text { text } => { |
| 438 | output.push_str(text); |
| 439 | output.push('\n'); |
| 440 | } |
| 441 | ToolContent::Image { data: _, mime_type } => { |
| 442 | output.push_str(&format!("[Image: {}]\n", mime_type)); |
| 443 | } |
| 444 | ToolContent::Resource { resource } => { |
| 445 | if let Some(text) = &resource.text { |
| 446 | output.push_str(text); |
| 447 | output.push('\n'); |
| 448 | } else { |
| 449 | output.push_str(&format!("[Resource: {}]\n", resource.uri)); |
| 450 | } |
| 451 | } |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | output.trim_end().to_string() |
| 456 | } |
| 457 | |
| 458 | #[cfg(test)] |
| 459 | mod tests { |
no outgoing calls