@@ -5,27 +5,35 @@ 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" ;
98import { ObjectId } from "mongodb" ;
109import { Telemetry } from "./telemetry/telemetry.js" ;
10+ import { UserConfig } from "./config.js" ;
11+
12+ export interface ServerOptions {
13+ session : Session ;
14+ userConfig : UserConfig ;
15+ mcpServer : McpServer ;
16+ }
1117
1218export class Server {
1319 public readonly session : Session ;
1420 private readonly mcpServer : McpServer ;
1521 private readonly telemetry : Telemetry ;
22+ private readonly userConfig : UserConfig ;
1623
17- constructor ( { mcpServer, session } : { mcpServer : McpServer ; session : Session } ) {
18- this . mcpServer = mcpServer ;
24+ constructor ( { session, mcpServer, userConfig } : ServerOptions ) {
1925 this . session = session ;
2026 this . telemetry = new Telemetry ( session ) ;
27+ this . mcpServer = mcpServer ;
28+ this . userConfig = userConfig ;
2129 }
2230
2331 async connect ( transport : Transport ) {
2432 this . mcpServer . server . registerCapabilities ( { logging : { } } ) ;
2533 this . registerTools ( ) ;
2634 this . registerResources ( ) ;
2735
28- await initializeLogger ( this . mcpServer ) ;
36+ await initializeLogger ( this . mcpServer , this . userConfig . logPath ) ;
2937
3038 await this . mcpServer . connect ( transport ) ;
3139
@@ -48,12 +56,12 @@ export class Server {
4856
4957 private registerTools ( ) {
5058 for ( const tool of [ ...AtlasTools , ...MongoDbTools ] ) {
51- new tool ( this . session , this . telemetry ) . register ( this . mcpServer ) ;
59+ new tool ( this . session , this . userConfig , this . telemetry ) . register ( this . mcpServer ) ;
5260 }
5361 }
5462
5563 private registerResources ( ) {
56- if ( config . connectionString ) {
64+ if ( this . userConfig . connectionString ) {
5765 this . mcpServer . resource (
5866 "connection-string" ,
5967 "config://connection-string" ,
@@ -64,7 +72,7 @@ export class Server {
6472 return {
6573 contents : [
6674 {
67- text : `Preconfigured connection string: ${ config . connectionString } ` ,
75+ text : `Preconfigured connection string: ${ this . userConfig . connectionString } ` ,
6876 uri : uri . href ,
6977 } ,
7078 ] ,
0 commit comments