@@ -5,6 +5,7 @@ import { DbOperationType, MongoDBToolBase } from "./mongodbTool.js";
55import { ToolArgs } from "../tool.js" ;
66import { ErrorCodes , MongoDBError } from "../../errors.js" ;
77import config from "../../config.js" ;
8+ import { connectToMongoDB } from "../../common/mongodb/connect.js" ;
89
910export class ConnectTool extends MongoDBToolBase {
1011 protected name = "connect" ;
@@ -58,27 +59,10 @@ export class ConnectTool extends MongoDBToolBase {
5859 throw new MongoDBError ( ErrorCodes . InvalidParams , "Invalid connection options" ) ;
5960 }
6061
61- await this . connect ( connectionString ) ;
62+ await connectToMongoDB ( connectionString , this . state ) ;
6263
6364 return {
6465 content : [ { type : "text" , text : `Successfully connected to ${ connectionString } .` } ] ,
6566 } ;
6667 }
67-
68- private async connect ( connectionString : string ) : Promise < void > {
69- const provider = await NodeDriverServiceProvider . connect ( connectionString , {
70- productDocsLink : "https://docs.mongodb.com/todo-mcp" ,
71- productName : "MongoDB MCP" ,
72- readConcern : config . connectOptions . readConcern ,
73- readPreference : config . connectOptions . readPreference ,
74- writeConcern : {
75- w : config . connectOptions . writeConcern ,
76- } ,
77- timeoutMS : config . connectOptions . timeoutMS ,
78- } ) ;
79-
80- this . state . serviceProvider = provider ;
81- this . state . credentials . connectionString = connectionString ;
82- await this . state . persistCredentials ( ) ;
83- }
8468}
0 commit comments