Skip to content
Open
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
4 changes: 2 additions & 2 deletions crates/rmcp/src/model/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! The various content types can be display to humans but also understood by models
//! They include optional annotations used to help inform agent usage
use serde::{Deserialize, Serialize};
use serde_json::json;
use serde_json::{Value, json};

use super::{AnnotateAble, Annotated, resource::ResourceContents};

Expand Down Expand Up @@ -107,7 +107,7 @@ pub struct ToolResultContent {
pub content: Vec<Content>,
/// Optional structured result
#[serde(skip_serializing_if = "Option::is_none")]
pub structured_content: Option<super::JsonObject>,
pub structured_content: Option<Value>,
/// Whether tool execution failed
#[serde(skip_serializing_if = "Option::is_none")]
pub is_error: Option<bool>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2118,12 +2118,7 @@
]
},
"structuredContent": {
"description": "Optional structured result",
"type": [
"object",
"null"
],
"additionalProperties": true
"description": "Optional structured result"
},
"toolUseId": {
"description": "ID of the corresponding tool use",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2118,12 +2118,7 @@
]
},
"structuredContent": {
"description": "Optional structured result",
"type": [
"object",
"null"
],
"additionalProperties": true
"description": "Optional structured result"
},
"toolUseId": {
"description": "ID of the corresponding tool use",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3467,12 +3467,7 @@
]
},
"structuredContent": {
"description": "Optional structured result",
"type": [
"object",
"null"
],
"additionalProperties": true
"description": "Optional structured result"
},
"toolUseId": {
"description": "ID of the corresponding tool use",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3467,12 +3467,7 @@
]
},
"structuredContent": {
"description": "Optional structured result",
"type": [
"object",
"null"
],
"additionalProperties": true
"description": "Optional structured result"
},
"toolUseId": {
"description": "ID of the corresponding tool use",
Expand Down
32 changes: 32 additions & 0 deletions crates/rmcp/tests/test_sampling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,38 @@ async fn test_tool_result_content_serialization() -> Result<()> {
Ok(())
}

#[tokio::test]
async fn test_tool_result_content_with_array_structured_content() -> Result<()> {
let structured =
serde_json::json!([{ "city": "SF", "temp": 72 }, { "city": "NY", "temp": 65 }]);
let mut tool_result = ToolResultContent::new("call_123", vec![Content::text("forecast")]);
tool_result.structured_content = Some(structured);

let json = serde_json::to_string(&tool_result)?;
let deserialized: ToolResultContent = serde_json::from_str(&json)?;
assert_eq!(tool_result, deserialized);
assert!(deserialized.structured_content.unwrap().is_array());

Ok(())
}

#[tokio::test]
async fn test_tool_result_content_with_primitive_structured_content() -> Result<()> {
let structured = serde_json::json!(42);
let mut tool_result = ToolResultContent::new("call_123", vec![Content::text("count")]);
tool_result.structured_content = Some(structured);

let json = serde_json::to_string(&tool_result)?;
let deserialized: ToolResultContent = serde_json::from_str(&json)?;
assert_eq!(tool_result, deserialized);
assert!(matches!(
deserialized.structured_content,
Some(serde_json::Value::Number(_))
));

Ok(())
}

#[tokio::test]
async fn test_sampling_message_with_tool_use() -> Result<()> {
let message = SamplingMessage::assistant_tool_use(
Expand Down