Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 47c0a09

Browse files
authored
fix: start mcp even if connection fails - [MCP-140] (#503)
1 parent d471cdd commit 47c0a09

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

‎src/common/logger.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export const LogId = {
4141

4242
mongodbConnectFailure: mongoLogId(1_004_001),
4343
mongodbDisconnectFailure: mongoLogId(1_004_002),
44+
mongodbConnectTry: mongoLogId(1_004_003),
4445

4546
toolUpdateFailure: mongoLogId(1_005_001),
4647
resourceUpdateFailure: mongoLogId(1_005_002),

‎src/server.ts‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
import assert from "assert";
2121
import type { ToolBase } from "./tools/tool.js";
2222
import { validateConnectionString } from "./helpers/connectionOptions.js";
23+
import { packageInfo } from "./common/packageInfo.js";
2324

2425
export interface ServerOptions {
2526
session: Session;
@@ -119,11 +120,10 @@ export class Server {
119120
this.session.setMcpClient(this.mcpServer.server.getClientVersion());
120121
// Placed here to start the connection to the config connection string as soon as the server is initialized.
121122
void this.connectToConfigConnectionString();
122-
123123
this.session.logger.info({
124124
id: LogId.serverInitialized,
125125
context: "server",
126-
message: `Server started with transport ${transport.constructor.name} and agent runner ${this.session.mcpClient?.name}`,
126+
message: `Server with version ${packageInfo.version}started with transport ${transport.constructor.name} and agent runner ${JSON.stringify(this.session.mcpClient)}`,
127127
});
128128

129129
this.emitServerEvent("start", Date.now() - this.startTime);
@@ -244,15 +244,21 @@ export class Server {
244244
private async connectToConfigConnectionString(): Promise<void> {
245245
if (this.userConfig.connectionString) {
246246
try {
247+
this.session.logger.info({
248+
id: LogId.mongodbConnectTry,
249+
context: "server",
250+
message: `Detected a MongoDB connection string in the configuration, trying to connect...`,
251+
});
247252
await this.session.connectToMongoDB({
248253
connectionString: this.userConfig.connectionString,
249254
});
250255
} catch (error) {
251-
console.error(
252-
"Failed to connect to MongoDB instance using the connection string from the config: ",
253-
error
254-
);
255-
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 instanceof Error ? error.message : String(error)}`,
261+
});
256262
}
257263
}
258264
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /