@@ -5,15 +5,22 @@ 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+ import version from "./version.js" ;
910
1011export class Server {
1112 public readonly session : Session ;
12- private readonly mcpServer : McpServer ;
13+ private readonly mcpServer : McpServer = new McpServer ( {
14+ name : "MongoDB Atlas" ,
15+ version,
16+ } ) ;
1317
14- constructor ( { mcpServer, session } : { mcpServer : McpServer ; session : Session } ) {
15- this . mcpServer = mcpServer ;
16- this . session = session ;
18+ constructor ( private readonly config : UserConfig ) {
19+ this . session = new Session ( {
20+ apiBaseUrl : config . apiBaseUrl ,
21+ apiClientId : config . apiClientId ,
22+ apiClientSecret : config . apiClientSecret ,
23+ } ) ;
1724 }
1825
1926 async connect ( transport : Transport ) {
@@ -22,7 +29,7 @@ export class Server {
2229 this . registerTools ( ) ;
2330 this . registerResources ( ) ;
2431
25- await initializeLogger ( this . mcpServer ) ;
32+ await initializeLogger ( this . mcpServer , this . config . logPath ) ;
2633
2734 await this . mcpServer . connect ( transport ) ;
2835
@@ -36,12 +43,12 @@ export class Server {
3643
3744 private registerTools ( ) {
3845 for ( const tool of [ ...AtlasTools , ...MongoDbTools ] ) {
39- new tool ( this . session ) . register ( this . mcpServer ) ;
46+ new tool ( this . session , this . config ) . register ( this . mcpServer ) ;
4047 }
4148 }
4249
4350 private registerResources ( ) {
44- if ( config . connectionString ) {
51+ if ( this . config . connectionString ) {
4552 this . mcpServer . resource (
4653 "connection-string" ,
4754 "config://connection-string" ,
@@ -52,7 +59,7 @@ export class Server {
5259 return {
5360 contents : [
5461 {
55- text : `Preconfigured connection string: ${ config . connectionString } ` ,
62+ text : `Preconfigured connection string: ${ this . config . connectionString } ` ,
5663 uri : uri . href ,
5764 } ,
5865 ] ,
0 commit comments