Skip to content

Commit 4e0eef5

Browse files
committed
fix: start mcp even if connection fails
1 parent 0f3deff commit 4e0eef5

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/server.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ export class Server {
120120
this.session.setMcpClient(this.mcpServer.server.getClientVersion());
121121
// Placed here to start the connection to the config connection string as soon as the server is initialized.
122122
void this.connectToConfigConnectionString();
123-
124123
this.session.logger.info({
125124
id: LogId.serverInitialized,
126125
context: "server",
@@ -245,15 +244,21 @@ export class Server {
245244
private async connectToConfigConnectionString(): Promise<void> {
246245
if (this.userConfig.connectionString) {
247246
try {
247+
this.session.logger.info({
248+
id: LogId.serverInitialized,
249+
context: "server",
250+
message: `Detected a MongoDB connection string in the configuration, trying to connect...`,
251+
});
248252
await this.session.connectToMongoDB({
249253
connectionString: this.userConfig.connectionString,
250254
});
251255
} catch (error) {
252-
console.error(
253-
"Failed to connect to MongoDB instance using the connection string from the config: ",
254-
error
255-
);
256-
throw new Error("Failed to connect to MongoDB instance using the connection string from the config");
256+
// We don't throw an error here because we want to allow the server to start even if the connection string is invalid.
257+
this.session.logger.error({
258+
id: LogId.mongodbConnectFailure,
259+
context: "server",
260+
message: `Failed to connect to MongoDB instance using the connection string from the config: ${error as string}`,
261+
});
257262
}
258263
}
259264
}

0 commit comments

Comments
 (0)