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

Function tool_result_to_string

core/src/mcp/manager.rs:432–456  ·  view source on GitHub ↗

Convert MCP tool result to string output

(result: &CallToolResult)

Source from the content-addressed store, hash-verified

430
431/// Convert MCP tool result to string output
432pub 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)]
459mod tests {

Calls

no outgoing calls