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

mongodb-js / mongodb-mcp-server / 16292877152

15 Jul 2025 12:10PM UTC coverage: 77.385% (+2.1%) from 75.27%
16292877152

push

github

web-flow
chore(tests): switch to vitest (#363)

498 of 687 branches covered (72.49%)

Branch coverage included in aggregate %.

0 of 27 new or added lines in 2 files covered. (0.0%)

293 existing lines in 26 files now uncovered.

2828 of 3611 relevant lines covered (78.32%)

28.46 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✔
UNCOV
19
        error: unknown,
×
UNCOV
20
        args: ToolArgs<typeof this.argsShape>
×
UNCOV
21
    ): Promise<CallToolResult> | CallToolResult {
×
22
        if (error instanceof ApiClientError) {
×
23
            const statusCode = error.response.status;
×
24

25
            if (statusCode === 401) {
×
26
                return {
×
UNCOV
27
                    content: [
×
UNCOV
28
                        {
×
UNCOV
29
                            type: "text",
×
UNCOV
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/`,
UNCOV
35
                        },
×
UNCOV
36
                    ],
×
UNCOV
37
                    isError: true,
×
UNCOV
38
                };
×
UNCOV
39
            }
×
40

41
            if (statusCode === 403) {
×
42
                return {
×
UNCOV
43
                    content: [
×
UNCOV
44
                        {
×
UNCOV
45
                            type: "text",
×
UNCOV
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/`,
UNCOV
51
                        },
×
UNCOV
52
                    ],
×
UNCOV
53
                    isError: true,
×
UNCOV
54
                };
×
UNCOV
55
            }
×
UNCOV
56
        }
×
57

58
        // For other types of errors, use the default error handling from the base class
59
        return super.handleError(error, args);
×
UNCOV
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✔
UNCOV
70
        ...args: Parameters<ToolCallback<typeof this.argsShape>>
×
UNCOV
71
    ): TelemetryToolMetadata {
×
72
        const toolMetadata: TelemetryToolMetadata = {};
×
73
        if (!args.length) {
×
74
            return toolMetadata;
×
UNCOV
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(
×
UNCOV
83
                LogId.telemetryMetadataError,
×
UNCOV
84
                "tool",
×
UNCOV
85
                `Error parsing tool arguments: ${parsedResult.error.message}`
×
UNCOV
86
            );
×
87
            return toolMetadata;
×
UNCOV
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;
×
UNCOV
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;
×
UNCOV
100
        }
×
101
        return toolMetadata;
×
UNCOV
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