Skip to content

Commit b8a936c

Browse files
authored
feat!: relax tool result structuredContent type (modelcontextprotocol#919)
1 parent 4158528 commit b8a936c

6 files changed

Lines changed: 38 additions & 30 deletions

File tree

crates/rmcp/src/model/content.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// ToolUseContent/ToolResultContent are SEP-2577-deprecated; internal references are expected.
1111
#![expect(deprecated)]
1212
use serde::{Deserialize, Serialize};
13-
use serde_json::json;
13+
use serde_json::{Value, json};
1414

1515
use super::{Annotations, Meta, resource::ResourceContents};
1616

@@ -207,7 +207,7 @@ pub struct ToolResultContent {
207207
pub tool_use_id: String,
208208
pub content: Vec<ContentBlock>,
209209
#[serde(skip_serializing_if = "Option::is_none")]
210-
pub structured_content: Option<super::JsonObject>,
210+
pub structured_content: Option<Value>,
211211
#[serde(skip_serializing_if = "Option::is_none")]
212212
pub is_error: Option<bool>,
213213
}

crates/rmcp/tests/test_message_schema/client_json_rpc_message_schema.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2352,13 +2352,7 @@
23522352
"null"
23532353
]
23542354
},
2355-
"structuredContent": {
2356-
"type": [
2357-
"object",
2358-
"null"
2359-
],
2360-
"additionalProperties": true
2361-
},
2355+
"structuredContent": true,
23622356
"toolUseId": {
23632357
"type": "string"
23642358
}

crates/rmcp/tests/test_message_schema/client_json_rpc_message_schema_current.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2352,13 +2352,7 @@
23522352
"null"
23532353
]
23542354
},
2355-
"structuredContent": {
2356-
"type": [
2357-
"object",
2358-
"null"
2359-
],
2360-
"additionalProperties": true
2361-
},
2355+
"structuredContent": true,
23622356
"toolUseId": {
23632357
"type": "string"
23642358
}

crates/rmcp/tests/test_message_schema/server_json_rpc_message_schema.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3454,13 +3454,7 @@
34543454
"null"
34553455
]
34563456
},
3457-
"structuredContent": {
3458-
"type": [
3459-
"object",
3460-
"null"
3461-
],
3462-
"additionalProperties": true
3463-
},
3457+
"structuredContent": true,
34643458
"toolUseId": {
34653459
"type": "string"
34663460
}

crates/rmcp/tests/test_message_schema/server_json_rpc_message_schema_current.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3454,13 +3454,7 @@
34543454
"null"
34553455
]
34563456
},
3457-
"structuredContent": {
3458-
"type": [
3459-
"object",
3460-
"null"
3461-
],
3462-
"additionalProperties": true
3463-
},
3457+
"structuredContent": true,
34643458
"toolUseId": {
34653459
"type": "string"
34663460
}

crates/rmcp/tests/test_sampling.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,38 @@ fn test_tool_result_content_requires_content() {
370370
assert!(err.to_string().contains("missing field `content`"));
371371
}
372372

373+
#[tokio::test]
374+
async fn test_tool_result_content_with_array_structured_content() -> Result<()> {
375+
let structured =
376+
serde_json::json!([{ "city": "SF", "temp": 72 }, { "city": "NY", "temp": 65 }]);
377+
let mut tool_result = ToolResultContent::new("call_123", vec![ContentBlock::text("forecast")]);
378+
tool_result.structured_content = Some(structured);
379+
380+
let json = serde_json::to_string(&tool_result)?;
381+
let deserialized: ToolResultContent = serde_json::from_str(&json)?;
382+
assert_eq!(tool_result, deserialized);
383+
assert!(deserialized.structured_content.unwrap().is_array());
384+
385+
Ok(())
386+
}
387+
388+
#[tokio::test]
389+
async fn test_tool_result_content_with_primitive_structured_content() -> Result<()> {
390+
let structured = serde_json::json!(42);
391+
let mut tool_result = ToolResultContent::new("call_123", vec![ContentBlock::text("count")]);
392+
tool_result.structured_content = Some(structured);
393+
394+
let json = serde_json::to_string(&tool_result)?;
395+
let deserialized: ToolResultContent = serde_json::from_str(&json)?;
396+
assert_eq!(tool_result, deserialized);
397+
assert!(matches!(
398+
deserialized.structured_content,
399+
Some(serde_json::Value::Number(_))
400+
));
401+
402+
Ok(())
403+
}
404+
373405
#[tokio::test]
374406
async fn test_sampling_message_with_tool_use() -> Result<()> {
375407
let message = SamplingMessage::assistant_tool_use(

0 commit comments

Comments
 (0)