diff --git a/crates/rmcp/src/model.rs b/crates/rmcp/src/model.rs index f0c92c0a..56e484b1 100644 --- a/crates/rmcp/src/model.rs +++ b/crates/rmcp/src/model.rs @@ -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(()), } diff --git a/crates/rmcp/tests/test_structured_output.rs b/crates/rmcp/tests/test_structured_output.rs index 7e85d0e7..8b6cb0cb 100644 --- a/crates/rmcp/tests/test_structured_output.rs +++ b/crates/rmcp/tests/test_structured_output.rs @@ -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; @@ -144,27 +144,6 @@ async fn test_structured_error_in_call_result() { assert_eq!(result.is_error, Some(true)); } -#[tokio::test] -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 = serde_json::from_value(invalid_json); - assert!(deserialized.is_err()); -} - #[tokio::test] async fn test_structured_return_conversion() { // Test that Json converts to CallToolResult with structured_content