@@ -5,15 +5,23 @@ import { AtlasTools } from "./tools/atlas/tools.js";
55import { MongoDbTools } from "./tools/mongodb/tools.js" ;
66import logger , { initializeLogger } from "./logger.js" ;
77import { mongoLogId } from "mongodb-log-writer" ;
8- import config from "./config.js" ;
8+ import { UserConfig } from "./config.js" ;
9+
10+ export interface ServerOptions {
11+ session : Session ;
12+ userConfig : UserConfig ;
13+ mcpServer : McpServer ;
14+ }
915
1016export class Server {
1117 public readonly session : Session ;
1218 private readonly mcpServer : McpServer ;
19+ private readonly userConfig : UserConfig ;
1320
14- constructor ( { mcpServer, session } : { mcpServer : McpServer ; session : Session } ) {
15- this . mcpServer = mcpServer ;
21+ constructor ( { session, mcpServer, userConfig } : ServerOptions ) {
1622 this . session = session ;
23+ this . mcpServer = mcpServer ;
24+ this . userConfig = userConfig ;
1725 }
1826
1927 async connect ( transport : Transport ) {
@@ -22,7 +30,7 @@ export class Server {
2230 this . registerTools ( ) ;
2331 this . registerResources ( ) ;
2432
25- await initializeLogger ( this . mcpServer ) ;
33+ await initializeLogger ( this . mcpServer , this . userConfig . logPath ) ;
2634
2735 await this . mcpServer . connect ( transport ) ;
2836
@@ -36,12 +44,12 @@ export class Server {
3644
3745 private registerTools ( ) {
3846 for ( const tool of [ ...AtlasTools , ...MongoDbTools ] ) {
39- new tool ( this . session ) . register ( this . mcpServer ) ;
47+ new tool ( this . session , this . userConfig ) . register ( this . mcpServer ) ;
4048 }
4149 }
4250
4351 private registerResources ( ) {
44- if ( config . connectionString ) {
52+ if ( this . userConfig . connectionString ) {
4553 this . mcpServer . resource (
4654 "connection-string" ,
4755 "config://connection-string" ,
@@ -52,7 +60,7 @@ export class Server {
5260 return {
5361 contents : [
5462 {
55- text : `Preconfigured connection string: ${ config . connectionString } ` ,
63+ text : `Preconfigured connection string: ${ this . userConfig . connectionString } ` ,
5664 uri : uri . href ,
5765 } ,
5866 ] ,
0 commit comments