@@ -5,15 +5,23 @@ import { AtlasTools } from "./tools/atlas/tools.js";
5
5
import { MongoDbTools } from "./tools/mongodb/tools.js" ;
6
6
import logger , { initializeLogger } from "./logger.js" ;
7
7
import { 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
+ }
9
15
10
16
export class Server {
11
17
public readonly session : Session ;
12
18
private readonly mcpServer : McpServer ;
19
+ private readonly userConfig : UserConfig ;
13
20
14
- constructor ( { mcpServer, session } : { mcpServer : McpServer ; session : Session } ) {
15
- this . mcpServer = mcpServer ;
21
+ constructor ( { session, mcpServer, userConfig } : ServerOptions ) {
16
22
this . session = session ;
23
+ this . mcpServer = mcpServer ;
24
+ this . userConfig = userConfig ;
17
25
}
18
26
19
27
async connect ( transport : Transport ) {
@@ -22,7 +30,7 @@ export class Server {
22
30
this . registerTools ( ) ;
23
31
this . registerResources ( ) ;
24
32
25
- await initializeLogger ( this . mcpServer ) ;
33
+ await initializeLogger ( this . mcpServer , this . userConfig . logPath ) ;
26
34
27
35
await this . mcpServer . connect ( transport ) ;
28
36
@@ -36,12 +44,12 @@ export class Server {
36
44
37
45
private registerTools ( ) {
38
46
for ( const tool of [ ...AtlasTools , ...MongoDbTools ] ) {
39
- new tool ( this . session ) . register ( this . mcpServer ) ;
47
+ new tool ( this . session , this . userConfig ) . register ( this . mcpServer ) ;
40
48
}
41
49
}
42
50
43
51
private registerResources ( ) {
44
- if ( config . connectionString ) {
52
+ if ( this . userConfig . connectionString ) {
45
53
this . mcpServer . resource (
46
54
"connection-string" ,
47
55
"config://connection-string" ,
@@ -52,7 +60,7 @@ export class Server {
52
60
return {
53
61
contents : [
54
62
{
55
- text : `Preconfigured connection string: ${ config . connectionString } ` ,
63
+ text : `Preconfigured connection string: ${ this . userConfig . connectionString } ` ,
56
64
uri : uri . href ,
57
65
} ,
58
66
] ,
0 commit comments