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

mongodb-js / mongodb-mcp-server / 17487477238

05 Sep 2025 08:06AM UTC coverage: 81.348% (+0.2%) from 81.158%
17487477238

Pull #517

github

web-flow
Merge d5c4b205b into 1f68c3e5d
Pull Request #517: feat(cli): notify when a flag is wrong and suggest a fix MCP-121

937 of 1241 branches covered (75.5%)

Branch coverage included in aggregate %.

59 of 59 new or added lines in 1 file covered. (100.0%)

13 existing lines in 2 files now uncovered.

4724 of 5718 relevant lines covered (82.62%)

44.43 hits per line

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

96.77
/src/transports/base.ts
1
import type { UserConfig } from "../common/config.js";
1✔
2
import { packageInfo } from "../common/packageInfo.js";
1✔
3
import { Server } from "../server.js";
1✔
4
import { Session } from "../common/session.js";
1✔
5
import { Telemetry } from "../telemetry/telemetry.js";
1✔
6
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
1✔
7
import type { LoggerBase } from "../common/logger.js";
8
import { CompositeLogger, ConsoleLogger, DiskLogger, McpLogger } from "../common/logger.js";
1✔
9
import { ExportsManager } from "../common/exportsManager.js";
1✔
10
import { DeviceId } from "../helpers/deviceId.js";
1✔
11
import { Keychain } from "../common/keychain.js";
1✔
12
import { createMCPConnectionManager, type ConnectionManagerFactoryFn } from "../common/connectionManager.js";
1✔
13
import {
1✔
14
    type ConnectionErrorHandler,
15
    connectionErrorHandler as defaultConnectionErrorHandler,
16
} from "../common/connectionErrorHandler.js";
17
import type { CommonProperties } from "../telemetry/types.js";
18

19
export type TransportRunnerConfig = {
20
    userConfig: UserConfig;
21
    createConnectionManager?: ConnectionManagerFactoryFn;
22
    connectionErrorHandler?: ConnectionErrorHandler;
23
    additionalLoggers?: LoggerBase[];
24
    telemetryProperties?: Partial<CommonProperties>;
25
};
26

27
export abstract class TransportRunnerBase {
1✔
28
    public logger: LoggerBase;
29
    public deviceId: DeviceId;
30
    protected readonly userConfig: UserConfig;
31
    private readonly createConnectionManager: ConnectionManagerFactoryFn;
32
    private readonly connectionErrorHandler: ConnectionErrorHandler;
33
    private readonly telemetryProperties: Partial<CommonProperties>;
34

35
    protected constructor({
1✔
36
        userConfig,
7✔
37
        createConnectionManager = createMCPConnectionManager,
7✔
38
        connectionErrorHandler = defaultConnectionErrorHandler,
7✔
39
        additionalLoggers = [],
7✔
40
        telemetryProperties = {},
7✔
41
    }: TransportRunnerConfig) {
7✔
42
        this.userConfig = userConfig;
7✔
43
        this.createConnectionManager = createConnectionManager;
7✔
44
        this.connectionErrorHandler = connectionErrorHandler;
7✔
45
        this.telemetryProperties = telemetryProperties;
7✔
46
        const loggers: LoggerBase[] = [...additionalLoggers];
7✔
47
        if (this.userConfig.loggers.includes("stderr")) {
7✔
48
            loggers.push(new ConsoleLogger(Keychain.root));
1✔
49
        }
1✔
50

51
        if (this.userConfig.loggers.includes("disk")) {
7✔
52
            loggers.push(
4✔
53
                new DiskLogger(
4✔
54
                    this.userConfig.logPath,
4✔
55
                    (err) => {
4✔
56
                        // If the disk logger fails to initialize, we log the error to stderr and exit
UNCOV
57
                        console.error("Error initializing disk logger:", err);
×
UNCOV
58
                        process.exit(1);
×
UNCOV
59
                    },
×
60
                    Keychain.root
4✔
61
                )
4✔
62
            );
4✔
63
        }
4✔
64

65
        this.logger = new CompositeLogger(...loggers);
7✔
66
        this.deviceId = DeviceId.create(this.logger);
7✔
67
    }
7✔
68

69
    protected async setupServer(): Promise<Server> {
1✔
70
        const mcpServer = new McpServer({
7✔
71
            name: packageInfo.mcpServerName,
7✔
72
            version: packageInfo.version,
7✔
73
        });
7✔
74

75
        const logger = new CompositeLogger(this.logger);
7✔
76
        const exportsManager = ExportsManager.init(this.userConfig, logger);
7✔
77
        const connectionManager = await this.createConnectionManager({
7✔
78
            logger,
7✔
79
            userConfig: this.userConfig,
7✔
80
            deviceId: this.deviceId,
7✔
81
        });
7✔
82

83
        const session = new Session({
7✔
84
            apiBaseUrl: this.userConfig.apiBaseUrl,
7✔
85
            apiClientId: this.userConfig.apiClientId,
7✔
86
            apiClientSecret: this.userConfig.apiClientSecret,
7✔
87
            logger,
7✔
88
            exportsManager,
7✔
89
            connectionManager,
7✔
90
            keychain: Keychain.root,
7✔
91
        });
7✔
92

93
        const telemetry = Telemetry.create(session, this.userConfig, this.deviceId, {
7✔
94
            commonProperties: this.telemetryProperties,
7✔
95
        });
7✔
96

97
        const result = new Server({
7✔
98
            mcpServer,
7✔
99
            session,
7✔
100
            telemetry,
7✔
101
            userConfig: this.userConfig,
7✔
102
            connectionErrorHandler: this.connectionErrorHandler,
7✔
103
        });
7✔
104

105
        // We need to create the MCP logger after the server is constructed
106
        // because it needs the server instance
107
        if (this.userConfig.loggers.includes("mcp")) {
7✔
108
            logger.addLogger(new McpLogger(result, Keychain.root));
2✔
109
        }
2✔
110

111
        return result;
7✔
112
    }
7✔
113

114
    abstract start(): Promise<void>;
115

116
    abstract closeTransport(): Promise<void>;
117

118
    async close(): Promise<void> {
1✔
119
        try {
6✔
120
            await this.closeTransport();
6✔
121
        } finally {
6✔
122
            this.deviceId.close();
6✔
123
        }
6✔
124
    }
6✔
125
}
1✔
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