@@ -183,7 +183,7 @@ impl<'de> Deserialize<'de> for ProtocolVersion {
183183pub enum NumberOrString {
184184 /// A numeric identifier
185185 Number ( u32 ) ,
186- /// A string identifier
186+ /// A string identifier
187187 String ( Arc < str > ) ,
188188}
189189
@@ -1257,8 +1257,7 @@ pub type CreateElicitationRequest =
12571257#[ cfg_attr( feature = "schemars" , derive( schemars:: JsonSchema ) ) ]
12581258pub struct CallToolResult {
12591259 /// The content returned by the tool (text, images, etc.)
1260- #[ serde( skip_serializing_if = "Option::is_none" ) ]
1261- pub content : Option < Vec < Content > > ,
1260+ pub content : Vec < Content > ,
12621261 /// An optional JSON object that represents the structured result of the tool call
12631262 #[ serde( skip_serializing_if = "Option::is_none" ) ]
12641263 pub structured_content : Option < Value > ,
@@ -1271,15 +1270,15 @@ impl CallToolResult {
12711270 /// Create a successful tool result with unstructured content
12721271 pub fn success ( content : Vec < Content > ) -> Self {
12731272 CallToolResult {
1274- content : Some ( content ) ,
1273+ content,
12751274 structured_content : None ,
12761275 is_error : Some ( false ) ,
12771276 }
12781277 }
12791278 /// Create an error tool result with unstructured content
12801279 pub fn error ( content : Vec < Content > ) -> Self {
12811280 CallToolResult {
1282- content : Some ( content ) ,
1281+ content,
12831282 structured_content : None ,
12841283 is_error : Some ( true ) ,
12851284 }
@@ -1300,7 +1299,7 @@ impl CallToolResult {
13001299 /// ```
13011300 pub fn structured ( value : Value ) -> Self {
13021301 CallToolResult {
1303- content : Some ( vec ! [ Content :: text( value. to_string( ) ) ] ) ,
1302+ content : vec ! [ Content :: text( value. to_string( ) ) ] ,
13041303 structured_content : Some ( value) ,
13051304 is_error : Some ( false ) ,
13061305 }
@@ -1325,7 +1324,7 @@ impl CallToolResult {
13251324 /// ```
13261325 pub fn structured_error ( value : Value ) -> Self {
13271326 CallToolResult {
1328- content : Some ( vec ! [ Content :: text( value. to_string( ) ) ] ) ,
1327+ content : vec ! [ Content :: text( value. to_string( ) ) ] ,
13291328 structured_content : Some ( value) ,
13301329 is_error : Some ( true ) ,
13311330 }
@@ -1341,10 +1340,10 @@ impl CallToolResult {
13411340 where
13421341 T : DeserializeOwned ,
13431342 {
1344- let raw_text = match ( self . structured_content , & self . content ) {
1343+ let raw_text = match ( self . structured_content , & self . content . first ( ) ) {
13451344 ( Some ( value) , _) => return serde_json:: from_value ( value) ,
13461345 ( None , Some ( contents) ) => {
1347- if let Some ( text) = contents. first ( ) . and_then ( |c| c . as_text ( ) ) {
1346+ if let Some ( text) = contents. as_text ( ) {
13481347 let text = & text. text ;
13491348 Some ( text)
13501349 } else {
@@ -1379,13 +1378,13 @@ impl<'de> Deserialize<'de> for CallToolResult {
13791378
13801379 let helper = CallToolResultHelper :: deserialize ( deserializer) ?;
13811380 let result = CallToolResult {
1382- content : helper. content ,
1381+ content : helper. content . unwrap_or_default ( ) ,
13831382 structured_content : helper. structured_content ,
13841383 is_error : helper. is_error ,
13851384 } ;
13861385
13871386 // Validate mutual exclusivity
1388- if result. content . is_none ( ) && result. structured_content . is_none ( ) {
1387+ if result. content . is_empty ( ) && result. structured_content . is_none ( ) {
13891388 return Err ( serde:: de:: Error :: custom (
13901389 "CallToolResult must have either content or structured_content" ,
13911390 ) ) ;
0 commit comments