Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 629
Match the shape of CallToolResult schema#377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -181,7 +181,7 @@ impl<'de> Deserialize<'de> for ProtocolVersion { | ||
| pub enum NumberOrString { | ||
| /// A numeric identifier | ||
| Number(u32), | ||
| /// A string identifier | ||
| /// A string identifier | ||
| String(Arc<str>), | ||
| } | ||
| @@ -1186,8 +1186,7 @@ pub type RootsListChangedNotification = NotificationNoParam<RootsListChangedNoti | ||
| #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] | ||
| pub struct CallToolResult { | ||
| /// The content returned by the tool (text, images, etc.) | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| pub content: Option<Vec<Content>>, | ||
| pub content: Vec<Content>, | ||
| /// An optional JSON object that represents the structured result of the tool call | ||
| #[serde(skip_serializing_if = "Option::is_none")] | ||
| pub structured_content: Option<Value>, | ||
| @@ -1200,15 +1199,15 @@ impl CallToolResult { | ||
| /// Create a successful tool result with unstructured content | ||
| pub fn success(content: Vec<Content>) -> Self { | ||
| CallToolResult { | ||
| content: Some(content), | ||
| content, | ||
| structured_content: None, | ||
| is_error: Some(false), | ||
| } | ||
| } | ||
| /// Create an error tool result with unstructured content | ||
| pub fn error(content: Vec<Content>) -> Self { | ||
| CallToolResult { | ||
| content: Some(content), | ||
| content, | ||
| structured_content: None, | ||
| is_error: Some(true), | ||
| } | ||
| @@ -1229,7 +1228,7 @@ impl CallToolResult { | ||
| /// ``` | ||
| pub fn structured(value: Value) -> Self { | ||
| CallToolResult { | ||
| content: Some(vec![Content::text(value.to_string())]), | ||
| content: vec![Content::text(value.to_string())], | ||
| structured_content: Some(value), | ||
| is_error: Some(false), | ||
| } | ||
| @@ -1254,7 +1253,7 @@ impl CallToolResult { | ||
| /// ``` | ||
| pub fn structured_error(value: Value) -> Self { | ||
| CallToolResult { | ||
| content: Some(vec![Content::text(value.to_string())]), | ||
| content: vec![Content::text(value.to_string())], | ||
| structured_content: Some(value), | ||
| is_error: Some(true), | ||
| } | ||
| @@ -1270,10 +1269,10 @@ impl CallToolResult { | ||
| where | ||
| T: DeserializeOwned, | ||
| { | ||
| let raw_text = match (self.structured_content, &self.content) { | ||
| let raw_text = match (self.structured_content, &self.content.first()) { | ||
| (Some(value), _) => return serde_json::from_value(value), | ||
| (None, Some(contents)) => { | ||
| if let Some(text) = contents.first().and_then(|c| c.as_text()) { | ||
| if let Some(text) = contents.as_text() { | ||
CopilotAI | ||
| let text = &text.text; | ||
| Some(text) | ||
| } else { | ||
| @@ -1308,13 +1307,13 @@ impl<'de> Deserialize<'de> for CallToolResult { | ||
| let helper = CallToolResultHelper::deserialize(deserializer)?; | ||
| let result = CallToolResult { | ||
| content: helper.content, | ||
| content: helper.content.unwrap_or_default(), | ||
| structured_content: helper.structured_content, | ||
| is_error: helper.is_error, | ||
| }; | ||
| // Validate mutual exclusivity | ||
| if result.content.is_none() && result.structured_content.is_none() { | ||
| if result.content.is_empty() && result.structured_content.is_none() { | ||
| return Err(serde::de::Error::custom( | ||
| "CallToolResult must have either content or structured_content", | ||
| )); | ||
CopilotAIAug 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pattern match
(None, Some(contents))is unreachable becauseself.contentis now aVec<Content>(notOption<Vec<Content>>), so it can never beSome(contents). This should be(None, contents)and the condition should check ifcontentsis not empty.