@@ -4,7 +4,7 @@ import ConnectionString from "mongodb-connection-string-url";
44import { NodeDriverServiceProvider } from "@mongosh/service-provider-node-driver" ;
55import { type ConnectionInfo , generateConnectionInfoFromCliArgs } from "@mongosh/arg-parser" ;
66import type { DeviceId } from "../helpers/deviceId.js" ;
7- import type { DriverOptions , UserConfig } from "./config.js" ;
7+ import { defaultDriverOptions , setupDriverConfig , type DriverOptions , type UserConfig } from "./config.js" ;
88import { MongoDBError , ErrorCodes } from "./errors.js" ;
99import { type LoggerBase , LogId } from "./logger.js" ;
1010import { packageInfo } from "./packageInfo.js" ;
@@ -360,3 +360,23 @@ export class MCPConnectionManager extends ConnectionManager {
360360 }
361361 }
362362}
363+
364+ /**
365+ * Consumers of MCP server library have option to bring their own connection
366+ * management if they need to. To support that, we enable injecting connection
367+ * manager implementation through a factory function.
368+ */
369+ export type ConnectionManagerFactoryFn = ( createParams : {
370+ logger : LoggerBase ;
371+ deviceId : DeviceId ;
372+ userConfig : UserConfig ;
373+ } ) => Promise < ConnectionManager > ;
374+
375+ export const createMCPConnectionManager : ConnectionManagerFactoryFn = ( { logger, deviceId, userConfig } ) => {
376+ const driverOptions = setupDriverConfig ( {
377+ config : userConfig ,
378+ defaults : defaultDriverOptions ,
379+ } ) ;
380+
381+ return Promise . resolve ( new MCPConnectionManager ( userConfig , driverOptions , logger , deviceId ) ) ;
382+ } ;
0 commit comments