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

mongodb-js / mongodb-mcp-server / 16779406063

06 Aug 2025 02:11PM UTC coverage: 81.424% (-0.4%) from 81.781%
16779406063

Pull #420

github

web-flow
Merge cc01ac54e into a35d18dd6
Pull Request #420: chore: allow logging unredacted messages MCP-103

679 of 874 branches covered (77.69%)

Branch coverage included in aggregate %.

161 of 291 new or added lines in 16 files covered. (55.33%)

7 existing lines in 4 files now uncovered.

3485 of 4240 relevant lines covered (82.19%)

63.42 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";
816✔
10

11
    protected verifyAllowed(): boolean {
2✔
12
        if (!this.config.apiClientId || !this.config.apiClientSecret) {
816✔
13
            return false;
360✔
14
        }
360✔
15
        return super.verifyAllowed();
456✔
16
    }
816✔
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) {
×
NEW
82
            logger.debug({
×
NEW
83
                id: LogId.telemetryMetadataError,
×
NEW
84
                context: "tool",
×
NEW
85
                message: `Error parsing tool arguments: ${parsedResult.error.message}`,
×
NEW
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