• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mongodb-js / mongodb-mcp-server / 19925638108

04 Dec 2025 10:23AM UTC coverage: 80.575% (-0.03%) from 80.607%
19925638108

Pull #779

github

web-flow
Merge 1e90969c7 into e12068a03
Pull Request #779: chore: bump mcp SDK, refactor tool arguments

1469 of 1905 branches covered (77.11%)

Branch coverage included in aggregate %.

49 of 66 new or added lines in 12 files covered. (74.24%)

2 existing lines in 2 files now uncovered.

6736 of 8278 relevant lines covered (81.37%)

78.78 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

51.82
/src/tools/atlasLocal/atlasLocalTool.ts
1
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
2
import type { ToolArgs, ToolCategory, ToolExecutionContext } from "../tool.js";
3
import { ToolBase } from "../tool.js";
3✔
4
import type { Client } from "@mongodb-js/atlas-local";
5
import { LogId } from "../../common/logger.js";
3✔
6
import type { ConnectionMetadata } from "../../telemetry/types.js";
7

8
export const AtlasLocalToolMetadataDeploymentIdKey = "deploymentId";
3✔
9

10
export abstract class AtlasLocalToolBase extends ToolBase {
3✔
11
    static category: ToolCategory = "atlas-local";
3✔
12

13
    protected verifyAllowed(): boolean {
3✔
14
        return this.session.atlasLocalClient !== undefined && super.verifyAllowed();
400✔
15
    }
400✔
16

17
    protected async execute(
3✔
18
        args: ToolArgs<typeof this.argsShape>,
26✔
19
        // eslint-disable-next-line @typescript-eslint/no-unused-vars
20
        _context: ToolExecutionContext
26✔
21
    ): Promise<CallToolResult> {
26✔
22
        const client = this.session.atlasLocalClient;
26✔
23

24
        // If the client is not found, throw an error
25
        // This should never happen:
26
        // - atlas-local tools are only added after the client is set
27
        //   this means that if we were unable to get the client, the tool will not be registered
28
        // - in case the tool was registered by accident
29
        //   verifyAllowed would still return false preventing the tool from being registered,
30
        //   preventing the tool from being executed
31
        if (!client) {
26!
32
            return {
×
33
                content: [
×
34
                    {
×
35
                        type: "text",
×
36
                        text: `Something went wrong on our end, this tool should have been disabled but it was not.
×
37
please log a ticket here: https://github.com/mongodb-js/mongodb-mcp-server/issues/new?template=bug_report.yml`,
38
                    },
×
39
                ],
×
40
                isError: true,
×
41
            };
×
42
        }
×
43

44
        return this.executeWithAtlasLocalClient(args, { client });
26✔
45
    }
26✔
46

47
    private async lookupDeploymentId(client: Client, containerId: string): Promise<string | undefined> {
3✔
48
        try {
×
49
            // Lookup and return the deployment id for telemetry metadata.
50
            return await client.getDeploymentId(containerId);
×
51
        } catch (error) {
×
52
            this.session.logger.debug({
×
53
                id: LogId.telemetryMetadataError,
×
54
                context: "tool",
×
55
                message: `Error looking up deployment ID: ${String(error)}`,
×
56
            });
×
57

58
            return undefined;
×
59
        }
×
60
    }
×
61

62
    protected async lookupTelemetryMetadata(client: Client, containerId: string): Promise<{ [key: string]: unknown }> {
3✔
63
        if (!this.telemetry.isTelemetryEnabled()) {
17✔
64
            return {};
17✔
65
        }
17!
66

67
        const deploymentId = await this.lookupDeploymentId(client, containerId);
×
68
        if (deploymentId === undefined) {
×
69
            return {};
×
70
        }
×
71

72
        return {
×
73
            [AtlasLocalToolMetadataDeploymentIdKey]: deploymentId,
×
74
        };
×
75
    }
17✔
76

77
    protected abstract executeWithAtlasLocalClient(
78
        args: ToolArgs<typeof this.argsShape>,
79
        context: { client: Client }
80
    ): Promise<CallToolResult>;
81

82
    protected handleError(
3✔
83
        error: unknown,
3✔
84
        args: ToolArgs<typeof this.argsShape>
3✔
85
    ): Promise<CallToolResult> | CallToolResult {
3✔
86
        // Error Handling for expected Atlas Local errors go here
87
        const errorMessage = error instanceof Error ? error.message : String(error);
3!
88

89
        // Check if Docker daemon is not running
90
        if (
3✔
91
            errorMessage.includes("Cannot connect to the Docker daemon") ||
3✔
92
            errorMessage.includes("Is the docker daemon running") ||
3✔
93
            errorMessage.includes("connect ENOENT") ||
3✔
94
            errorMessage.includes("ECONNREFUSED")
3✔
95
        ) {
3!
96
            return {
×
97
                content: [
×
98
                    {
×
99
                        type: "text",
×
100
                        text: "Docker is not running. Please start Docker and try again. Atlas Local tools require Docker to be running.",
×
101
                    },
×
102
                ],
×
103
                isError: true,
×
104
            };
×
105
        }
×
106

107
        if (errorMessage.includes("No such container")) {
3✔
108
            const deploymentName =
2✔
109
                "deploymentName" in args ? (args.deploymentName as string) : "the specified deployment";
2!
110
            return {
2✔
111
                content: [
2✔
112
                    {
2✔
113
                        type: "text",
2✔
114
                        text: `The Atlas Local deployment "${deploymentName}" was not found. Please check the deployment name or use "atlas-local-list-deployments" to see available deployments.`,
2✔
115
                    },
2✔
116
                ],
2✔
117
                isError: true,
2✔
118
            };
2✔
119
        }
2✔
120

121
        // For other types of errors, use the default error handling from the base class
122
        return super.handleError(error, args);
1✔
123
    }
3✔
124

125
    protected resolveTelemetryMetadata(
3✔
NEW
126
        _args: ToolArgs<typeof this.argsShape>,
×
NEW
127
        { result }: { result: CallToolResult }
×
NEW
128
    ): ConnectionMetadata {
×
UNCOV
129
        const toolMetadata: ConnectionMetadata = {};
×
130

131
        // Atlas Local tools set the deployment ID in the result metadata for telemetry
132
        // If the deployment ID is set, we use it for telemetry
133
        const resultDeploymentId = result._meta?.[AtlasLocalToolMetadataDeploymentIdKey];
×
134
        if (resultDeploymentId !== undefined && typeof resultDeploymentId === "string") {
×
135
            toolMetadata.atlas_local_deployment_id = resultDeploymentId;
×
136
        }
×
137

138
        return toolMetadata;
×
139
    }
×
140
}
3✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc