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

mongodb-js / mongodb-mcp-server / 14594832497

22 Apr 2025 12:31PM UTC coverage: 53.54% (+0.3%) from 53.208%
14594832497

Pull #88

github

nirinchev
fix tests
Pull Request #88: fix: tweak the connect tool to prefer preconfigured connection string

32 of 147 branches covered (21.77%)

Branch coverage included in aggregate %.

9 of 11 new or added lines in 2 files covered. (81.82%)

399 of 658 relevant lines covered (60.64%)

90.71 hits per line

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

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

10
export class Server {
11✔
11
    public readonly session: Session;
12
    private readonly mcpServer: McpServer;
13

14
    constructor({ mcpServer, session }: { mcpServer: McpServer; session: Session }) {
15
        this.mcpServer = mcpServer;
109✔
16
        this.session = session;
109✔
17
    }
18

19
    async connect(transport: Transport) {
20
        this.mcpServer.server.registerCapabilities({ logging: {} });
109✔
21

22
        this.registerTools();
109✔
23
        this.registerResources();
109✔
24

25
        await initializeLogger(this.mcpServer);
109✔
26

27
        await this.mcpServer.connect(transport);
109✔
28

29
        logger.info(mongoLogId(1_000_004), "server", `Server started with transport ${transport.constructor.name}`);
109✔
30
    }
31

32
    async close(): Promise<void> {
33
        await this.session.close();
109✔
34
        await this.mcpServer.close();
109✔
35
    }
36

37
    private registerTools() {
38
        for (const tool of [...AtlasTools, ...MongoDbTools]) {
109✔
39
            new tool(this.session).register(this.mcpServer);
3,052✔
40
        }
41
    }
42

43
    private registerResources() {
44
        if (config.connectionString) {
109!
NEW
45
            this.mcpServer.resource(
×
46
                "connection-string",
47
                "config://connection-string",
48
                {
49
                    description: "Preconfigured connection string that will be used as a default in the `connect` tool",
50
                },
51
                (uri) => {
NEW
52
                    return {
×
53
                        contents: [
54
                            {
55
                                text: `Preconfigured connection string: ${config.connectionString}`,
56
                                uri: uri.href,
57
                            },
58
                        ],
59
                    };
60
                }
61
            );
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

© 2025 Coveralls, Inc