File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -831,11 +831,29 @@ class FirebaseMcpServer {
831831 } ;
832832 } catch ( error ) {
833833 logger . error ( 'Error in collection group query:' , error ) ;
834+
835+ // Special handling for Firebase index errors
836+ const errorMessage = error instanceof Error ? error . message : 'Unknown error' ;
837+ if ( errorMessage . includes ( 'FAILED_PRECONDITION' ) && errorMessage . includes ( 'requires an index' ) ) {
838+ const indexUrl = errorMessage . match ( / h t t p s : \/ \/ c o n s o l e \. f i r e b a s e \. g o o g l e \. c o m [ ^ \s ] * / ) ?. [ 0 ] ;
839+ return {
840+ content : [ {
841+ type : 'text' ,
842+ text : JSON . stringify ( {
843+ error : 'This query requires a composite index.' ,
844+ details : 'When ordering by multiple fields or combining filters with ordering, you need to create a composite index.' ,
845+ indexUrl : indexUrl || null ,
846+ message : errorMessage
847+ } )
848+ } ]
849+ } ;
850+ }
851+
834852 return {
835853 content : [ {
836854 type : 'text' ,
837855 text : JSON . stringify ( {
838- error : error instanceof Error ? error . message : 'Unknown error'
856+ error : errorMessage
839857 } )
840858 } ]
841859 } ;
Original file line number Diff line number Diff line change @@ -747,13 +747,21 @@ describe('Firestore Client', () => {
747747 // Parse the response
748748 const responseData = JSON . parse ( result . content [ 0 ] . text ) ;
749749
750- // Verify documents array exists and has correct length
750+ // Verify documents array exists
751751 expect ( Array . isArray ( responseData . documents ) ) . toBe ( true ) ;
752- expect ( responseData . documents . length ) . toBe ( 2 ) ; // Should find both comments
752+
753+ // Instead of checking total count, filter to only include our test documents
754+ const testDocuments = responseData . documents . filter ( ( doc : any ) =>
755+ doc . path . includes ( `${ testCollection } /${ parentDoc1Id } /${ subcollectionName } ` ) ||
756+ doc . path . includes ( `${ testCollection } /${ parentDoc2Id } /${ subcollectionName } ` )
757+ ) ;
758+
759+ // Verify we have our 2 test documents
760+ expect ( testDocuments . length ) . toBe ( 2 ) ;
753761
754762 // Verify both documents are returned with correct data
755- const document1 = responseData . documents . find ( ( doc : any ) => doc . id === 'comment1' ) ;
756- const document2 = responseData . documents . find ( ( doc : any ) => doc . id === 'comment2' ) ;
763+ const document1 = testDocuments . find ( ( doc : any ) => doc . id === 'comment1' ) ;
764+ const document2 = testDocuments . find ( ( doc : any ) => doc . id === 'comment2' ) ;
757765
758766 expect ( document1 ) . toBeDefined ( ) ;
759767 expect ( document1 . data . author ) . toBe ( 'User A' ) ;
You can’t perform that action at this time.
0 commit comments