1
1
import { Client } from "@modelcontextprotocol/sdk/client/index.js" ;
2
2
import { InMemoryTransport } from "./inMemoryTransport.js" ;
3
3
import { Server } from "../../src/server.js" ;
4
- import runner , { MongoCluster } from "mongodb-runner" ;
5
- import path from "path" ;
6
- import fs from "fs/promises" ;
7
- import { MongoClient , ObjectId } from "mongodb" ;
8
- import { toIncludeAllMembers } from "jest-extended" ;
4
+ import { ObjectId } from "mongodb" ;
9
5
import { config , UserConfig } from "../../src/config.js" ;
10
6
import { McpError } from "@modelcontextprotocol/sdk/types.js" ;
11
7
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js" ;
12
8
import { Session } from "../../src/session.js" ;
9
+ import { toIncludeAllMembers } from "jest-extended" ;
13
10
14
11
interface ParameterInfo {
15
12
name : string ;
@@ -98,31 +95,9 @@ export function setupIntegrationTest(userConfig: UserConfig = config): Integrati
98
95
return mcpServer ;
99
96
} ;
100
97
101
- const getConnectionString = ( ) => {
102
- if ( ! mongoCluster ) {
103
- throw new Error ( "beforeAll() hook not ran yet" ) ;
104
- }
105
-
106
- return mongoCluster . connectionString ;
107
- } ;
108
-
109
98
return {
110
99
mcpClient : getMcpClient ,
111
100
mcpServer : getMcpServer ,
112
- mongoClient : ( ) => {
113
- if ( ! mongoClient ) {
114
- mongoClient = new MongoClient ( getConnectionString ( ) ) ;
115
- }
116
- return mongoClient ;
117
- } ,
118
- connectionString : getConnectionString ,
119
- connectMcpClient : async ( ) => {
120
- await getMcpClient ( ) . callTool ( {
121
- name : "connect" ,
122
- arguments : { options : [ { connectionString : getConnectionString ( ) } ] } ,
123
- } ) ;
124
- } ,
125
- randomDbName : ( ) => randomDbName ,
126
101
} ;
127
102
}
128
103
@@ -199,52 +174,6 @@ export function validateToolMetadata(
199
174
} ) ;
200
175
}
201
176
202
- export function validateAutoConnectBehavior (
203
- integration : IntegrationTest ,
204
- name : string ,
205
- validation : ( ) => {
206
- args : { [ x : string ] : unknown } ;
207
- expectedResponse ?: string ;
208
- validate ?: ( content : unknown ) => void ;
209
- } ,
210
- beforeEachImpl ?: ( ) => Promise < void >
211
- ) : void {
212
- describe ( "when not connected" , ( ) => {
213
- if ( beforeEachImpl ) {
214
- beforeEach ( ( ) => beforeEachImpl ( ) ) ;
215
- }
216
-
217
- it ( "connects automatically if connection string is configured" , async ( ) => {
218
- config . connectionString = integration . connectionString ( ) ;
219
-
220
- const validationInfo = validation ( ) ;
221
-
222
- const response = await integration . mcpClient ( ) . callTool ( {
223
- name,
224
- arguments : validationInfo . args ,
225
- } ) ;
226
-
227
- if ( validationInfo . expectedResponse ) {
228
- const content = getResponseContent ( response . content ) ;
229
- expect ( content ) . toContain ( validationInfo . expectedResponse ) ;
230
- }
231
-
232
- if ( validationInfo . validate ) {
233
- validationInfo . validate ( response . content ) ;
234
- }
235
- } ) ;
236
-
237
- it ( "throws an error if connection string is not configured" , async ( ) => {
238
- const response = await integration . mcpClient ( ) . callTool ( {
239
- name,
240
- arguments : validation ( ) . args ,
241
- } ) ;
242
- const content = getResponseContent ( response . content ) ;
243
- expect ( content ) . toContain ( "You need to connect to a MongoDB instance before you can access its data." ) ;
244
- } ) ;
245
- } ) ;
246
- }
247
-
248
177
export function validateThrowsForInvalidArguments (
249
178
integration : IntegrationTest ,
250
179
name : string ,
@@ -253,7 +182,6 @@ export function validateThrowsForInvalidArguments(
253
182
describe ( "with invalid arguments" , ( ) => {
254
183
for ( const arg of args ) {
255
184
it ( `throws a schema error for: ${ JSON . stringify ( arg ) } ` , async ( ) => {
256
- await integration . connectMcpClient ( ) ;
257
185
try {
258
186
await integration . mcpClient ( ) . callTool ( { name, arguments : arg } ) ;
259
187
expect . fail ( "Expected an error to be thrown" ) ;
0 commit comments