fix: match shape of the calltoolresult schema (#377)

BREAKING CHANGE: makes the `content` field non-optional
This commit is contained in:
Peter L 2025-08-19 15:58:25 +09:30 • committed by GitHub
commit a47cbaac4b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 26 additions and 29 deletions

View file

@ -304,10 +304,7 @@
"properties": {
"content": {
"description": "The content returned by the tool (text, images, etc.)",
"type": [
"array",
"null"
],
"type": "array",
"items": {
"$ref": "#/definitions/Annotated"
}
@ -322,7 +319,10 @@
"structuredContent": {
"description": "An optional JSON object that represents the structured result of the tool call"
}
}
},
"required": [
"content"
]
},
"CancelledNotificationMethod": {
"type": "string",

View file

@ -122,10 +122,10 @@ async fn test_structured_content_in_call_result() {
let result = CallToolResult::structured(structured_data.clone());
assert!(result.content.is_some());
assert!(!result.content.is_empty());
assert!(result.structured_content.is_some());
let contents = result.content.unwrap();
let contents = result.content;
assert_eq!(contents.len(), 1);
@ -150,10 +150,10 @@ async fn test_structured_error_in_call_result() {
let result = CallToolResult::structured_error(error_data.clone());
assert!(result.content.is_some());
assert!(!result.content.is_empty());
assert!(result.structured_content.is_some());
let contents = result.content.unwrap();
let contents = result.content;
assert_eq!(contents.len(), 1);
@ -217,10 +217,10 @@ async fn test_structured_return_conversion() {
// Tools which return structured content should also return a serialized version as
// Content::text for backwards compatibility.
assert!(call_result.content.is_some());
assert!(!call_result.content.is_empty());
assert!(call_result.structured_content.is_some());
let contents = call_result.content.unwrap();
let contents = call_result.content;
assert_eq!(contents.len(), 1);
@ -278,5 +278,5 @@ async fn test_output_schema_requires_structured_content() {
// Verify it has structured_content and content
assert!(call_result.structured_content.is_some());
assert!(call_result.content.is_some());
assert!(!call_result.content.is_empty());
}

View file

@ -301,8 +301,7 @@ async fn test_optional_i64_field_with_null_input() -> anyhow::Result<()> {
let result_text = result
.content
.as_ref()
.and_then(|contents| contents.first())
.first()
.and_then(|content| content.raw.as_text())
.map(|text| text.text.as_str())
.expect("Expected text content");
@ -330,8 +329,7 @@ async fn test_optional_i64_field_with_null_input() -> anyhow::Result<()> {
let some_result_text = some_result
.content
.as_ref()
.and_then(|contents| contents.first())
.first()
.and_then(|content| content.raw.as_text())
.map(|text| text.text.as_str())
.expect("Expected text content");