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

mongodb-js / mongodb-mcp-server / 14621895739

23 Apr 2025 03:20PM UTC coverage: 78.292% (-0.1%) from 78.42%
14621895739

Pull #101

github

fmenezes
Merge branch 'main' into fmenezes/refactor_config
Pull Request #101: refactor: move configuration to be passed

90 of 161 branches covered (55.9%)

Branch coverage included in aggregate %.

17 of 18 new or added lines in 8 files covered. (94.44%)

11 existing lines in 2 files now uncovered.

570 of 682 relevant lines covered (83.58%)

30.28 hits per line

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

88.0
/src/server.ts
1
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
18✔
2
import { Session } from "./session.js";
18✔
3
import { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
4
import { AtlasTools } from "./tools/atlas/tools.js";
18✔
5
import { MongoDbTools } from "./tools/mongodb/tools.js";
18✔
6
import logger, { initializeLogger } from "./logger.js";
18✔
7
import { mongoLogId } from "mongodb-log-writer";
18✔
8
import { UserConfig } from "./config.js";
9
import version from "./version.js";
18✔
10

11
export class Server {
18✔
12
    public readonly session: Session;
13
    private readonly mcpServer: McpServer = new McpServer({
18✔
14
        name: "MongoDB Atlas",
15
        version,
16
    });
17

18
    constructor(private readonly config: UserConfig) {
18✔
19
        this.session = new Session({
18✔
20
            apiBaseUrl: config.apiBaseUrl,
21
            apiClientId: config.apiClientId,
22
            apiClientSecret: config.apiClientSecret,
23
        });
24
    }
25

26
    async connect(transport: Transport) {
27
        this.mcpServer.server.registerCapabilities({ logging: {} });
18✔
28

29
        this.registerTools();
18✔
30
        this.registerResources();
18✔
31

32
        await initializeLogger(this.mcpServer, this.config.logPath);
18✔
33

34
        await this.mcpServer.connect(transport);
18✔
35

36
        logger.info(mongoLogId(1_000_004), "server", `Server started with transport ${transport.constructor.name}`);
18✔
37
    }
38

39
    async close(): Promise<void> {
40
        await this.session.close();
18✔
41
        await this.mcpServer.close();
18✔
42
    }
43

44
    private registerTools() {
45
        for (const tool of [...AtlasTools, ...MongoDbTools]) {
18✔
46
            new tool(this.session, this.config).register(this.mcpServer);
522✔
47
        }
48
    }
49

50
    private registerResources() {
51
        if (this.config.connectionString) {
18!
NEW
52
            this.mcpServer.resource(
×
53
                "connection-string",
54
                "config://connection-string",
55
                {
56
                    description: "Preconfigured connection string that will be used as a default in the `connect` tool",
57
                },
58
                (uri) => {
UNCOV
59
                    return {
×
60
                        contents: [
61
                            {
62
                                text: `Preconfigured connection string: ${this.config.connectionString}`,
63
                                uri: uri.href,
64
                            },
65
                        ],
66
                    };
67
                }
68
            );
69
        }
70
    }
71
}
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