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

mongodb-js / mongodb-mcp-server / 16347477296

17 Jul 2025 02:10PM UTC coverage: 77.304% (-0.09%) from 77.39%
16347477296

Pull #378

github

web-flow
Merge 2f2bcf319 into fd3f2a4fd
Pull Request #378: chore: specify the correct minimum node requirements

496 of 685 branches covered (72.41%)

Branch coverage included in aggregate %.

2825 of 3611 relevant lines covered (78.23%)

28.48 hits per line

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

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

8
export abstract class AtlasToolBase extends ToolBase {
2✔
9
    public category: ToolCategory = "atlas";
408✔
10

11
    protected verifyAllowed(): boolean {
2✔
12
        if (!this.config.apiClientId || !this.config.apiClientSecret) {
408✔
13
            return false;
312✔
14
        }
312✔
15
        return super.verifyAllowed();
96✔
16
    }
408✔
17

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

25
            if (statusCode === 401) {
×
26
                return {
×
27
                    content: [
×
28
                        {
×
29
                            type: "text",
×
30
                            text: `Unable to authenticate with MongoDB Atlas, API error: ${error.message}
×
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
                        },
×
36
                    ],
×
37
                    isError: true,
×
38
                };
×
39
            }
×
40

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

48
You don't have sufficient permissions to perform this action in MongoDB Atlas
49
Please ensure your API key has the necessary roles assigned.
50
For more information on Atlas API access roles, visit: https://www.mongodb.com/docs/atlas/api/service-accounts-overview/`,
51
                        },
×
52
                    ],
×
53
                    isError: true,
×
54
                };
×
55
            }
×
56
        }
×
57

58
        // For other types of errors, use the default error handling from the base class
59
        return super.handleError(error, args);
×
60
    }
×
61

62
    /**
63
     *
64
     * Resolves the tool metadata from the arguments passed to the tool
65
     *
66
     * @param args - The arguments passed to the tool
67
     * @returns The tool metadata
68
     */
69
    protected resolveTelemetryMetadata(
2✔
70
        ...args: Parameters<ToolCallback<typeof this.argsShape>>
×
71
    ): TelemetryToolMetadata {
×
72
        const toolMetadata: TelemetryToolMetadata = {};
×
73
        if (!args.length) {
×
74
            return toolMetadata;
×
75
        }
×
76

77
        // Create a typed parser for the exact shape we expect
78
        const argsShape = z.object(this.argsShape);
×
79
        const parsedResult = argsShape.safeParse(args[0]);
×
80

81
        if (!parsedResult.success) {
×
82
            logger.debug(
×
83
                LogId.telemetryMetadataError,
×
84
                "tool",
×
85
                `Error parsing tool arguments: ${parsedResult.error.message}`
×
86
            );
×
87
            return toolMetadata;
×
88
        }
×
89

90
        const data = parsedResult.data;
×
91

92
        // Extract projectId using type guard
93
        if ("projectId" in data && typeof data.projectId === "string" && data.projectId.trim() !== "") {
×
94
            toolMetadata.projectId = data.projectId;
×
95
        }
×
96

97
        // Extract orgId using type guard
98
        if ("orgId" in data && typeof data.orgId === "string" && data.orgId.trim() !== "") {
×
99
            toolMetadata.orgId = data.orgId;
×
100
        }
×
101
        return toolMetadata;
×
102
    }
×
103
}
2✔
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