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

mongodb-js / mongodb-mcp-server / 17657973871

11 Sep 2025 09:37PM UTC coverage: 81.59% (+0.4%) from 81.188%
17657973871

Pull #524

github

web-flow
Merge 7617674d0 into d6b84c7bd
Pull Request #524: chore: update smithery dockerfile to be closer to the official one

962 of 1279 branches covered (75.22%)

Branch coverage included in aggregate %.

4866 of 5864 relevant lines covered (82.98%)

46.3 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 type { ToolCallback } from "@modelcontextprotocol/sdk/server/mcp.js";
2
import { ToolBase, type ToolArgs, type ToolCategory, type TelemetryToolMetadata } from "../tool.js";
2✔
3
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
4
import { 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";
732✔
10

11
    protected verifyAllowed(): boolean {
2✔
12
        if (!this.config.apiClientId || !this.config.apiClientSecret) {
732✔
13
            return false;
636✔
14
        }
636✔
15
        return super.verifyAllowed();
96✔
16
    }
732✔
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
            this.session.logger.debug({
×
83
                id: LogId.telemetryMetadataError,
×
84
                context: "tool",
×
85
                message: `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