@@ -4,10 +4,15 @@ import {
4
4
validateThrowsForInvalidArguments ,
5
5
getResponseContent ,
6
6
} from "../../../helpers.js" ;
7
- import { expect , it } from "vitest" ;
7
+ import { expect , it , afterEach } from "vitest" ;
8
8
import { describeWithMongoDB , getDocsFromUntrustedContent , validateAutoConnectBehavior } from "../mongodbHelpers.js" ;
9
9
10
10
describeWithMongoDB ( "aggregate tool" , ( integration ) => {
11
+ afterEach ( ( ) => {
12
+ integration . mcpServer ( ) . userConfig . readOnly = false ;
13
+ integration . mcpServer ( ) . userConfig . disabledTools = [ ] ;
14
+ } ) ;
15
+
11
16
validateToolMetadata ( integration , "aggregate" , "Run an aggregation against a MongoDB collection" , [
12
17
...databaseCollectionParameters ,
13
18
{
@@ -129,6 +134,42 @@ describeWithMongoDB("aggregate tool", (integration) => {
129
134
) ;
130
135
} ) ;
131
136
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
+
132
173
validateAutoConnectBehavior ( integration , "aggregate" , ( ) => {
133
174
return {
134
175
args : {
0 commit comments