@@ -797,14 +797,32 @@ export class MCPAgent {
797797 * Attempt to create structured output from raw result with validation and retry logic.
798798 */
799799 private async _attemptStructuredOutput < T > (
800- rawResult : string ,
800+ rawResult : string | any ,
801801 structuredLlm : BaseLanguageModelInterface ,
802802 outputSchema : ZodSchema < T > ,
803803 schemaDescription : string ,
804804 ) : Promise < T > {
805- logger . debug ( `🔄 Attempting structured output with schema: ${ outputSchema } ` )
806- logger . debug ( `🔄 Schema description: ${ schemaDescription } ` )
807- logger . debug ( `🔄 Raw result: ${ JSON . stringify ( rawResult , null , 2 ) } ` )
805+ logger . info ( `🔄 Attempting structured output with schema: ${ outputSchema } ` )
806+ logger . info ( `🔄 Schema description: ${ schemaDescription } ` )
807+ logger . info ( `🔄 Raw result: ${ JSON . stringify ( rawResult , null , 2 ) } ` )
808+
809+ // Handle different input formats - rawResult might be an array or object from the agent
810+ let textContent : string = '' ;
811+ if ( typeof rawResult === 'string' ) {
812+ textContent = rawResult ;
813+ }
814+ else if ( rawResult && typeof rawResult === 'object' ) {
815+ // Handle object format
816+ textContent = JSON . stringify ( rawResult ) ;
817+ }
818+
819+ // If we couldn't extract text, use the stringified version
820+ if ( ! textContent ) {
821+ textContent = JSON . stringify ( rawResult ) ;
822+ }
823+
824+
825+
808826 // Get detailed schema information for better prompting
809827 const maxRetries = 3
810828 let lastError : string = ''
@@ -819,8 +837,8 @@ export class MCPAgent {
819837 Required schema format:
820838 ${ schemaDescription }
821839
822- Content to format :
823- ${ rawResult }
840+ Content to extract from :
841+ ${ textContent }
824842
825843 IMPORTANT:
826844 - Use ONLY the field names specified in the schema
0 commit comments