@@ -4,10 +4,15 @@ import {
44 validateThrowsForInvalidArguments ,
55 getResponseContent ,
66} from "../../../helpers.js" ;
7- import { expect , it } from "vitest" ;
7+ import { expect , it , afterEach } from "vitest" ;
88import { describeWithMongoDB , getDocsFromUntrustedContent , validateAutoConnectBehavior } from "../mongodbHelpers.js" ;
99
1010describeWithMongoDB ( "aggregate tool" , ( integration ) => {
11+ afterEach ( ( ) => {
12+ integration . mcpServer ( ) . userConfig . readOnly = false ;
13+ integration . mcpServer ( ) . userConfig . disabledTools = [ ] ;
14+ } ) ;
15+
1116 validateToolMetadata ( integration , "aggregate" , "Run an aggregation against a MongoDB collection" , [
1217 ...databaseCollectionParameters ,
1318 {
@@ -129,6 +134,42 @@ describeWithMongoDB("aggregate tool", (integration) => {
129134 ) ;
130135 } ) ;
131136
137+ for ( const disabledOpType of [ "create" , "update" , "delete" ] as const ) {
138+ it ( `can not run $out stages when ${ disabledOpType } operation is disabled` , async ( ) => {
139+ await integration . connectMcpClient ( ) ;
140+ integration . mcpServer ( ) . userConfig . disabledTools = [ disabledOpType ] ;
141+ const response = await integration . mcpClient ( ) . callTool ( {
142+ name : "aggregate" ,
143+ arguments : {
144+ database : integration . randomDbName ( ) ,
145+ collection : "people" ,
146+ pipeline : [ { $out : "outpeople" } ] ,
147+ } ,
148+ } ) ;
149+ const content = getResponseContent ( response ) ;
150+ expect ( content ) . toEqual (
151+ "Error running aggregate: When 'create', 'update', or 'delete' operations are disabled, you can not run pipelines with $out or $merge stages."
152+ ) ;
153+ } ) ;
154+
155+ it ( `can not run $merge stages when ${ disabledOpType } operation is disabled` , async ( ) => {
156+ await integration . connectMcpClient ( ) ;
157+ integration . mcpServer ( ) . userConfig . disabledTools = [ disabledOpType ] ;
158+ const response = await integration . mcpClient ( ) . callTool ( {
159+ name : "aggregate" ,
160+ arguments : {
161+ database : integration . randomDbName ( ) ,
162+ collection : "people" ,
163+ pipeline : [ { $merge : "outpeople" } ] ,
164+ } ,
165+ } ) ;
166+ const content = getResponseContent ( response ) ;
167+ expect ( content ) . toEqual (
168+ "Error running aggregate: When 'create', 'update', or 'delete' operations are disabled, you can not run pipelines with $out or $merge stages."
169+ ) ;
170+ } ) ;
171+ }
172+
132173 validateAutoConnectBehavior ( integration , "aggregate" , ( ) => {
133174 return {
134175 args : {
0 commit comments