• 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

44.83
/src/tools/atlas/atlasTool.ts
1
import type { AtlasMetadata } from "../../telemetry/types.js";
2
import { ToolBase, type ToolArgs, type ToolCategory } from "../tool.js";
3✔
3
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
4
import { LogId } from "../../common/logger.js";
3✔
5
import { z } from "zod";
3✔
6
import { ApiClientError } from "../../common/atlas/apiClientError.js";
3✔
7

8
export abstract class AtlasToolBase extends ToolBase {
3✔
9
    static category: ToolCategory = "atlas";
3✔
10

11
    protected verifyAllowed(): boolean {
3✔
12
        if (!this.config.apiClientId || !this.config.apiClientSecret) {
1,300✔
13
            return false;
1,131✔
14
        }
1,131!
15
        return super.verifyAllowed();
169✔
16
    }
1,300✔
17

18
    protected handleError(
3✔
19
        error: unknown,
3✔
20
        args: ToolArgs<typeof this.argsShape>
3✔
21
    ): Promise<CallToolResult> | CallToolResult {
3✔
22
        if (error instanceof ApiClientError) {
3✔
23
            const statusCode = error.response.status;
3✔
24

25
            if (statusCode === 401) {
3✔
26
                return {
3✔
27
                    content: [
3✔
28
                        {
3✔
29
                            type: "text",
3✔
30
                            text: `Unable to authenticate with MongoDB Atlas, API error: ${error.message}
3✔
31

32
Hint: Your API credentials may be invalid, expired or lack permissions.
33
Please check your Atlas API credentials and ensure they have the appropriate permissions.
34
For more information on setting up API keys, visit: https://www.mongodb.com/docs/atlas/configure-api-access/`,
35
                        },
3✔
36
                    ],
3✔
37
                    isError: true,
3✔
38
                };
3✔
39
            }
3!
40

41
            if (statusCode === 402) {
×
42
                return {
×
43
                    content: [
×
44
                        {
×
45
                            type: "text",
×
46
                            text: `Received a Payment Required API Error: ${error.message}
×
47

48
Payment setup is required to perform this action in MongoDB Atlas.
49
Please ensure that your payment method for your organization has been set up and is active.
50
For more information on setting up payment, visit: https://www.mongodb.com/docs/atlas/billing/`,
51
                        },
×
52
                    ],
×
53
                };
×
54
            }
×
55

56
            if (statusCode === 403) {
×
57
                return {
×
58
                    content: [
×
59
                        {
×
60
                            type: "text",
×
61
                            text: `Received a Forbidden API Error: ${error.message}
×
62

63
You don't have sufficient permissions to perform this action in MongoDB Atlas.
64
Please ensure your API key has the necessary roles assigned.
65
For more information on Atlas API access roles, visit: https://www.mongodb.com/docs/atlas/api/service-accounts-overview/`,
66
                        },
×
67
                    ],
×
68
                    isError: true,
×
69
                };
×
70
            }
×
71
        }
3!
72

73
        // For other types of errors, use the default error handling from the base class
74
        return super.handleError(error, args);
×
75
    }
3✔
76

77
    /**
78
     *
79
     * Resolves the tool metadata from the arguments passed to the tool
80
     *
81
     * @param args - The arguments passed to the tool
82
     * @returns The tool metadata
83
     */
84
    protected resolveTelemetryMetadata(
3✔
NEW
85
        args: ToolArgs<typeof this.argsShape>,
×
86
        // eslint-disable-next-line @typescript-eslint/no-unused-vars
NEW
87
        { result }: { result: CallToolResult }
×
88
    ): AtlasMetadata {
×
89
        const toolMetadata: AtlasMetadata = {};
×
90

91
        // Create a typed parser for the exact shape we expect
92
        const argsShape = z.object(this.argsShape);
×
NEW
93
        const parsedResult = argsShape.safeParse(args);
×
94

95
        if (!parsedResult.success) {
×
96
            this.session.logger.debug({
×
97
                id: LogId.telemetryMetadataError,
×
98
                context: "tool",
×
99
                message: `Error parsing tool arguments: ${parsedResult.error.message}`,
×
100
            });
×
101
            return toolMetadata;
×
102
        }
×
103

104
        const data = parsedResult.data;
×
105

106
        // Extract projectId using type guard
107
        if ("projectId" in data && typeof data.projectId === "string" && data.projectId.trim() !== "") {
×
108
            toolMetadata.project_id = data.projectId;
×
109
        }
×
110

111
        // Extract orgId using type guard
112
        if ("orgId" in data && typeof data.orgId === "string" && data.orgId.trim() !== "") {
×
113
            toolMetadata.org_id = data.orgId;
×
114
        }
×
115
        return toolMetadata;
×
116
    }
×
117
}
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