@@ -2,7 +2,7 @@ import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
22import type { Session } from "./common/session.js" ;
33import type { Transport } from "@modelcontextprotocol/sdk/shared/transport.js" ;
44import { AtlasTools } from "./tools/atlas/tools.js" ;
5- import { BuildAtlasLocalTools } from "./tools/atlasLocal/tools.js" ;
5+ import { AtlasLocalTools } from "./tools/atlasLocal/tools.js" ;
66import { MongoDbTools } from "./tools/mongodb/tools.js" ;
77import { Resources } from "./resources/resources.js" ;
88import type { LogLevel } from "./common/logger.js" ;
@@ -61,8 +61,10 @@ export class Server {
6161
6262 this . mcpServer . server . registerCapabilities ( { logging : { } , resources : { listChanged : true , subscribe : true } } ) ;
6363
64+ await this . tryInitializeAtlasLocalClient ( ) ;
65+
6466 // TODO: Eventually we might want to make tools reactive too instead of relying on custom logic.
65- await this . registerTools ( ) ;
67+ this . registerTools ( ) ;
6668
6769 // This is a workaround for an issue we've seen with some models, where they'll see that everything in the `arguments`
6870 // object is optional, and then not pass it at all. However, the MCP server expects the `arguments` object to be if
@@ -193,9 +195,23 @@ export class Server {
193195 this . telemetry . emitEvents ( [ event ] ) . catch ( ( ) => { } ) ;
194196 }
195197
196- private async registerTools ( ) : Promise < void > {
197- const atlasLocalTools = await BuildAtlasLocalTools ( ) ;
198- for ( const toolConstructor of [ ...AtlasTools , ...atlasLocalTools , ...MongoDbTools ] ) {
198+ private async tryInitializeAtlasLocalClient ( ) : Promise < void > {
199+ try {
200+ const { Client : AtlasLocalClient } = await import ( "@mongodb-js-preview/atlas-local" ) ;
201+
202+ const client = AtlasLocalClient . connect ( ) ;
203+ this . session . setAtlasLocalClient ( client ) ;
204+ } catch ( error ) {
205+ console . warn (
206+ "Failed to initialize Atlas Local client, atlas-local tools will be disabled (error: " ,
207+ error ,
208+ ")"
209+ ) ;
210+ }
211+ }
212+
213+ private registerTools ( ) : void {
214+ for ( const toolConstructor of [ ...AtlasTools , ...AtlasLocalTools , ...MongoDbTools ] ) {
199215 const tool = new toolConstructor ( this . session , this . userConfig , this . telemetry ) ;
200216 if ( tool . register ( this ) ) {
201217 this . tools . push ( tool ) ;
0 commit comments