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

mongodb-js / mongodb-mcp-server / 19146805236

06 Nov 2025 07:05PM UTC coverage: 80.192% (+0.04%) from 80.151%
19146805236

Pull #716

github

web-flow
Merge 3b9e5951c into 454e81617
Pull Request #716: chore: cleanup telemetry

1357 of 1802 branches covered (75.31%)

Branch coverage included in aggregate %.

2 of 6 new or added lines in 4 files covered. (33.33%)

31 existing lines in 4 files now uncovered.

6477 of 7967 relevant lines covered (81.3%)

69.52 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 { ToolCallback } from "@modelcontextprotocol/sdk/server/mcp.js";
2
import type { AtlasMetadata } from "../../telemetry/types.js";
3
import { ToolBase, type ToolArgs, type ToolCategory } from "../tool.js";
3✔
4
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
5
import { LogId } from "../../common/logger.js";
3✔
6
import { z } from "zod";
3✔
7
import { ApiClientError } from "../../common/atlas/apiClientError.js";
3✔
8

9
export abstract class AtlasToolBase extends ToolBase {
3✔
10
    public category: ToolCategory = "atlas";
1,105✔
11

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

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

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

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

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

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

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

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

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

78
    /**
79
     *
80
     * Resolves the tool metadata from the arguments passed to the tool
81
     *
82
     * @param args - The arguments passed to the tool
83
     * @returns The tool metadata
84
     */
85
    protected resolveTelemetryMetadata(...args: Parameters<ToolCallback<typeof this.argsShape>>): AtlasMetadata {
3✔
NEW
86
        const toolMetadata: AtlasMetadata = {};
×
87
        if (!args.length) {
×
88
            return toolMetadata;
×
89
        }
×
90

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

95
        if (!parsedResult.success) {
×
96
            this.session.logger.debug({
×
UNCOV
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() !== "") {
×
UNCOV
108
            toolMetadata.project_id = data.projectId;
×
UNCOV
109
        }
×
110

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