@@ -2,7 +2,7 @@ import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
2
import type { Session } from "./common/session.js" ;
3
3
import type { Transport } from "@modelcontextprotocol/sdk/shared/transport.js" ;
4
4
import { AtlasTools } from "./tools/atlas/tools.js" ;
5
- import { BuildAtlasLocalTools } from "./tools/atlasLocal/tools.js" ;
5
+ import { AtlasLocalTools } from "./tools/atlasLocal/tools.js" ;
6
6
import { MongoDbTools } from "./tools/mongodb/tools.js" ;
7
7
import { Resources } from "./resources/resources.js" ;
8
8
import type { LogLevel } from "./common/logger.js" ;
@@ -61,8 +61,10 @@ export class Server {
61
61
62
62
this . mcpServer . server . registerCapabilities ( { logging : { } , resources : { listChanged : true , subscribe : true } } ) ;
63
63
64
+ await this . tryInitializeAtlasLocalClient ( ) ;
65
+
64
66
// TODO: Eventually we might want to make tools reactive too instead of relying on custom logic.
65
- await this . registerTools ( ) ;
67
+ this . registerTools ( ) ;
66
68
67
69
// This is a workaround for an issue we've seen with some models, where they'll see that everything in the `arguments`
68
70
// 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 {
193
195
this . telemetry . emitEvents ( [ event ] ) . catch ( ( ) => { } ) ;
194
196
}
195
197
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 ] ) {
199
215
const tool = new toolConstructor ( this . session , this . userConfig , this . telemetry ) ;
200
216
if ( tool . register ( this ) ) {
201
217
this . tools . push ( tool ) ;
0 commit comments