1
- import { beforeEach , describe , expect , it , vi } from "vitest" ;
1
+ import { afterEach , beforeEach , describe , expect , it , vi } from "vitest" ;
2
2
import type { Document , Collection } from "mongodb" ;
3
3
import {
4
4
getResponseContent ,
@@ -228,37 +228,38 @@ describeWithMongoDB("find tool", (integration) => {
228
228
describeWithMongoDB (
229
229
"find tool with configured max documents per query" ,
230
230
( integration ) => {
231
+ beforeEach ( async ( ) => {
232
+ await freshInsertDocuments ( {
233
+ collection : integration . mongoClient ( ) . db ( integration . randomDbName ( ) ) . collection ( "foo" ) ,
234
+ count : 1000 ,
235
+ } ) ;
236
+ } ) ;
237
+
238
+ afterEach ( ( ) => {
239
+ vi . resetAllMocks ( ) ;
240
+ } ) ;
241
+
231
242
describe ( "when the provided limit is lower than the configured max limit" , ( ) => {
232
243
it ( "should return documents limited to the provided limit" , async ( ) => {
233
- await freshInsertDocuments ( {
234
- collection : integration . mongoClient ( ) . db ( integration . randomDbName ( ) ) . collection ( "foo" ) ,
235
- count : 1000 ,
236
- } ) ;
237
244
await integration . connectMcpClient ( ) ;
238
245
const response = await integration . mcpClient ( ) . callTool ( {
239
246
name : "find" ,
240
247
arguments : {
241
248
database : integration . randomDbName ( ) ,
242
249
collection : "foo" ,
243
250
filter : { } ,
244
- // default is 10
245
- limit : undefined ,
251
+ limit : 8 ,
246
252
} ,
247
253
} ) ;
248
254
249
255
const content = getResponseContent ( response ) ;
250
- expect ( content ) . toContain ( `Query on collection "foo" resulted in 10 documents.` ) ;
251
- expect ( content ) . toContain ( `Returning 10 documents while respecting the applied limits.` ) ;
256
+ expect ( content ) . toContain ( `Query on collection "foo" resulted in 8 documents.` ) ;
257
+ expect ( content ) . toContain ( `Returning 8 documents while respecting the applied limits.` ) ;
252
258
} ) ;
253
259
} ) ;
254
260
255
261
describe ( "when the provided limit is larger than the configured max limit" , ( ) => {
256
262
it ( "should return documents limited to the configured max limit" , async ( ) => {
257
- await freshInsertDocuments ( {
258
- collection : integration . mongoClient ( ) . db ( integration . randomDbName ( ) ) . collection ( "foo" ) ,
259
- count : 1000 ,
260
- } ) ;
261
-
262
263
await integration . connectMcpClient ( ) ;
263
264
const response = await integration . mcpClient ( ) . callTool ( {
264
265
name : "find" ,
@@ -272,17 +273,13 @@ describeWithMongoDB(
272
273
273
274
const content = getResponseContent ( response ) ;
274
275
expect ( content ) . toContain ( `Query on collection "foo" resulted in 1000 documents.` ) ;
275
- expect ( content ) . toContain ( `Returning 20 documents while respecting the applied limits.` ) ;
276
+ expect ( content ) . toContain ( `Returning 10 documents while respecting the applied limits.` ) ;
276
277
} ) ;
277
278
} ) ;
278
279
279
280
describe ( "when counting documents exceed the configured count maxTimeMS" , ( ) => {
280
- it ( "should abort discard count operation and respond with indeterminable count" , async ( ) => {
281
+ it ( "should abort count operation and respond with indeterminable count" , async ( ) => {
281
282
vi . spyOn ( constants , "QUERY_COUNT_MAX_TIME_MS_CAP" , "get" ) . mockReturnValue ( 0.1 ) ;
282
- await freshInsertDocuments ( {
283
- collection : integration . mongoClient ( ) . db ( integration . randomDbName ( ) ) . collection ( "foo" ) ,
284
- count : 1000 ,
285
- } ) ;
286
283
await integration . connectMcpClient ( ) ;
287
284
const response = await integration . mcpClient ( ) . callTool ( {
288
285
name : "find" ,
@@ -293,22 +290,23 @@ describeWithMongoDB(
293
290
294
291
const docs = getDocsFromUntrustedContent ( content ) ;
295
292
expect ( docs . length ) . toEqual ( 10 ) ;
296
- vi . resetAllMocks ( ) ;
297
293
} ) ;
298
294
} ) ;
299
295
} ,
300
- ( ) => ( { ...defaultTestConfig , maxDocumentsPerQuery : 20 } )
296
+ ( ) => ( { ...defaultTestConfig , maxDocumentsPerQuery : 10 } )
301
297
) ;
302
298
303
299
describeWithMongoDB (
304
300
"find tool with configured max bytes per query" ,
305
301
( integration ) => {
302
+ beforeEach ( async ( ) => {
303
+ await freshInsertDocuments ( {
304
+ collection : integration . mongoClient ( ) . db ( integration . randomDbName ( ) ) . collection ( "foo" ) ,
305
+ count : 1000 ,
306
+ } ) ;
307
+ } ) ;
306
308
describe ( "when the provided maxBytesPerQuery is hit" , ( ) => {
307
309
it ( "should return only the documents that could fit in maxBytesPerQuery limit" , async ( ) => {
308
- await freshInsertDocuments ( {
309
- collection : integration . mongoClient ( ) . db ( integration . randomDbName ( ) ) . collection ( "foo" ) ,
310
- count : 1000 ,
311
- } ) ;
312
310
await integration . connectMcpClient ( ) ;
313
311
const response = await integration . mcpClient ( ) . callTool ( {
314
312
name : "find" ,
0 commit comments