Skip to content
Closed
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
3 changes: 1 addition & 2 deletions crates/rmcp/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1262,10 +1262,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
23 changes: 1 addition & 22 deletions crates/rmcp/tests/test_structured_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use rmcp::{
Json, ServerHandler,
handler::server::{router::tool::ToolRouter, tool::Parameters},
model::{CallToolResult, Content, Tool},
model::{CallToolResult, Tool},
tool, tool_handler, tool_router,
};
use schemars::JsonSchema;
Expand Down Expand Up @@ -144,27 +144,6 @@ async fn test_structured_error_in_call_result() {
assert_eq!(result.is_error, Some(true));
}

#[tokio::test]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe keep the test and check that it it doesn't error at the end?

async fn test_mutual_exclusivity_validation() {
// Test that content and structured_content are mutually exclusive
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!({
"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());
}

#[tokio::test]
async fn test_structured_return_conversion() {
// Test that Json<T> converts to CallToolResult with structured_content
Expand Down