Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/common/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
20 changes: 13 additions & 7 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)}`,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding more logs to make it easier to debug

});

this.emitServerEvent("start", Date.now() - this.startTime);
Expand Down Expand Up @@ -244,15 +244,21 @@ export class Server {
private async connectToConfigConnectionString(): Promise<void> {
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)}`,
});
}
}
}
Expand Down
Loading