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

mongodb-js / mongodb-mcp-server / 16056999906

03 Jul 2025 05:34PM UTC coverage: 75.743% (+1.5%) from 74.286%
16056999906

Pull #339

github

web-flow
Merge dd6dadd52 into d7d4aa9ae
Pull Request #339: chore: reinstate telemetry/docker change after revert (MCP-49)

235 of 394 branches covered (59.64%)

Branch coverage included in aggregate %.

17 of 21 new or added lines in 1 file covered. (80.95%)

3 existing lines in 2 files now uncovered.

836 of 1020 relevant lines covered (81.96%)

59.11 hits per line

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

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

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

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

18
    protected handleError(
19
        error: unknown,
20
        args: ToolArgs<typeof this.argsShape>
21
    ): Promise<CallToolResult> | CallToolResult {
UNCOV
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
UNCOV
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(
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
}
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