@@ -306,26 +306,28 @@ async def _get_initial_state_from_mcp_resource(self, session: MCPSession) -> Any
306306 resource_content = await mcp_session .read_resource (initial_state_resource .uri )
307307
308308 # Handle the new ResourceContents format
309- if hasattr (resource_content , "text" ):
309+ text_value = getattr (resource_content , "text" , None )
310+ if text_value is not None :
310311 try :
311- initial_observation = json .loads (resource_content . text )
312+ initial_observation = json .loads (text_value )
312313 logger .info (
313314 f"Session { session .session_id } : ✅ Successfully parsed JSON initial state with grid_layout: { initial_observation .get ('grid_layout' , 'N/A' )[:20 ]} ..."
314315 )
315316 except json .JSONDecodeError :
316- initial_observation = {"observation" : resource_content . text }
317+ initial_observation = {"observation" : text_value }
317318 elif (
318319 hasattr (resource_content , "contents" )
319320 and resource_content .contents
320321 and len (resource_content .contents ) > 0
321322 ):
322323 # Fallback to old format for backward compatibility
323324 content = resource_content .contents [0 ]
324- if hasattr (content , "text" ):
325+ content_text = getattr (content , "text" , None )
326+ if content_text is not None :
325327 try :
326- initial_observation = json .loads (content . text )
328+ initial_observation = json .loads (content_text )
327329 except json .JSONDecodeError :
328- initial_observation = {"observation" : content . text }
330+ initial_observation = {"observation" : content_text }
329331 else :
330332 initial_observation = {"observation" : str (resource_content )}
331333 else :
@@ -359,23 +361,25 @@ async def _get_initial_state_from_mcp_resource(self, session: MCPSession) -> Any
359361 )
360362
361363 # Handle the new ResourceContents format
362- if hasattr (resource_content , "text" ):
364+ text_value_2 = getattr (resource_content , "text" , None )
365+ if text_value_2 is not None :
363366 try :
364- initial_observation = json .loads (resource_content . text )
367+ initial_observation = json .loads (text_value_2 )
365368 except json .JSONDecodeError :
366- initial_observation = {"observation" : resource_content . text }
369+ initial_observation = {"observation" : text_value_2 }
367370 elif (
368371 hasattr (resource_content , "contents" )
369372 and resource_content .contents
370373 and len (resource_content .contents ) > 0
371374 ):
372375 # Fallback to old format for backward compatibility
373376 content = resource_content .contents [0 ]
374- if hasattr (content , "text" ):
377+ content_text_2 = getattr (content , "text" , None )
378+ if content_text_2 is not None :
375379 try :
376- initial_observation = json .loads (content . text )
380+ initial_observation = json .loads (content_text_2 )
377381 except json .JSONDecodeError :
378- initial_observation = {"observation" : content . text }
382+ initial_observation = {"observation" : content_text_2 }
379383 else :
380384 initial_observation = {"observation" : str (content )}
381385 else :
0 commit comments