11import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js" ;
22import { ApiClient } from "./common/atlas/apiClient.js" ;
3- import { State , saveState , loadState } from "./state.js" ;
3+ import defaultState , { State } from "./state.js" ;
44import { Transport } from "@modelcontextprotocol/sdk/shared/transport.js" ;
55import { registerAtlasTools } from "./tools/atlas/tools.js" ;
66import { registerMongoDBTools } from "./tools/mongodb/index.js" ;
@@ -9,26 +9,27 @@ import logger, { initializeLogger } from "./logger.js";
99import { mongoLogId } from "mongodb-log-writer" ;
1010
1111export class Server {
12- state : State | undefined = undefined ;
12+ state : State = defaultState ;
1313 apiClient : ApiClient | undefined = undefined ;
1414 initialized : boolean = false ;
1515
1616 private async init ( ) {
1717 if ( this . initialized ) {
1818 return ;
1919 }
20- this . state = await loadState ( ) ;
20+
21+ await this . state . loadCredentials ( ) ;
2122
2223 this . apiClient = new ApiClient ( {
23- token : this . state . persistent . auth . token ,
24+ token : this . state . credentials . auth . token ,
2425 saveToken : async ( token ) => {
2526 if ( ! this . state ) {
2627 throw new Error ( "State is not initialized" ) ;
2728 }
28- this . state . persistent . auth . code = undefined ;
29- this . state . persistent . auth . token = token ;
30- this . state . persistent . auth . status = "issued" ;
31- await saveState ( this . state ) ;
29+ this . state . credentials . auth . code = undefined ;
30+ this . state . credentials . auth . token = token ;
31+ this . state . credentials . auth . status = "issued" ;
32+ await this . state . persistCredentials ( ) ;
3233 } ,
3334 } ) ;
3435
@@ -43,8 +44,8 @@ export class Server {
4344
4445 server . server . registerCapabilities ( { logging : { } } ) ;
4546
46- registerAtlasTools ( server , this . state ! , this . apiClient ! ) ;
47- registerMongoDBTools ( server , this . state ! ) ;
47+ registerAtlasTools ( server , this . state , this . apiClient ! ) ;
48+ registerMongoDBTools ( server , this . state ) ;
4849
4950 return server ;
5051 }
0 commit comments