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

mongodb-js / mongodb-mcp-server / 14592314930

22 Apr 2025 10:13AM UTC coverage: 56.835% (+5.2%) from 51.628%
14592314930

Pull #87

github

blva
reformat
Pull Request #87: draft: telemetry

44 of 171 branches covered (25.73%)

Branch coverage included in aggregate %.

70 of 82 new or added lines in 6 files covered. (85.37%)

1 existing line in 1 file now uncovered.

484 of 758 relevant lines covered (63.85%)

78.11 hits per line

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

46.43
/src/session.ts
1
import { NodeDriverServiceProvider } from "@mongosh/service-provider-node-driver";
2
import { ApiClient } from "./common/atlas/apiClient.js";
8✔
3
import config from "./config.js";
8✔
4
import { Implementation } from "@modelcontextprotocol/sdk/types.js";
5

6
export class Session {
8✔
7
    sessionId?: string;
8
    serviceProvider?: NodeDriverServiceProvider;
9
    apiClient: ApiClient;
10
    agentClientName?: string;
11
    agentClientVersion?: string;
12

13
    constructor() {
14
        // Initialize API client with credentials if available
15
        if (config.apiClientId && config.apiClientSecret) {
80!
NEW
16
            this.apiClient = new ApiClient({
×
17
                baseUrl: config.apiBaseUrl,
18
                credentials: {
19
                    clientId: config.apiClientId,
20
                    clientSecret: config.apiClientSecret,
21
                },
22
            });
NEW
23
            return;
×
24
        }
25

26
        // Initialize API client without credentials
27
        this.apiClient = new ApiClient({ baseUrl: config.apiBaseUrl });
80✔
28
    }
29

30
    setAgentClientData(agentClient: Implementation | undefined) {
31
        this.agentClientName = agentClient?.name;
80✔
32
        this.agentClientVersion = agentClient?.version;
80✔
33
    }
34

35
    ensureAuthenticated(): asserts this is { apiClient: ApiClient } {
NEW
36
        if (!this.apiClient || !this.apiClient.hasCredentials()) {
×
37
            if (!config.apiClientId || !config.apiClientSecret) {
×
38
                throw new Error(
×
39
                    "Not authenticated make sure to configure MCP server with MDB_MCP_API_CLIENT_ID and MDB_MCP_API_CLIENT_SECRET environment variables."
40
                );
41
            }
42

43
            // Initialize or reinitialize API client with credentials
UNCOV
44
            this.apiClient = new ApiClient({
×
45
                baseUrl: config.apiBaseUrl,
46
                credentials: {
47
                    clientId: config.apiClientId,
48
                    clientSecret: config.apiClientSecret,
49
                },
50
            });
51
        }
52
    }
53

54
    async close(): Promise<void> {
55
        if (this.serviceProvider) {
80✔
56
            try {
59✔
57
                await this.serviceProvider.close(true);
59✔
58
            } catch (error) {
59
                console.error("Error closing service provider:", error);
×
60
            }
61
            this.serviceProvider = undefined;
59✔
62
        }
63
    }
64
}
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

© 2026 Coveralls, Inc