pub struct CallToolResult {
pub content: Vec<ContentBlock>,
pub is_error: Option<bool>,
pub structured_content: Option<Value>,
pub _meta: Option<Value>,
}Expand description
The result of a CallToolRequest.
Fields§
§content: Vec<ContentBlock>The output of the tool, typically as a series of text or other content blocks. This is required.
is_error: Option<bool>An optional boolean indicating whether the tool execution resulted in an error.
When is_error is true, all content blocks should be treated as error information.
The error message may span multiple text blocks for structured error reporting.
structured_content: Option<Value>Optional structured output from the tool, conforming to its output_schema.
When present, this contains schema-validated JSON output that clients can parse and use programmatically. Tools that return structured content SHOULD also include the serialized JSON in a TextContent block for backward compatibility with clients that don’t support structured output.
See Tool::output_schema for defining the expected structure.
_meta: Option<Value>Optional metadata for the result.
This field is for client applications and tools to pass additional context that should NOT be exposed to LLMs. Examples include tracking IDs, performance metrics, cache status, or internal state information.
Implementations§
Source§impl CallToolResult
impl CallToolResult
Sourcepub fn all_text(&self) -> String
pub fn all_text(&self) -> String
Extracts and concatenates all text content from the result.
This is useful for simple text-only tools or when you want to present all textual output as a single string.
§Returns
A single string containing all text blocks concatenated with newlines. Returns an empty string if there are no text blocks.
§Example
use turbomcp_protocol::types::{CallToolResult, ContentBlock, TextContent};
let result = CallToolResult {
content: vec![
ContentBlock::Text(TextContent {
text: "Line 1".to_string(),
annotations: None,
meta: None,
}),
ContentBlock::Text(TextContent {
text: "Line 2".to_string(),
annotations: None,
meta: None,
}),
],
is_error: None,
structured_content: None,
_meta: None,
};
assert_eq!(result.all_text(), "Line 1\nLine 2");Sourcepub fn first_text(&self) -> Option<&str>
pub fn first_text(&self) -> Option<&str>
Returns the text content of the first text block, if any.
This is a common pattern for simple tools that return a single text response.
§Returns
Some(&str) if the first content block is text, None otherwise.
§Example
use turbomcp_protocol::types::{CallToolResult, ContentBlock, TextContent};
let result = CallToolResult {
content: vec![
ContentBlock::Text(TextContent {
text: "Hello, world!".to_string(),
annotations: None,
meta: None,
}),
],
is_error: None,
structured_content: None,
_meta: None,
};
assert_eq!(result.first_text(), Some("Hello, world!"));Sourcepub fn has_error(&self) -> bool
pub fn has_error(&self) -> bool
Checks if the tool execution resulted in an error.
§Returns
true if is_error is explicitly set to true, false otherwise
(including when is_error is None).
§Example
use turbomcp_protocol::types::CallToolResult;
let success_result = CallToolResult {
content: vec![],
is_error: Some(false),
structured_content: None,
_meta: None,
};
assert!(!success_result.has_error());
let error_result = CallToolResult {
content: vec![],
is_error: Some(true),
structured_content: None,
_meta: None,
};
assert!(error_result.has_error());
let unspecified_result = CallToolResult {
content: vec![],
is_error: None,
structured_content: None,
_meta: None,
};
assert!(!unspecified_result.has_error());Sourcepub fn to_display_string(&self) -> String
pub fn to_display_string(&self) -> String
Creates a user-friendly display string for the tool result.
This method provides a formatted representation suitable for logging, debugging, or displaying to end users. It handles multiple content types and includes structured content and error information when present.
§Returns
A formatted string representing the tool result.
§Example
use turbomcp_protocol::types::{CallToolResult, ContentBlock, TextContent};
let result = CallToolResult {
content: vec![
ContentBlock::Text(TextContent {
text: "Operation completed".to_string(),
annotations: None,
meta: None,
}),
],
is_error: Some(false),
structured_content: None,
_meta: None,
};
let display = result.to_display_string();
assert!(display.contains("Operation completed"));Trait Implementations§
Source§impl Clone for CallToolResult
impl Clone for CallToolResult
Source§fn clone(&self) -> CallToolResult
fn clone(&self) -> CallToolResult
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more