@@ -6,21 +6,22 @@ import { MongoDbTools } from "./tools/mongodb/tools.js";
66import logger , { initializeLogger } from "./logger.js" ;
77import { mongoLogId } from "mongodb-log-writer" ;
88import { UserConfig } from "./config.js" ;
9- import version from "./version.js" ;
9+
10+ export interface ServerOptions {
11+ session : Session ;
12+ userConfig : UserConfig ;
13+ mcpServer : McpServer ;
14+ }
1015
1116export class Server {
1217 public readonly session : Session ;
13- private readonly mcpServer : McpServer = new McpServer ( {
14- name : "MongoDB Atlas" ,
15- version,
16- } ) ;
18+ private readonly mcpServer : McpServer ;
19+ private readonly userConfig : UserConfig ;
1720
18- constructor ( private readonly config : UserConfig ) {
19- this . session = new Session ( {
20- apiBaseUrl : config . apiBaseUrl ,
21- apiClientId : config . apiClientId ,
22- apiClientSecret : config . apiClientSecret ,
23- } ) ;
21+ constructor ( { session, mcpServer, userConfig } : ServerOptions ) {
22+ this . session = session ;
23+ this . mcpServer = mcpServer ;
24+ this . userConfig = userConfig ;
2425 }
2526
2627 async connect ( transport : Transport ) {
@@ -29,7 +30,7 @@ export class Server {
2930 this . registerTools ( ) ;
3031 this . registerResources ( ) ;
3132
32- await initializeLogger ( this . mcpServer , this . config . logPath ) ;
33+ await initializeLogger ( this . mcpServer , this . userConfig . logPath ) ;
3334
3435 await this . mcpServer . connect ( transport ) ;
3536
@@ -43,12 +44,12 @@ export class Server {
4344
4445 private registerTools ( ) {
4546 for ( const tool of [ ...AtlasTools , ...MongoDbTools ] ) {
46- new tool ( this . session , this . config ) . register ( this . mcpServer ) ;
47+ new tool ( this . session , this . userConfig ) . register ( this . mcpServer ) ;
4748 }
4849 }
4950
5051 private registerResources ( ) {
51- if ( this . config . connectionString ) {
52+ if ( this . userConfig . connectionString ) {
5253 this . mcpServer . resource (
5354 "connection-string" ,
5455 "config://connection-string" ,
@@ -59,7 +60,7 @@ export class Server {
5960 return {
6061 contents : [
6162 {
62- text : `Preconfigured connection string: ${ this . config . connectionString } ` ,
63+ text : `Preconfigured connection string: ${ this . userConfig . connectionString } ` ,
6364 uri : uri . href ,
6465 } ,
6566 ] ,
0 commit comments