diff --git a/src/common/logger.ts b/src/common/logger.ts index 2535b4025..03b94f313 100644 --- a/src/common/logger.ts +++ b/src/common/logger.ts @@ -41,6 +41,7 @@ export const LogId = { mongodbConnectFailure: mongoLogId(1_004_001), mongodbDisconnectFailure: mongoLogId(1_004_002), + mongodbConnectTry: mongoLogId(1_004_003), toolUpdateFailure: mongoLogId(1_005_001), resourceUpdateFailure: mongoLogId(1_005_002), diff --git a/src/server.ts b/src/server.ts index ded916180..76399e986 100644 --- a/src/server.ts +++ b/src/server.ts @@ -20,6 +20,7 @@ import { import assert from "assert"; import type { ToolBase } from "./tools/tool.js"; import { validateConnectionString } from "./helpers/connectionOptions.js"; +import { packageInfo } from "./common/packageInfo.js"; export interface ServerOptions { session: Session; @@ -119,11 +120,10 @@ export class Server { this.session.setMcpClient(this.mcpServer.server.getClientVersion()); // Placed here to start the connection to the config connection string as soon as the server is initialized. void this.connectToConfigConnectionString(); - this.session.logger.info({ id: LogId.serverInitialized, context: "server", - message: `Server started with transport ${transport.constructor.name} and agent runner ${this.session.mcpClient?.name}`, + message: `Server with version ${packageInfo.version} started with transport ${transport.constructor.name} and agent runner ${JSON.stringify(this.session.mcpClient)}`, }); this.emitServerEvent("start", Date.now() - this.startTime); @@ -244,15 +244,21 @@ export class Server { private async connectToConfigConnectionString(): Promise { if (this.userConfig.connectionString) { try { + this.session.logger.info({ + id: LogId.mongodbConnectTry, + context: "server", + message: `Detected a MongoDB connection string in the configuration, trying to connect...`, + }); await this.session.connectToMongoDB({ connectionString: this.userConfig.connectionString, }); } catch (error) { - console.error( - "Failed to connect to MongoDB instance using the connection string from the config: ", - error - ); - throw new Error("Failed to connect to MongoDB instance using the connection string from the config"); + // We don't throw an error here because we want to allow the server to start even if the connection string is invalid. + this.session.logger.error({ + id: LogId.mongodbConnectFailure, + context: "server", + message: `Failed to connect to MongoDB instance using the connection string from the config: ${error instanceof Error ? error.message : String(error)}`, + }); } } }