From 1ae29199967a143d140968f1a8343feb685c1abc Mon Sep 17 00:00:00 2001 From: Michael Neale Date: Thu, 7 Aug 2025 10:29:02 +1000 Subject: [PATCH 1/2] allow backwards compat as per MCP spec --- crates/rmcp/src/model.rs | 3 +-- crates/rmcp/tests/test_structured_output.rs | 21 --------------------- 2 files changed, 1 insertion(+), 23 deletions(-) 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..92aa27f9 100644 --- a/crates/rmcp/tests/test_structured_output.rs +++ b/crates/rmcp/tests/test_structured_output.rs @@ -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 From 7f33cdf13ce1812decd3666f61d40b7cbe92610a Mon Sep 17 00:00:00 2001 From: Michael Neale Date: Thu, 7 Aug 2025 13:42:39 +1000 Subject: [PATCH 2/2] fix(model): remove unneeded import --- crates/rmcp/tests/test_structured_output.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/rmcp/tests/test_structured_output.rs b/crates/rmcp/tests/test_structured_output.rs index 92aa27f9..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;