-
Notifications
You must be signed in to change notification settings - Fork 442
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
Merged
4t145
merged 1 commit into
modelcontextprotocol:main
from
cetra3:match_mcp_calltoolresult_schema
Aug 19, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() { | ||
|
||
| 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", | ||
| )); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.