@@ -95,21 +95,26 @@ describe("Config Overrides via HTTP", () => {
9595 expect ( readTools . length ) . toBe ( 1 ) ;
9696 } ) ;
9797
98- it ( "should override connectionString with header" , async ( ) => {
98+ it ( "should not be able tooverride connectionString with header" , async ( ) => {
9999 await startRunner ( {
100100 ...defaultTestConfig ,
101101 httpPort : 0 ,
102102 connectionString : undefined ,
103103 allowRequestOverrides : true ,
104104 } ) ;
105105
106- await connectClient ( {
107- [ "x-mongodb-mcp-connection-string" ] : "mongodb://override:27017" ,
108- } ) ;
109-
110- const response = await client . listTools ( ) ;
111-
112- expect ( response ) . toBeDefined ( ) ;
106+ try {
107+ await connectClient ( {
108+ [ "x-mongodb-mcp-connection-string" ] : "mongodb://override:27017" ,
109+ } ) ;
110+ expect . fail ( "Expected an error to be thrown" ) ;
111+ } catch ( error ) {
112+ if ( ! ( error instanceof Error ) ) {
113+ throw new Error ( "Expected an error to be thrown" ) ;
114+ }
115+ expect ( error . message ) . toContain ( "Error POSTing to endpoint (HTTP 400)" ) ;
116+ expect ( error . message ) . toContain ( `Config key connectionString is not allowed to be overridden` ) ;
117+ }
113118 } ) ;
114119 } ) ;
115120
@@ -415,4 +420,131 @@ describe("Config Overrides via HTTP", () => {
415420 expect ( findTool ) . toBeDefined ( ) ;
416421 } ) ;
417422 } ) ;
423+
424+ describe ( "onlyLowerThanBaseValueOverride behavior" , ( ) => {
425+ it ( "should allow override to a lower value" , async ( ) => {
426+ await startRunner ( {
427+ ...defaultTestConfig ,
428+ httpPort : 0 ,
429+ idleTimeoutMs : 600_000 ,
430+ allowRequestOverrides : true ,
431+ } ) ;
432+
433+ await connectClient ( {
434+ [ "x-mongodb-mcp-idle-timeout-ms" ] : "300000" ,
435+ } ) ;
436+
437+ const response = await client . listTools ( ) ;
438+ expect ( response ) . toBeDefined ( ) ;
439+ } ) ;
440+
441+ it ( "should reject override to a higher value" , async ( ) => {
442+ await startRunner ( {
443+ ...defaultTestConfig ,
444+ httpPort : 0 ,
445+ idleTimeoutMs : 600_000 ,
446+ allowRequestOverrides : true ,
447+ } ) ;
448+
449+ try {
450+ await connectClient ( {
451+ [ "x-mongodb-mcp-idle-timeout-ms" ] : "900000" ,
452+ } ) ;
453+ expect . fail ( "Expected an error to be thrown" ) ;
454+ } catch ( error ) {
455+ if ( ! ( error instanceof Error ) ) {
456+ throw new Error ( "Expected an error to be thrown" ) ;
457+ }
458+ expect ( error . message ) . toContain ( "Error POSTing to endpoint (HTTP 400)" ) ;
459+ expect ( error . message ) . toContain (
460+ "Cannot apply override for idleTimeoutMs: Can only set to a value lower than the base value"
461+ ) ;
462+ }
463+ } ) ;
464+
465+ it ( "should reject override to equal value" , async ( ) => {
466+ await startRunner ( {
467+ ...defaultTestConfig ,
468+ httpPort : 0 ,
469+ idleTimeoutMs : 600_000 ,
470+ allowRequestOverrides : true ,
471+ } ) ;
472+
473+ try {
474+ await connectClient ( {
475+ [ "x-mongodb-mcp-idle-timeout-ms" ] : "600000" ,
476+ } ) ;
477+ expect . fail ( "Expected an error to be thrown" ) ;
478+ } catch ( error ) {
479+ if ( ! ( error instanceof Error ) ) {
480+ throw new Error ( "Expected an error to be thrown" ) ;
481+ }
482+ expect ( error . message ) . toContain ( "Error POSTing to endpoint (HTTP 400)" ) ;
483+ expect ( error . message ) . toContain (
484+ "Cannot apply override for idleTimeoutMs: Can only set to a value lower than the base value"
485+ ) ;
486+ }
487+ } ) ;
488+ } ) ;
489+
490+ describe ( "onlySubsetOfBaseValueOverride behavior" , ( ) => {
491+ describe ( "previewFeatures" , ( ) => {
492+ it ( "should allow override to same value" , async ( ) => {
493+ await startRunner ( {
494+ ...defaultTestConfig ,
495+ httpPort : 0 ,
496+ previewFeatures : [ "vectorSearch" ] ,
497+ allowRequestOverrides : true ,
498+ } ) ;
499+
500+ await connectClient ( {
501+ [ "x-mongodb-mcp-preview-features" ] : "vectorSearch" ,
502+ } ) ;
503+
504+ const response = await client . listTools ( ) ;
505+ expect ( response ) . toBeDefined ( ) ;
506+ } ) ;
507+
508+ it ( "should allow override to an empty array (subset of any array)" , async ( ) => {
509+ await startRunner ( {
510+ ...defaultTestConfig ,
511+ httpPort : 0 ,
512+ previewFeatures : [ "vectorSearch" ] ,
513+ allowRequestOverrides : true ,
514+ } ) ;
515+
516+ await connectClient ( {
517+ [ "x-mongodb-mcp-preview-features" ] : "" ,
518+ } ) ;
519+
520+ const response = await client . listTools ( ) ;
521+ expect ( response ) . toBeDefined ( ) ;
522+ } ) ;
523+
524+ it ( "should reject override when base is empty array and trying to add items" , async ( ) => {
525+ await startRunner ( {
526+ ...defaultTestConfig ,
527+ httpPort : 0 ,
528+ previewFeatures : [ ] ,
529+ allowRequestOverrides : true ,
530+ } ) ;
531+
532+ // Empty array trying to override with non-empty should fail (superset)
533+ try {
534+ await connectClient ( {
535+ [ "x-mongodb-mcp-preview-features" ] : "vectorSearch" ,
536+ } ) ;
537+ expect . fail ( "Expected an error to be thrown" ) ;
538+ } catch ( error ) {
539+ if ( ! ( error instanceof Error ) ) {
540+ throw new Error ( "Expected an error to be thrown" ) ;
541+ }
542+ expect ( error . message ) . toContain ( "Error POSTing to endpoint (HTTP 400)" ) ;
543+ expect ( error . message ) . toContain (
544+ "Cannot apply override for previewFeatures: Can only override to a subset of the base value"
545+ ) ;
546+ }
547+ } ) ;
548+ } ) ;
549+ } ) ;
418550} ) ;
0 commit comments