11import { Client } from "@modelcontextprotocol/sdk/client/index.js" ;
22import { InMemoryTransport } from "./inMemoryTransport.js" ;
33import { 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" ;
95import { config , UserConfig } from "../../src/config.js" ;
106import { McpError } from "@modelcontextprotocol/sdk/types.js" ;
117import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js" ;
128import { Session } from "../../src/session.js" ;
9+ import { toIncludeAllMembers } from "jest-extended" ;
1310
1411interface ParameterInfo {
1512 name : string ;
@@ -98,31 +95,9 @@ export function setupIntegrationTest(userConfig: UserConfig = config): Integrati
9895 return mcpServer ;
9996 } ;
10097
101- const getConnectionString = ( ) => {
102- if ( ! mongoCluster ) {
103- throw new Error ( "beforeAll() hook not ran yet" ) ;
104- }
105-
106- return mongoCluster . connectionString ;
107- } ;
108-
10998 return {
11099 mcpClient : getMcpClient ,
111100 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 ,
126101 } ;
127102}
128103
@@ -199,52 +174,6 @@ export function validateToolMetadata(
199174 } ) ;
200175}
201176
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-
248177export function validateThrowsForInvalidArguments (
249178 integration : IntegrationTest ,
250179 name : string ,
@@ -253,7 +182,6 @@ export function validateThrowsForInvalidArguments(
253182 describe ( "with invalid arguments" , ( ) => {
254183 for ( const arg of args ) {
255184 it ( `throws a schema error for: ${ JSON . stringify ( arg ) } ` , async ( ) => {
256- await integration . connectMcpClient ( ) ;
257185 try {
258186 await integration . mcpClient ( ) . callTool ( { name, arguments : arg } ) ;
259187 expect . fail ( "Expected an error to be thrown" ) ;
0 commit comments