Skip to content

Commit 74d2218

Browse files
refactor: Update atlas local error handling
1 parent 9eb0c1a commit 74d2218

File tree

2 files changed

+47
-20
lines changed

2 files changed

+47
-20
lines changed

src/server.ts

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -231,29 +231,37 @@ export class Server {
231231
// This will fail on unsupported platforms
232232
const { Client: AtlasLocalClient } = await import("@mongodb-js-preview/atlas-local");
233233

234-
// Connect to Atlas Local client
235-
// This will fail if docker is not running
236-
const client = AtlasLocalClient.connect();
237-
238-
// Set Atlas Local client
239-
this.session.atlasLocalClient = client;
240-
241-
// Register Atlas Local tools
242-
for (const toolConstructor of AtlasLocalTools) {
243-
const tool = new toolConstructor({
244-
session: this.session,
245-
config: this.userConfig,
246-
telemetry: this.telemetry,
247-
elicitation: this.elicitation,
248-
});
249-
if (tool.register(this)) {
250-
this.tools.push(tool);
234+
try {
235+
// Connect to Atlas Local client
236+
// This will fail if docker is not running
237+
const client = AtlasLocalClient.connect();
238+
239+
// Set Atlas Local client
240+
this.session.atlasLocalClient = client;
241+
242+
// Register Atlas Local tools
243+
for (const toolConstructor of AtlasLocalTools) {
244+
const tool = new toolConstructor({
245+
session: this.session,
246+
config: this.userConfig,
247+
telemetry: this.telemetry,
248+
elicitation: this.elicitation,
249+
});
250+
if (tool.register(this)) {
251+
this.tools.push(tool);
252+
}
251253
}
254+
} catch (dockerError) {
255+
console.warn(
256+
"Failed to connect to Atlas Local client (Docker not available or not running), atlas-local tools will be disabled (error: ",
257+
dockerError,
258+
")"
259+
);
252260
}
253-
} catch (error) {
261+
} catch (importError) {
254262
console.warn(
255-
"Failed to initialize Atlas Local client, atlas-local tools will be disabled (error: ",
256-
error,
263+
"Failed to import Atlas Local client (platform not supported), atlas-local tools will be disabled (error: ",
264+
importError,
257265
")"
258266
);
259267
}

src/tools/atlasLocal/atlasLocalTool.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,25 @@ please log a ticket here: https://github.com/mongodb-js/mongodb-mcp-server/issue
5656
): Promise<CallToolResult> | CallToolResult {
5757
// Error Handling for expected Atlas Local errors go here
5858
const errorMessage = error instanceof Error ? error.message : String(error);
59+
60+
// Check if Docker daemon is not running
61+
if (
62+
errorMessage.includes("Cannot connect to the Docker daemon") ||
63+
errorMessage.includes("Is the docker daemon running") ||
64+
errorMessage.includes("connect ENOENT") ||
65+
errorMessage.includes("ECONNREFUSED")
66+
) {
67+
return {
68+
content: [
69+
{
70+
type: "text",
71+
text: "Docker is not running. Please start Docker and try again. Atlas Local tools require Docker to be running.",
72+
},
73+
],
74+
isError: true,
75+
};
76+
}
77+
5978
if (errorMessage.includes("No such container")) {
6079
const deploymentName =
6180
"deploymentName" in args ? (args.deploymentName as string) : "the specified deployment";

0 commit comments

Comments
 (0)