Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions crates/rmcp/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1181,8 +1181,6 @@ pub type RootsListChangedNotification = NotificationNoParam<RootsListChangedNoti
///
/// Contains the content returned by the tool execution and an optional
/// flag indicating whether the operation resulted in an error.
///
/// Note: `content` and `structured_content` are mutually exclusive - exactly one must be provided.
#[derive(Debug, Serialize, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
Expand Down Expand Up @@ -1262,10 +1260,9 @@ impl CallToolResult {
}
}

/// Validate that content and structured_content are mutually exclusive
/// Validate that content or structured content is provided
pub fn validate(&self) -> Result<(), &'static str> {
match (&self.content, &self.structured_content) {
(Some(_), Some(_)) => Err("content and structured_content are mutually exclusive"),
(None, None) => Err("either content or structured_content must be provided"),
_ => Ok(()),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@
}
},
"CallToolResult": {
"description": "The result of a tool call operation.\n\nContains the content returned by the tool execution and an optional\nflag indicating whether the operation resulted in an error.\n\nNote: `content` and `structured_content` are mutually exclusive - exactly one must be provided.",
"description": "The result of a tool call operation.\n\nContains the content returned by the tool execution and an optional\nflag indicating whether the operation resulted in an error.",
"type": "object",
"properties": {
"content": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@
}
},
"CallToolResult": {
"description": "The result of a tool call operation.\n\nContains the content returned by the tool execution and an optional\nflag indicating whether the operation resulted in an error.\n\nNote: `content` and `structured_content` are mutually exclusive - exactly one must be provided.",
"description": "The result of a tool call operation.\n\nContains the content returned by the tool execution and an optional\nflag indicating whether the operation resulted in an error.",
"type": "object",
"properties": {
"content": {
Expand Down Expand Up @@ -1336,7 +1336,7 @@
{
"type": "object",
"properties": {
"mime_type": {
"mimeType": {
"type": [
"string",
"null"
Expand All @@ -1360,7 +1360,7 @@
"blob": {
"type": "string"
},
"mime_type": {
"mimeType": {
"type": [
"string",
"null"
Expand Down
12 changes: 6 additions & 6 deletions crates/rmcp/tests/test_structured_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,23 +146,23 @@ async fn test_structured_error_in_call_result() {

#[tokio::test]
async fn test_mutual_exclusivity_validation() {
// Test that content and structured_content are mutually exclusive
// Test that content and structured_content can both be passed separately
let content_result = CallToolResult::success(vec![Content::text("Hello")]);
let structured_result = CallToolResult::structured(json!({"message": "Hello"}));

// Verify the validation
assert!(content_result.validate().is_ok());
assert!(structured_result.validate().is_ok());

// Try to create an invalid result with both fields
let invalid_json = json!({
// Try to create a result with both fields
let json_with_both = json!({
"content": [{"type": "text", "text": "Hello"}],
"structuredContent": {"message": "Hello"}
});

// The deserialization itself should fail due to validation
let deserialized: Result<CallToolResult, _> = serde_json::from_value(invalid_json);
assert!(deserialized.is_err());
// The deserialization itself should not fail
let deserialized: Result<CallToolResult, _> = serde_json::from_value(json_with_both);
assert!(deserialized.is_ok());
}

#[tokio::test]
Expand Down